📜 ⬆️ ⬇️

Creating a channel with auto posting in Telegram without a single line of code

Introduction


I warn you at once: there is very little technical in the article. This is almost a step-by-step instruction for users who are not very technical . For knowledgeable people (and those who are too lazy to read a lot of text), here are two links: Telegram Bots API + IFTTT Maker Channel .

Now more. I think everyone heard about the Telegram messenger. Probably, many even know about the simple API for creating bots in this messenger. In addition, not so long ago, T had the opportunity to create so-called “channels” (channels), which simplify instant messaging to almost any number of people who subscribe to the channel. Finally, the latest news: bots can be added as administrators to the channels , that is, such mailings can be done automatically.

I think it is not necessary to explain that this opens up quite broad opportunities for various services. For example, I quickly did the following:

Already after creating all these bots and channels, it occurred to me that the simplest auto-import of posts from somewhere “outside” can be established without any code or hosting at all - literally about 5 minutes later. The excellent service IFTTT - If This Then That, having a lot of integration with social networks and other services. True, unfortunately, he has no (yet?) Direct integration with Telegram - but there is a so-called. IFTTT Maker Channel , which allows you to make simple HTTP (S) requests when a trigger is triggered. Unfortunately, we will not be able to receive messages sent to the bot (incoming requests to IFTTT Maker can receive, but, alas, only in a strictly defined format) - the interactive will not work. But we can by triggering any event (for example, a new tweet or post in FB):

True, the trigger will be triggered about once every 15 minutes. And until there was a way to upload images / videos / documents (you can only throw a link to them). Yes, the restrictions are tough. But for the simplest alerts - go. So let's go.
')

Step 1. Create a bot.


On the issue of creating a bot, you need to contact the most important bot: @BotFather . You will be asked two things: the name that will be displayed in the list of dialogs, as well as the username on which your bot can be found (it must be unique). If the goal is to publish posts in the channel, neither the one nor the other is of any particular importance (only you will see your administrator bot).

After receiving the answers to these two questions, BotFather should issue you the token of your bot. It has the following form:
123456789: Blablabla ...

You should not lose a message with a token, and the token itself should not be disclosed to anyone, since the token allows anyone to be represented by your bot.


Step 2. Create a channel.


Channel creation is optional step. If you want, you can send messages to the chat or to the user (although you will first have to find out their id - about this below).

In our Telegram client, we choose to create a new message - New Channel (it seems that all official clients now support this). Specify the name, description and photo to taste. The channel must be public, so we specify the type Public and set the address (“username”) now for the channel. You can skip inviting friends.

When the channel is created, go to its settings, open the list of administrators and add the bot created in the first step (search by its username).


Step 3. Configure the integration on IFTTT.


Heading to IFTTT . Register, if not yet. IFTTT allows you to create multiple triggers of the form “import from where”, “under what condition”, “export to”. They are called "recipes." Create a new recipe: Create a recipe .

First you need to select the source and the specific condition (trigger) by which the recipe should work. Here you are not limited by anything: if you want to - follow the hashtag tweets, if you want - transfer your posts from Facebook. I will not go into details, everything is quite simple.

The last part of the recipe, “that”, is to choose what to do if the condition has worked. Here you need to enter into the search for Maker , select it, and then the only available action - Make a web request . Finally - the most crucial stage, filling in the fields:

(note: method and content type can be selected by others - Telegrams are relatively omnivorous in this regard)

Note: instead of <token> and URL, you need to specify your bot's token (see step 1), instead of <channel>, in Body - the channel address (step 2). Without angle brackets, of course, but the @ address must appear before the channel address. {{Text}} in the Body field means the replacement of the text obtained from the published record. The specific substitution code may be different, they depend on the selected trigger, to see their list (and substitute them in the message text), click on the button with the bulb next to the Body field. Of course, you can not make any substitutions at all, but publish the same text, but this quickly annoys subscribers :)

Specification: if you want to send a message not to the channel, but to the chat or to a specific person (yourself, for example), then instead of "@ <channel> " you need to specify the ID of the chat or this person. To find it out, the easiest way is to add to yourself, for example, this bot - with the command / start (in a personal or in the required chat) it will send the desired number. Messages will be delivered to the chat only if your bot is added to it as a participant, and to the user personally if he has previously initiated a dialogue with him.

Step 4. PROFIT!


Everything, approximately once every 15 minutes, IFTTT should check your “recipe” (they say, some triggers are checked more often), and when it is triggered, send a message through the bot to the channel. If necessary, in the list of recipes, you can force a check, view the history of operations or turn off the recipe altogether.

I hope my article will help even people far from programming to organize their own simplest autoposting for Telegram, which does not require any investments. Thanks for attention :)

Source: https://habr.com/ru/post/269819/


All Articles