According to the messenger policy, bots cannot send messages first. In order for the user to receive notifications from the bot, he must somehow interact with the bot and send him at least some initial message.
The easiest way to do this is on the site / application side, you need to create a button "I want to receive notifications in the messenger" (or "follow the status of the order in the messenger", "select a support channel" and etc), that the person will click and initiate a contact with a bot.
In this button, the starting parameter can contain the customer_id of the customer in your CRM / ERP and the bot will return the chat_id and the communication channel chosen by the customer so that you can continue to send him notifications. In this script, the bot does nothing other than saying "Great, now I will inform you of all the news on your order, if you want help - click "connect with the operator".
There are mechanisms in messengers that allow you to pass input parameters to the bot. These mechanisms are called deeplinks and are a way to sew a parameter into a link that will open a bot.
Viber https://developers.viber.com/docs/tools/deep-links/
Example: viber://pa?chatURI=<URI>&context=<UserID>&text=<Start!>
The text
parameter is optional, if passed, it will be presented to the user input string as follows:
If it doesn't pass, referrals will still be regarded as the beginning of the conversation, and is sufficient to subscribe to the notification
Telegram https://core.telegram.org/bots#deep-linking
Example: [https://telegram.me/<Имя_бота>?start=<UserID>
](https://telegram.me/<Имя_бота>?start=<UserID>)
To subscribe to notifications, following the link is not enough, you need to click the Start button
Facebook https://developers.facebook.com/docs/messenger-platform/discovery/m-me-links/
Example: http://m.me/<PAGE_NAME>?ref=<UserID>
In the starting parameter, you can pass the id of the client, order, and etc. In general, anything that will allow you to match data from your site / application with a pair of chat_id + channel from the bot later.
Thus, you need to generate links to your bots indicating the input parameter and ask the user to click on the link and start communicating with the bot.
If you do not need to use the user id in the bot in an external system (for example, identify), you can not pass any parameters, but simply send the user to the bot to take the first steps and save the chat_id + channel in the CRM / application.
<aside>
⚠️ When using a Facebook and Viber deeplink, it sends a command start
. Consider this if you are branching your script with with get_command
action
</aside>
If you want to use a start parameter in your script, use the get_command
action
It will process a command like /commandname
or passed through deeplink, if a parameter is passed, sets the constant {{messenger_input_param}}
After the first message from the user, for example, clicking the "Start" button in Telegram, the bot must return a couple of parameters back to the application (website, CRM, etc.), namely
chat_id
- unique within the messenger chat id. This is usually an alpha-character string.channel
- channel name (telegram, viber, facebook, etc)