> For the complete documentation index, see [llms.txt](https://docs.dataspace.ch/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.dataspace.ch/platform/transformation/notify/telegram.md).

# Telegram

## Creating a Telegram Bot

To send messages, you first need a Telegram Bot.

{% stepper %}
{% step %}

### Open BotFather

Open Telegram and search for [@BotFather](https://t.me/BotFather).
{% endstep %}

{% step %}

### Create a new bot

Start a chat with BotFather and send `/newbot`.
{% endstep %}

{% step %}

### Name your bot

Follow the instructions to give your bot a name and username.
{% endstep %}

{% step %}

### Keep the Bot Token safe

BotFather will provide a **Bot Token** — keep this secret. You will use it to authenticate API requests.

For more detailed information, see the official [Telegram Bot API documentation](https://core.telegram.org/bots).
{% endstep %}
{% endstepper %}

{% hint style="warning" %}
Do not share your Bot Token publicly. Treat it like a password.
{% endhint %}

## Obtain Chat ID

You have to start a chat with your newly created bot. Once done, there will be a new chat ID associated with your bot. You can extract this code by calling the following endpoint:

```url
https://api.telegram.org/bot{TELEGRAM_TOKEN}/getUpdates
```

## Notification Implementation

Once the bot token and the chat ID are obtained, the API can be pinged to send a message inside that chat.

```python
import polars as pl
import requests
import os

TELEGRAM_TOKEN = os.environ["TELEGRAM_BOT_TOKEN"]
TELEGRAM_CHAT_ID = "191699299"

def send_telegram_message(message, chat_id):
    url = f"https://api.telegram.org/bot{TELEGRAM_TOKEN}/sendMessage?parse_mode=HTML&chat_id={chat_id}&text={message}"
    response = requests.get(url).json()
    print(response)
    return response


def transform():
    text = """
    ⚠️ <b>New Alert!</b>
    """
    response = send_telegram_message(text, TELEGRAM_CHAT_ID)    
    return pl.LazyFrame(response)
```


---

# 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 dynamically by asking a question.

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

```
GET https://docs.dataspace.ch/platform/transformation/notify/telegram.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
