# Telegram Bot

> Connect a Telegram bot via Bot API.

Lets an agent operate a Telegram bot: poll incoming updates, send
messages and photos.

## What it can do

| Method | What it does |
| --- | --- |
| `get_me` | Name the bot (its @username) and the chat a message without `chat_id` goes to: the chat that last wrote to the bot, else the remembered one. Sends nothing. |
| `get_updates` | Receive incoming updates (messages, callback queries, etc.) via long polling or one-off request. On success, you MUST save last received update to long term memory. When use method, you MUST take last received update … |
| `get_photo` | Download a photo (or any file) by Telegram file_id from get_updates message.photo[], save as AgentFile, return agent_file (id, public_url). |
| `send_message` | Send a text message to a chat. |
| `send_photo` | Send a photo to a chat. Use photo=agent_file_id (from generate_image) or photo=HTTPS URL / file_id. |
| `send_voice` | Send a voice message. Prefer voice_url (HTTPS), e.g. agent_file.public_url from a previous speech generation tool call. Use voice_base64 only when you already have raw audio bytes explicitly. |

## How to get credentials

1. Open [@BotFather](https://t.me/BotFather) in Telegram.
2. Send `/newbot`, pick a name and username.
3. BotFather returns a **Bot Token** in the form
   `123456789:ABCdefGhIJKlmNoPQRstuVwxyZ`. Copy it.
4. Paste the token in FlyMyAI when setting up the MCP.
5. Open your bot in Telegram and press **Start** (or send it any message), so it
   knows which chat to write to. In a group, add the bot and write in the group.

If you need the bot in a group, add it manually and disable privacy mode
with `/setprivacy` in BotFather if it must read all messages.

## Fields to fill in FlyMyAI

| FlyMyAI field | Where it comes from |
| --- | --- |
| `Bot Token` | BotFather's reply after `/newbot` |

## Troubleshooting

- **Nothing was sent, "does not know which chat to write to"** - nobody has
  written to the bot yet. Open it in Telegram, press **Start**, then try again,
  or pass `chat_id`. `get_me` shows which chat it will use.
- **`401 Unauthorized`** - token is wrong or the bot was deleted. Ask
  BotFather for `/token` on the bot.
- **Bot doesn't see group messages** - disable privacy mode with
  `/setprivacy` in BotFather, then remove and re-add the bot.

## Links

- [@BotFather](https://t.me/BotFather)
- [Bot API reference](https://core.telegram.org/bots/api)
