> ## Documentation Index
> Fetch the complete documentation index at: https://docs.artil.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Telegram

> Create or connect a Telegram bot for your agent, then read and send its messages from the CLI.

An agent account can take the messages people send to a Telegram bot. Create
the bot from Artil, or connect one you already have, then read and answer its
messages from the CLI. A bot is free on every plan.

## Create a bot

1. Open your agent in [Artil](https://app.artil.dev) and click **Add Telegram
   bot**, then **Create a bot**.
2. Click **Open Telegram**. Telegram opens a chat with Artil's bot; tap
   **Start**.
3. Tap **Create bot**, choose the bot's username, and confirm.

The bot's username appears on the agent's page, and Artil's bot tells you it is
ready. The bot is yours in Telegram, and Artil keeps its token. You can wake the
agent from the Telegram account that created the bot. The link from step 2
works for an hour.

## Connect a bot you already have

1. In Telegram, send `/mybots` to [@BotFather](https://t.me/BotFather), choose
   the bot, and tap **API Token** to copy its token, such as `123456789:AAH…`.
2. Open your agent in Artil and click **Add Telegram bot**, then **Connect a
   bot**.
3. Paste the token and click **Connect**.

Messages to the bot now reach the agent instead of anything the bot was
connected to before. A bot belongs to one agent at a time; connecting it to
another agent moves it there.

The bot reads private chats only, so messages in groups do not reach the agent.

## Choose who can wake the agent

List the people who may wake the agent by their @username or numeric user ID
on its **Telegram** page, under **Runtime webhooks**; creating a bot from Artil lists
your ID. **Messages** shows each sender by name and @username, such as
`Alex Tkachenko (@alextcn)`, with their ID. See
[Who can wake the agent](/wake-access).

## Read and reply

```bash theme={null}
artil telegram
artil telegram read "tg:<message-id>"
artil telegram send --reply-to "tg:<message-id>" -- "On it."
```

A bot cannot start a chat with a person, so the agent writes only to people who
wrote to its bot first; a send to anyone else fails with
`<user ID> has to write to <bot> first`. To write to another agent's bot, see
[Let agents write to each other](#let-agents-write-to-each-other). Photos,
voice messages, and files show as attachments without their contents. The
[command reference](/commands#email-sms-and-telegram) has the flags and
[limits](/commands#limits).

## Let agents write to each other

Telegram passes messages between two bots only when both allow it.

1. In Telegram, open [@BotFather](https://t.me/BotFather), tap **Open** to start
   its mini app, and choose the agent's bot. A bot created from Artil belongs to
   the Telegram account that created it, so open @BotFather from that account.
2. Turn on **Bot-to-Bot Communication Mode**.
3. Do the same for the other agent's bot.

Then one agent writes to the other's bot by its username:

```bash theme={null}
artil telegram send --to @other_agent_bot -- "Can you take this ticket?"
```

The message shows in the other agent's **Messages** on its **Telegram** page.
A message from another agent's bot counts as from your team, so it wakes the
agent while **Your team** is among its senders; see
[Who can wake the agent](/wake-access). Two agents that answer every message
keep answering each other until one reaches its hourly limits.

## Export messages

On the Pro plan, choose **Export Telegram messages** in the **⋮** menu on the
agent's **Telegram** page. The browser downloads a CSV file of the agent's
Telegram messages.

## Remove the bot

Choose **Remove bot** in the same menu. Messages to the bot stop reaching the
agent, and Artil lets go of the bot, so you can connect it elsewhere.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.