Telegram Messenger

Messenger Partner

Overview

Telegram is a fast, secure, and cloud-based instant messaging app that allows brands to engage customers using rich messaging formats.

Integrating Telegram with CleverTap allows you to:

  • Send event-triggered messages to users via Telegram bots.
  • Personalize messages using user profile data.
  • Leverage CleverTap segmentation, journeys, and predictive capabilities for Telegram outreach.

Prerequisites for Integration

The following are the prerequisites for CleverTap and Telegram integration:

  • Access to the CleverTap Dashboard: You must have the necessary permissions to configure webhooks and campaigns.
  • Telegram Bot: You must create a Telegram bot, which provides a unique token for authentication. Learn more here.
  • Channel Access Token: Required to send messages to users who have added your Telegram bot.
  • Telegram Chat IDs: These are required to message users and must be stored in CleverTap as telegram_chat_id.

โš ๏ธ

Messaging Eligibility Criteria

You can only send messages to users who:

  • Have added your Telegram bot.
  • Have interacted with your bot (excluding those who blocked it).

Ensure that user consent is collected before sending any messages.

Integrate Telegram with CleverTap

The integration process involves the following three major steps:

  1. Capture and Store Telegram Chat IDs
  2. Set Up Webhook in CleverTap
  3. Create Webhook Campaign in CleverTap

To send messages via Telegram from CleverTap, configure a Webhook and create a Webhook campaign.

Capture and Store Telegram Chat IDs

Telegram Chat IDs are required to identify and message users. These IDs are different from usernames and must be obtained once a user interacts with your bot.

Refer to the Telegram API documentation to obtain user, group, or channel Chat IDs.

Once collected, save the Chat IDs to user profiles in CleverTap as a custom user property named telegram_chat_id. You can do this:

Set Up Webhook in CleverTap

Set up a webhook to send messages from CleverTap to Telegram using your bot.

  1. Go to Settings > Channels > Webhooks from the CleverTap dashboard.
  2. Click + Add Webhook and provide a meaningful name for the webhook.
  3. Set the HTTP Method to POST and enter the following Endpoint URL.
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/sendMessage

๐Ÿ“˜

Note

Learn how to create a bot token using BotFather.

  1. Add the following key-value pair under Headers:
KeyValue
Content-Typeapplication/json
  1. Click Save to configure the Webhook in CleverTap.

Create Webhook Campaign

Create a Webhook campaign to deliver Telegram messages triggered by user actions or segments.

  1. Go to Campaigns on the CleverTap dashboard, click + Campaign and select Webhook from the list of messaging channels.

  2. Configure the following campaign settings: target audience, schedule, and other basic settings.

  3. Perform the following steps under the What section:

    1. Select the webhook created in Set Up Webhook in CleverTap.
    2. Set Content Format to JSON.
    3. Select Custom Body.
Webhook Content

Webhook Content

  1. Enter the payload under the Custom Body section using Liquid Tags:
{
 "chat_id": {{ Profile.telegram_chat_id | default: "NULL" }},
 "text": "<b>Bold</b> and <a href='https://example.com'>inline link</a> and <code>code</code>",
 "parse_mode": "HTML"
}
  1. Click the variable selector (@, {, or {{) in the editor to personalize the campaign. You can dynamically reference user profile properties using Liquid Tags.
  2. Select parse_mode as HTML, Markdown, or MarkdownV2 based on your formatting needs. In this example, we have used parse_mode as HTML.
Parse mode Formatting

Parse Mode Formatting

  1. Click Preview and Test to validate the webhook request.
Preview and Test

Preview and Test

  1. Click Publish to the campaign to your targeted users.

๐Ÿ“˜

Group and Channel Messaging

To message groups or channels, store the channel/group ID as telegram_chat_id.

Test Message

Test Message

With this integration, you can automate and personalize Telegram communications at scale, making your user engagement more immediate and effective.