# Telegram

## What is Telegram

[Telegram](https://telegram.org/) is a messenger that allows for the creation of advanced chatbots. Let's explore how you can create a Telegram bot using Directual.

## &#x20;Directual–Telegram basics

### Step 1. Create a bot

Open the messenger and go to the [BotFather](https://t.me/BotFather) and type `/newbot`

![Secret token is red. Here on the screenshot it is masked partially :)](https://3071851461-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4Nnmtk9_gFGWOddsf6%2F-MQfKRohZx-Xw-w5YHRj%2F-MQfKxScX0tY2HQAQu-z%2Fbotfather.jpg?alt=media\&token=4f365853-2544-48fd-b5e7-e5cdf9c913e7)

The BotFather will give you an HPPT API **secret token** (the red one).

### Step 2. Connect your bot to the app

Go to Directual app, **Plugins** section → **Telegram** , insert the **secret token** you copied and click **Install**.

<figure><img src="https://3071851461-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M4Nnmtk9_gFGWOddsf6%2Fuploads%2FtyHyUWgIkHak7gLLMom0%2Fimage.png?alt=media&#x26;token=5790c97c-74b9-476c-99e2-e2e22197eea5" alt=""><figcaption></figcaption></figure>

### Step 3. Find Telegram structures in Directual

Go to Database section, `Integrations/Telegram` folder (it appears automatically). Here you will find five data structures:

![](https://3071851461-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4Nnmtk9_gFGWOddsf6%2F-MQfKRohZx-Xw-w5YHRj%2F-MQfP8SBK2E_ZXT8Ze4M%2Fstep-2.png?alt=media\&token=bc98f186-06c0-4f41-9210-04a771f0ba68)

* **Incoming Telegram messages** (system name `TMessageIn`). Stores all messages that users have sent to the bot.
* **Outcoming Telegram messages** (system name `TMessageOut`). Stores all messages that the bot have sent to users.
* **Users Telegram** (system name `TUser`). Stores Users who have sent messages to the bot.
* **Chats Telegram** (system name `TChat`). Stores Chat-objects. That is the object which is used by scenario Telegram step as a 'destination'.
* **Keyboards Telegram (Legacy)** (system name `TKeyboard`).

Also, a [webhook](https://readme.directual.com/api-integrations/webhooks) for receiving Telegram messages has been added, and a new [System scenario](https://readme.directual.com/scenarios/system-scenarios) `Parse incoming telegram messages` has appeared (do not edit them!).

### Step 4. Test the integration and investigate `TMessageIn` structure

Type something to the bot! Send a picture, a file, or location details. Then check the `TMessageIn` structure.

![Different messages are being sent to the bot](https://3071851461-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4Nnmtk9_gFGWOddsf6%2F-MQfQ-o1DmLI2ufqPkuR%2F-MQfShYO0FcjHKZYIgUv%2Fmessages.png?alt=media\&token=e9f201fe-e55a-4a4a-930c-198711c82c29)

Let's have a look at new objects which appeared in `TMessageIn`!

![](https://3071851461-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4Nnmtk9_gFGWOddsf6%2F-MQfTgvXVprgB1aqtdO9%2F-MQfUPWN16IxlJJ_0b4t%2FtmessageIn.gif?alt=media\&token=0ae871b5-6d7e-405b-838c-2929f408cd60)

The clue field for text messages is `text` — it contains the message. Also there is information referring to images, files and locations.&#x20;

{% hint style="info" %}
Information about files and images are stored as `Telegram file IDs`, further in this manual we'll figure out how to download and process them.&#x20;
{% endhint %}

### Step 5. Creating a simple scenario

Create a new scenario, which triggers new objects in `TMessageIn` structure. (See [scenarios documentation](https://readme.directual.com/scenarios/principles-of-scenarios)):

![](https://3071851461-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4Nnmtk9_gFGWOddsf6%2F-MQfVVSmOqg0UM65W_NT%2F-MQfXVDsKUkWHC3H2aUv%2Fnew-scen.png?alt=media\&token=d0ca8dc0-0a20-4db6-a185-d3c9230558c8)

Put the [Telegram step](https://readme.directual.com/scenarios/editing-scenarios/integration-steps/telegram-step) in scenario and configure it as follows (don't forget to publish and run the scenario):

![](https://3071851461-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4Nnmtk9_gFGWOddsf6%2F-MQfVVSmOqg0UM65W_NT%2F-MQfYJ3is7HuQGMnvHmg%2Fscen.gif?alt=media\&token=38574e50-06f7-4b31-b01c-6f812ff4c60e)

The bot will behave as follows:

![](https://3071851461-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4Nnmtk9_gFGWOddsf6%2F-MQfZyB8LHI7EpR6dmxf%2F-MQf_ZOszMDh6rEbP2tZ%2Fsimple-dialog.gif?alt=media\&token=fbf36c37-f67d-4593-8e96-99c91ae7b663)

Check out some [useful techniques for building Telegram bots with Directual](https://readme.directual.com/api-integrations/other-integrations/telegram/telegram-advanced-techniques)


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://readme.directual.com/api-integrations/other-integrations/telegram.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
