# Telegram: Advanced Techniques

### Using the templating system

Feel free to use all the features of the [Templating system](/template-system/basics-of-template-system.md) in the [Telegram step](/scenarios/editing-scenarios/integration-steps/telegram-step.md).

### Processing system commands

Telegram bots have `/commands`, so add them in the BotFather (using `/setcommands`) and create **one** scenario which triggers new objects from `TMessageIn`, and if there is no system commands in `text` field, the scenario sends an object to the **Router** **scenario**.

![](/files/-MQfdvp-ASQJAEuSwUeH)

{% hint style="info" %}
Important! The best bot architecture includes **only one** scenario which triggers new `TMessageIn` objects.
{% endhint %}

### Context-based architecture

**The Router** scenario (which is not triggered by events but invoked) is routing messages, based on the value of the field `context` in `TChat` object.

![](/files/-MQfgEylh62bus4hpR9K)

Condition step (checking `context`) looks like:

![](/files/-MQfggwZed1T6j8IdoUU)

{% hint style="info" %}
**Multi-context architecture**

You can add as many fields in `TChat` structure (e.g. `subcontext`) and compose conditions on them. That is a way to create multi-context architecture.
{% endhint %}

### Dealing with files, images and userpics

#### Step 1. Getting temporary file path

Call Telegram API-method `getFile` using Telegram step this way:

![](/files/-MQfihLjK1Skat4-Loyh)

Then, save to a field temporary URL: `https://api.telegram.org/file/bot_BOT_TOKEN_/{{API_response.file_path}}`, where `_BOT_TOKEN_` is token of your bot.

#### Step 2. Saving file to Directual

Use internal SDK method [$D.fs.download](/javascript-sdk/internal-usdd-methods.md#save-file-to-the-internal-file-storage-usdd-fs-download) (it can be applied in both [SDK step](/scenarios/editing-scenarios/action-steps/js-sdk-step.md) and in [Edit object step](/scenarios/editing-scenarios/action-steps/edit-object-step.md))


---

# 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/telegram-advanced-techniques.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.
