Creating a Telegram bot
To work with Telegram bot in enKod go to Mailings → Telegram bots.
Make sure that the bot has been previously created in @botfather. For the desired bot, copy the token (read more about integration with Telegram in this article), you will need it to activate the bot in enKod.
Set a name (it will be displayed only in the enKod interface) and go to the bot editor. Two blocks are available for customization: start and message.
The chain of any bot should start from the start block. At the moment only start by /start command is available, but this list will be expanded in the future.
Place the “Message” block and connect the starting block to it by pulling a link. In the “Message” block you can set the text and customize the buttons. Buttons can be one of three types:
- button-text (clicking on such a button will cause sending the messages, connected to it)
- a link button (clicking on such a button will open the Telegram app's built-in browser and the link specified in the button's settings)
- return to the beginning (always displayed at the very end and can be only one per block, clicking this button will return the user to the first message after launching the bot)
In total you can add up to 10 buttons to 1 “Message” block, buttons of different types can be used in parallel with each other, only the number of “return to the beginning” buttons is limited.
Each button in a block can and must be connected to subsequent “Message” blocks (with their own buttons). The button-text must be connected to the next block (even if it contains just some message, for example, “thank you”), otherwise the dialog of the bot with the user will not be finished, because it will not react to the click. It is acceptable to not connect the button-link to anything, because the transition itself can be a necessary action. The “return to the beginning” button does not require a connection, because it always performs one specific action.
Thus, by combining message blocks with different buttons inside the bot you can create an infinite number of different scenarios depending on the user's action - to transfer him to the site, to send certain notifications on click, etc.
When activating the bot, if all checks pass successfully, the system will ask you for the access token of the bot, which was obtained from @botfather. Paste the token into the popup window and launch the bot.
Working with contacts
When launching the bot, we will receive and save contacts's username into the contact base. Such contacts, even if they do not have any other channels, are considered to be full-fledged and participate in the billing of the base. Usernames of contacts are available for viewing and editing in the contact card.
If a contact changes his/her username in Telegram, his/her username will also change in enKod. This will happen the next time the bot sends a message to the contact or the next time the contact interacts with the bot (i.e. not instantly).
Deleted contacts will not be restored when interacting with the bot to avoid accidentally exceeding the database size limit.
Please note that the bot cannot write first, even if there is a contact with a filled in username! The bot can be launched only by the user.
Features of the chat bot
- In Telegram bot user can repeatedly click on the buttons as many times as he/she wants in any of the received messages, thus the user will go to the branch of the script corresponding to the button.
- The system will prohibit you from creating bots where some part of the script is looped and this cycling does not depend on the user's clicks (you will receive a corresponding notification).
- Stopping the bot (in the enKod interface) means that the bot will stop working according to the scenario (sending messages, responding to clicks in sent messages, and nothing will happen when subscribing to the bot), in Telegram the buttons in the bot for subscribers will become inactive.
- when the bot is activated after a stop in a scenario, all subscribers will start moving further along the branches from the place of the stop, the buttons in the bot will become clickable (if they have not been deleted/edited).
- Chatbot can automatically change its status to “Inactive” if permission for the token in Telegram is revoked (check happens once an hour)
Chat Bot Details and Statistics
In the bot details, statistics are available to view, namely:
- Total bot launches: N
- Number of unique users in Telegram who have launched the bot at least once by /start for the entire time of its existence
- Interacted with the bot for the current month: N
- the number of interactions with the bot (launch, click on the button in the message) for the current month (from the first day to the current day) by unique users.
In addition to these metrics, you can view statistics on the blocks themselves in the “Preview” tab:
- Block Start
- N sent - number of launches of this bot
- Message block (without buttons)
- N sent - number of times this bot has been sent
- Message box (with buttons)
- N sent - the number of times the message has been sent
- N clicks - number of clicks on all buttons in the message
- For each button - number of clicks on it
Features of editing chatbots
The active bot can be edited (name, content of blocks (buttons, texts), their order, add new blocks, delete blocks), but it is forbidden to change the token in the authorization window. When editing an active bot, it continues to work according to the script. Changing the bot token is available only for inactive status.
If during editing you:
1. Deleted a message block
If the user has already received this block, it will not be deleted. If deleted along with subsequent blocks - users will end this branch of the script. If the links between subsequent blocks are not broken, the user will move on with the edited script.
2. Deleted message block with buttons
Buttons in the received message of the deleted block will become unclickable. If the user has already clicked on the buttons of the deleted block and has moved on in the branch, and the blocks exist and the links are not broken, the user will move on in the edited branch. Otherwise, the user will terminate the bot script branch.
3. Edited text and/or button links in a message block
In already received messages with the old text, the buttons will be unclickable. Otherwise there are no changes.
4. Changed links with blocks by buttons.
Buttons will become unclickable in the message the user has already received. Otherwise, the user will go on with the edited script. If the branch is missing - the user will terminate the script.
5. Added a button to the message
The button will not be added to already received messages. Buttons that have not been modified will be clickable. Otherwise, the user will move on with the edited script.
6. Deleted one of the buttons from the message
In already received messages, the deleted button will become unclickable. Otherwise, the user will follow the edited scenario.
Display statistics when editing bot
- If a post originally had buttons, and after the button was deleted, the statistics on total clicks (under the block) will not change.
- When a button is edited - statistics on clicks in the edited button is not reset. If a button is deleted - the statistics of the deleted button is deleted together with it, but the statistics on clicks under the block is not changed.
- If a start block is deleted, the statistics under it is deleted. General statistics of bot launches in the “General information” tab is not changed.
- The statistics in the “General Information” tab is never decreased even if the bot itself deletes blocks/changes buttons.