> For the complete documentation index, see [llms.txt](https://help.smartico.ai/welcome/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.smartico.ai/welcome/products/crm-automation/activities-of-flows/activity-telegram-bot.md).

# Activity: Telegram Bot

This document provides a detailed guide to creating and configuring a Telegram Bot, enabling you to build Journey flows and use the chat features described in [the communications guide](/welcome/products/crm-automation/communication-channels/telegram.md) effectively.

{% hint style="success" %}
Note:

The Telegram Bot is an additional service that must be activated. Please get in touch with your Success Manager on the Smartico side for more details.
{% endhint %}

To start using the Telegram bot as a communication channel, you will need to complete the following steps:

1. Create a Telegram bot for your brand(s) using the Telegram application.
2. Configure the bot's settings on the Smartico side.
3. Invite users to the Telegram bot so their Telegram profile is linked to their Smartico profile.
4. Create telegram messages as resources in Smartico BackOffice.
5. Start using Realtime and Scheduled campaigns to communicate with your users.

## Create a Telegram Bot

1. Open the Telegram application on your laptop or mobile device.
2. Please search for a bot called **BotFather** and start a chat with it.<br>

   <div data-with-frame="true"><figure><img src="https://77049817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfS5hl0PiysHtKAKMsQTe%2Fuploads%2Fgit-blob-535b32382f97ac6371acaefb4bee81199c440506%2FBotFather%201.png?alt=media" alt=""><figcaption></figcaption></figure></div>
3. Send the command **/newbot** to create a new bot.
4. Set a name for your bot (e.g., My Casino Bot).
5. Choose a unique username for your bot that ends with “bot” (e.g., MyCasinoBot).\
   **Important:** Remember this username, as you will need it for the Smartico setup.
6. Once the bot is created, BotFather will provide an API token.\
   **Important:** Save this token, as it grants access to Telegram’s HTTP API.

## Configure the Bot in Smartico

1. Log in to Smartico Back Office and navigate to Label → Instant Messages.
2. Create a new gateway and select Telegram as the type.<br>

   <div data-with-frame="true"><figure><img src="https://77049817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfS5hl0PiysHtKAKMsQTe%2Fuploads%2FENFMM2GoXRi9J9PvsMad%2Fr2-005-crop-2-998daaf5-34adee.png?alt=media" alt=""><figcaption></figcaption></figure></div>
3. Define an internal name for the gateway, then select the appropriate brand for your bot.
4. Fill in the required parameters:

<div data-with-frame="true"><figure><img src="https://77049817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfS5hl0PiysHtKAKMsQTe%2Fuploads%2Fgit-blob-a03cb78e11a2dc3b6d8929b59d9052f0e3b9889c%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure></div>

* **Name of the Bot:** Use the username from Step 5 in the format @MyCasinoBot (use the format @MyCasinoBot; Smartico removes the “@” itself when it builds the bot link).
* **Telegram Bot token:** Enter the token received in Step 6. Keep this token secure and never share it publicly.
* **Disable webhooks:** When set to "yes", the Smartico system will not stitch the player with the Smartico CRM and will not register a webhook on the Telegram side. This option can be used if you already have a bot, have logic to connect a Telegram user to the PAM player, and want to use Smartico only to send Telegram messages while keeping full control of the bot on your technical side. When this is enabled, you must supply the `core_telegram_chat_id` for each player via the REST API `update_profile` event, database ingestion, or Kafka/RabbitMQ feeds. The value must be the player's numeric Telegram chat ID, received by your own bot after the player started it. In this mode Smartico does not receive updates from Telegram, so it learns that a player left only when a send fails because the player blocked the bot or deleted their Telegram account. In that case the chat ID and username are cleared. This property is the same one used by Smartico's own Telegram linking, so do not mix both approaches for the same brand. While this option is on, the form hides **Secret for User ID hashing**, **Auth link** and **Bot proxy mode**.
* **Secret for User ID hashing:** Enter a random string to secure the process of linking the Telegram user profile with the casino user profile. An alphanumeric string of 10 symbols is secure enough.
* **Auth link:** Provide a link to your casino’s front-end. This is used to connect the Telegram user profile with the casino user profile. Example: [https://mycasino.com](https://mycasino.com/). Pay attention that it should be HTTPS.
* **Bot proxy mode:** If you already have a Telegram bot on your side and want Smartico to run in parallel with your logic, enable this mode. After saving the configuration, reopen it and use the **Bot proxy URL** value to route webhook requests handled by your logic to the Smartico side. Note that the format of the routed request should match the format Telegram sends to your handler.

Telegram gateways are created and managed in the same Label → Instant messages screen as your SMS, WhatsApp and Viber gateways, and they use the same routing rules. A gateway can be tied to a brand and, if you set the gateway-selection user properties in the label settings, to specific values of those properties. If you have several Telegram gateways, leave the conditions empty on one of them to make it the default fallback.

{% hint style="info" %}
**Telegram Webhook Limitation and resolution with "Bot proxy mode"**\
Telegram Bot API allows **only one webhook URL to be registered per bot**. This means that a Telegram bot cannot send updates to multiple webhook endpoints simultaneously. If a webhook is already configured for your bot, registering another webhook will override the existing one, preventing you from connecting both your own backend logic and Smartico directly to Telegram simultaneously.

The *Bot proxy mode* resolves this limitation by keeping your existing webhook as the single Telegram entry point. In this setup, Telegram continues to send all updates to your webhook, and your system forwards those requests to Smartico via the **Bot proxy URL** provided after saving the configuration. As long as the forwarded request preserves the original Telegram webhook payload format, Smartico can process the same updates in parallel with your internal bot logic without requiring an additional Telegram webhook registration.
{% endhint %}

## Enable Mini App for your Telegram Bot (optional)

These optional steps let you activate the Mini App feature, allowing your bot to open a link directly inside Telegram’s Mini App instead of a standard web browser.

**Mini App vs Regular Bot:**

* Regular bot: Opens chat interface, user clicks buttons
* Mini App: Opens a web view inside Telegram (better UX for complex interactions)
* You can have both: a Telegram Bot and a Mini App; these options are not mutually exclusive.

**When to use Mini App:**

* When you want users to browse your site within Telegram
* When you need rich interactive content
* When you want a seamless authentication flow

How to set up Mini-App

1. Open your bot
2. Tap the **three-dot menu** (top right corner) and select **Manage Bot**

   <div data-with-frame="true"><figure><img src="https://77049817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfS5hl0PiysHtKAKMsQTe%2Fuploads%2Fgit-blob-481abf687c40e35763013b4398fc8ec289a2d7a0%2Funknown%20(43).png?alt=media" alt=""><figcaption></figcaption></figure></div>
3. Select **Change Bot Settings**<br>

   <div data-with-frame="true"><figure><img src="https://77049817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfS5hl0PiysHtKAKMsQTe%2Fuploads%2Fgit-blob-c0c6d0cda72017fc1e705c42b79083c078425120%2Funknown.png?alt=media" alt=""><figcaption></figcaption></figure></div>
4. You'll be redirected to Bot Father (the Telegram bot used to create your bot). An **automatic reply** will provide different configuration options.
5. Select **Bot Settings**<br>

   <div data-with-frame="true"><figure><img src="https://77049817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfS5hl0PiysHtKAKMsQTe%2Fuploads%2Fgit-blob-54a363c62744fe8290eb78e670bea5435e9e79f4%2Funknown.png?alt=media" alt=""><figcaption></figcaption></figure></div>
6. Select **Configure Mini App**<br>

   <div data-with-frame="true"><figure><img src="https://77049817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfS5hl0PiysHtKAKMsQTe%2Fuploads%2Fgit-blob-1acb1c7a2089ebc67ba404a4dcfb7653bc78f727%2Funknown.png?alt=media" alt=""><figcaption></figcaption></figure></div>
7. Select **Enable Mini App**<br>

   <div data-with-frame="true"><figure><img src="https://77049817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfS5hl0PiysHtKAKMsQTe%2Fuploads%2Fgit-blob-5eaffc6d31293acacc9294fbd3884b068c6247f1%2Funknown.png?alt=media" alt=""><figcaption></figcaption></figure></div>
8. **Submit the URL** for your website - this is what the Mini App will load. To launch the Mini App for users, use the following link format:\
   <https://t.me/your_bot_username?startapp>\
   \* "*your\_bot\_username must exactly match the name of your bot without @*

## Invite users to the Bot channel

Once your setup is complete, the user can subscribe to the chatbot by authenticating via a deep link to Telegram, "**dp:telegram"**.\
\
For example, you can set the deep link to a mission "Join our Telegram" to encourage the user to subscribe. Upon clicking, the user will be redirected to the Telegram app, a new chat window will open automatically, and the authentication process will complete.

<div data-with-frame="true"><figure><img src="https://77049817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfS5hl0PiysHtKAKMsQTe%2Fuploads%2Fgit-blob-41916e4453ff9117295a6b294ed5cc4e988c9608%2FTelegram%20HELP.gif?alt=media" alt=""><figcaption></figcaption></figure></div>

You can use the deep link "dp:telegram" in any other context, for example, in the popups, or you can also execute it from the front-end code of the website.

```html
<button onclick="_smartico.dp('dp:telegram')">
    Join our Telegram bot
</button>
```

## The user flows to the bot channel

#### **Flow 1: Initiated via Deep-Link `dp:telegram`**

1. The player clicks an element that contains the deep-link `dp:telegram`.
2. Smartico generates a unique token and constructs a URL leading to the Telegram bot/channel, embedding the token.
3. The player opens the link in the Telegram app and clicks the **Start** button of the bot.
4. Telegram sends the start command with the token to Smartico.
5. Smartico links the player’s profile with their Telegram account using the token.
6. The `core_telegram_chat_id` and `core_telegram_user_name` fields in the player profile are updated with the user's Telegram chat ID and, if available, their Telegram username or first name.
7. Smartico triggers the internal event `core_telegram_auth`, which can be leveraged to send a welcome message or trigger onboarding automation.

#### **Flow 2: Initiated from Telegram Channel**

1. A user discovers the Telegram bot and clicks the **Start** button.
2. Telegram notifies Smartico that the user has started the bot.
3. Smartico generates a unique token and creates a link to the brand’s website, using the **Auth Link** configured in the Telegram channel settings. The link is sent to the Telegram bot channel.
4. The user opens the link in a browser and is redirected to the brand’s site.
5. After successful authentication, Smartico receives the token data from the website.
6. Smartico matches Telegram users with their corresponding player profiles.
7. The `core_telegram_chat_id` and `core_telegram_user_name` fields in the player profile are updated with the user's Telegram chat ID and username or first name from Telegram.
8. Smartico triggers the `core_telegram_auth` internal event that enables welcome messages or other follow-up flows.

{% hint style="info" %}
**Translations**

* Bot uses `telegram_welcome` translation key for welcome message
* Bot uses `telegram_auth_button` translation key for auth button text
* These can be customized in Smartico [translation settings](/welcome/products/tools-and-guides/override-translations-on-label-brand-level.md)
* Language is detected from the user's Telegram profile language setting
  {% endhint %}

## Telegram Activity

The Telegram activity is used to send messages to end users via Telegram and is considered offline, as it doesn't require the user to be online. This type of communication can be sent only from Campaigns - Real-time and Scheduled.

Inside the flow builder, the Telegram activity is located in the communication section.

<div data-with-frame="true"><figure><img src="https://77049817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfS5hl0PiysHtKAKMsQTe%2Fuploads%2Fgit-blob-f6cf3bfc77942995c231a0d68acadccc94e3939d%2FTelegram%20journey.png?alt=media" alt=""><figcaption></figcaption></figure></div>

The telegram activity has the following setup options:

<div data-with-frame="true"><figure><img src="https://77049817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfS5hl0PiysHtKAKMsQTe%2Fuploads%2Fbc3Av5cDU6Fe4BiVRoll%2Fr2-002-crop-11-aa20152a-980243.png?alt=media" alt=""><figcaption></figcaption></figure></div>

1. **Provider** - choosing the Telegram provider that will be used for sending the communication. You can also select the Automatic Selection (multi-brand setup).
   1. Automatic Selection (multi-brand setup) - used to select automatically the gateway whose conditions best match the user; if no gateway with conditions matches, the gateway that has no conditions (the default one) is used. By default, the first condition is Brand, but you can add more user properties. This gives you greater flexibility when you want to filter a specific user segment to use a different gateway, for example.
2. **Allowed Communication hours** - used to define how the flow should behave if the time of the sending is in the ‘Do not Disturb’ period of the user.
3. **Caps status impact** - used to define if the message should be blocked or sent based on caps defined on the user and/or global level. CAP restrictions are not applied to accounts marked as test.
4. **Telegram message** - used to add the asset that will be sent to players, where you can define the message content. Before sending any communication via Telegram, the corresponding asset must be created. You can also add multiple message variations for A/B testing, allowing you to test different versions and optimize engagement. When adding a second variation, you can specify the percentage of the audience that will receive each version, ensuring controlled message distribution.

### Inline Buttons

Telegram message assets support up to 5 inline keyboard buttons displayed below the message. Each button supports three action types:

* **URL:** A standard web link or deep link (`https://...` or `dp:...`).
* **Mini App (`web_app:`):** Opens a Telegram Mini App webview directly within Telegram when prefixed with `web_app:` (e.g. `web_app:https://mycasino.com/game`).
* **Callback (`cb:`):** Sends a silent callback event (`engagement_action`) to Smartico without opening an external browser when prefixed with `cb:` (e.g. `cb:claim_bonus`).

## Visibility in the user profile

From the profile page, you can check if the user has subscribed to the Telegram chat bot, and if so, you see the chat ID (`core_telegram_chat_id`), you will also see the Telegram user name (`core_telegram_user_name`), which is populated from the profile of the user in Telegram.

<div data-with-frame="true"><figure><img src="https://77049817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfS5hl0PiysHtKAKMsQTe%2Fuploads%2FnP1dkp0uaZma96Xv0jWn%2Fr2-003-crop-12-930ff36a-7716d6.png?alt=media" alt=""><figcaption><p>CRM User profile, telegram chat ID and telegram user name</p></figcaption></figure></div>

## Segmentation

You can create a segmentation for all subscribed users by using the user property "Core: Telegram chat ID" in the segment conditions and setting it to be non-zero (this selects users with a Telegram channel enabled). The linked Telegram username is available as "Core: Telegram username / first name".

<div data-with-frame="true"><figure><img src="https://77049817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfS5hl0PiysHtKAKMsQTe%2Fuploads%2Fgit-blob-bb916509c9fe5c8dced17e743ff17f0c9f30d9b5%2FTelegram%20segmentation.png?alt=media" alt=""><figcaption></figcaption></figure></div>

## **Telegram-specific events**

There are 2 Telegram-specific events you can use to start real-time campaigns, complete missions, and execute automation rules to progress through campaign flows.

1. When the user subscribes to the Telegram bot, Smartico will trigger the "Core: telegram auth completed" event. You can use this event to send a welcome message to the user's personal channel.
2. When a user blocks or unsubscribes from the Telegram bot, Smartico will trigger the "Core: telegram unsubscribed" event.<br>

<div data-with-frame="true"><figure><img src="https://77049817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfS5hl0PiysHtKAKMsQTe%2Fuploads%2F11KPC3AkOdALrxC5OFnY%2Fr2-004-crop-14-aee1b63e-49be7e.png?alt=media" alt=""><figcaption><p>Example of campaign that is started when user is joining telegram bot</p></figcaption></figure></div>

## FAQ

**Q: I have set up a campaign to send messages, but they are not being delivered**

A: Check the following configurations

* You are targeting users who are subscribed to the Telegram bot. Your segment conditions should check for "Telegram chat id" <> 0
* The **Enable Instant Messaging (SMS, WhatsApp, Viber, Telegram, Custom IM)** setting is on in **Label settings**
* The **Instant message sending hours (SMS, WhatsApp, Viber)** label setting allows sending at this time (Telegram uses it too)

**Q: How can I do a new line in the Telegram message? Tried \<br> and \<p>, but they are not supported**

A: Telegram has a limited set of support HTML tags. To achieve a new line you can put an empty \<pre>\</pre> pair of tags

**Q: How are delivery/impressions/clicks tracked in reporting for Telegram messages?**

A: Telegram as a platform does not provide information on whether the message was delivered or seen by the user, though on the Smartico side, we have only information like

* Created - first fact, indicating that communication is created by activity in the campaign
* Sent - the fact that communication was dispatched to the Telegram bot API
* Failed - failed to deliver the message
* Click - user clicked on the link to the button in the message

Note: because Telegram sends no delivery receipt, the Delivered status and delivery rate shown for Telegram in campaign reports are not a true delivery measure. A message is marked Delivered only once one of its tracked links is opened. Messages that are never clicked stay without a Delivered status, so reports or exports that filter on "Delivered" will under-count Telegram recipients. Use Sent minus Failed as the closest equivalent of delivered messages.

**Q: What happens if the user blocks and then unblocks the bot?**

A: When unblocked, the user needs to click /start again and complete the authentication step the bot offers (or use the `dp:telegram` deep link again). Once authentication completes, the `core_telegram_auth` event fires again and the chat ID is updated.

**Q: Can I send images in Telegram messages?**

A: Yes. Smartico supports four content types for Telegram message assets: Text/HTML, Image/Photo (JPEG, PNG, WEBP), Video (MP4 with streaming support), and Animation (GIF/MP4). All media URLs must be publicly accessible HTTPS links.

**Q: What's the maximum message length?**

A: Text-only messages: up to 4096 characters. Messages with media captions (Photo, Video, Animation): up to 1000 characters (enforced by Smartico message delivery).

**Q: Can you explain the events that are sent when a user joins/leaves the Telegram bot?**

**core\_telegram\_auth -** happens when the user joins the bot

```json
{
  "core_telegram_chat_id": 123456789,
  "core_telegram_user_name": "john_doe"
}
```

**core\_telegram\_unsubscribed** - when the user leaves the bot

```json
{
  "core_telegram_chat_id": null,
  "core_telegram_user_name": null
}
```

**Q: Which HTML tags are supported?**

A: Telegram supports limited HTML:

`<b>`, `<strong>`, `<i>`, `<em>`, `<u>`, `<ins>`, `<s>`, `<strike>`, `<del>`, `<a>`, `<code>`, `<pre>`, `<blockquote>`

**Q: What happens if a campaign sends a Telegram message to a user who is not subscribed?**

A: If a player does not have a linked Telegram account (the user's Telegram chat ID is missing or 0), the Telegram send activity will fail. In journey flows, always use a segment condition (Telegram chat ID > 0) or add a Check User Profile activity before the Telegram activity to ensure the player is subscribed before sending.

**Q: How can I prevent my Telegram bot from being banned or deleted by Telegram?**

A: Telegram uses automated anti-spam algorithms that monitor newly created bots and accounts. To avoid rapid bans:

* Do not immediately launch mass marketing campaigns or reward missions from a newly created bot.
* Gradually ramp up subscriber volume and message sending over several days rather than blasting thousands of users on day one.
* Ensure users explicitly initiate interaction with the bot first via deep-link opt-in (`dp:telegram`).
* Adhere to Telegram's rate limits (approximately 30 messages per second per bot) to prevent delivery errors.

**Q: How do users unsubscribe from the Telegram bot, and when is their chat ID removed?**

A: Users unsubscribe by blocking the bot in Telegram. Smartico does not add an unsubscribe link or a stop command to Telegram messages. When a user blocks the bot, Smartico triggers "Core: telegram unsubscribed" and clears the chat ID and username. The same happens when a send fails because the user blocked the bot or deleted their Telegram account. If a send fails with "chat not found", the "Core: telegram unsubscribed" event is still triggered, but the chat ID is kept.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.smartico.ai/welcome/products/crm-automation/activities-of-flows/activity-telegram-bot.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
