Introduction
MoEngage <> Telegram
Integration
Telegram allows both promotional and non-promotional messaging to users as long your brand has secured users’ consent. To send messages to users, you must meet one of two conditions:
- Users who have added your Telegram bot
- Users who haven’t added your Telegram bot but have sent a message to your Telegram bot (excluding users who have blocked your Telegram bot).
REQUIREMENT | DESCRIPTION |
---|---|
Telegram bot | A Telegram bot is required to use this integration When sending Telegram messages, your messages will all be associated with your Telegram bot, resulting in users seeing your bot details (name, link) |
Channel access tokens | The channel access token will allow you to send messages to users that have added your Telegram. |
Telegram user IDs | You will need to have users’ Telegram IDs (this ID is different from users’ usernames) to send messages on Telegram. Once a user adds your Telegram official account, you can access the user’s Telegram ID through Telegram's Users API. |
Note-
- You can send personalised campaigns only to the users for which you have a user identifier (phone number).
- Telegram bots do not have phone number for your users by default. The number needs to be shared with your bot by the end users. You should either use Telegram API methods instead or ask it explicitly from the user (by sending a broadcast message on Telegram ID).
Step 1: Collect customer Telegram IDs
To send messages in Telegram, you need to collect your users’ Telegram IDs to identify your user and interact with them consistently. Telegram IDs are not the same as the user’s Telegram usernames. Telegram IDs are generated by Telegram and can be used when interacting with Telegram's APIs.
This endpoint will return a list of Telegram IDs for all users who have friended your Telegram official account or sent your account a message and have not blocked you.
Step 2: Save user's Telegram ID on MoEngage
Once you obtain a list of Telegram IDs, you need to add them to MoEngage.
-
If you have a user identifier such as phone number, you can add them on MoEngage as a
telegram_id
- custom tracked user attribute/property (phone number). You can save this data to MoEngage either using:- User Data API or
- Upload them using User Imports inside MoEngage.
- If you do not have any user identifier (meaning the user has not shared his personal details with your bot), you can upload them as Anonymous users.
Step 3: Create Connector Campaign on MoEngage to send Telegram Message
To create a connector campaign on MoEngage,
1. Navigate to Create Campaign >> Connectors >> Custom and choose delivery type most suitable to your needs
2. Choose Segment of users for whom telegram_id exists (You can combine with other Segment criteria)
3. On step 2 of the campaign,
- Select method as POST
- Add Webhook URL as :
https://api.telegram.org/bot<botID>/sendMessage
- In Headers, use
- Content-Type as application/json
- In Body, choose Raw and use the content depending on what kind of message object you want to send out. You can look at different message objects here.
Here are few content samples for different message types:
"chat_id": "{{UserAttribute['telegram_id']}}",
"text":"Hello world"
"chat_id": "{{UserAttribute['telegram_id']}}",
"photo": "https://example.com/image.jpg",
"to": "{{UserAttribute['telegram_id']}}",
"document" : "https://example.com/file.pdf"
4. At this point, your campaign should be ready to test and send. You can also test your connector configuration using the Test functionality available on Step 2 of Create Connector Campaign
If your test user successfully receives the message, your set-up is good to go. You can go ahead and Publish the campaign.