Skip to main content
Glama
README.md
# Telegram Cloud MCP

A Cloudflare Worker that provides MCP (Model Context Protocol) integration for Telegram, enabling AI assistants to send messages, media, and voice notes via Telegram bots.

## v3.0 — Media Support

Send photos, videos, audio, GIFs, and documents alongside text and voice. Every media tool supports URL-based sending, captions, and reply threading.

**v2.0** introduced multi-companion routing — one worker, unlimited bots. Every tool takes a `companion` parameter that maps to a per-companion bot token.

Single-bot setups still work — just configure one companion.

## Features

- Send text messages to Telegram chats
- Send photos with inline preview
- Send videos with inline player
- Send audio with music player widget (title + artist)
- Send GIFs/animations
- Send documents/files as attachments
- Send voice notes with text-to-speech (ElevenLabs or OpenAI)
- Get bot information, retrieve updates, inspect chats
- **Multi-companion routing** — one worker, unlimited bots

## Tools

All tools accept a `companion` parameter to select which bot acts.

| Tool | Description |
|------|-------------|
| `telegram_send` | Send a text message to a chat |
| `telegram_voice` | Send a voice note (TTS) to a chat |
| `telegram_send_photo` | Send a photo (URL or file_id) with optional caption |
| `telegram_send_video` | Send a video with inline player |
| `telegram_send_audio` | Send audio with music player (title + artist) |
| `telegram_send_animation` | Send a GIF/animation |
| `telegram_send_document` | Send any file as an attachment |
| `telegram_get_me` | Get bot information |
| `telegram_get_updates` | Get recent messages and updates |
| `telegram_get_chat` | Get information about a chat |

---

## Setup

### 1. Create Telegram Bot(s)

1. Message [@BotFather](https://t.me/BotFather) on Telegram
2. Send `/newbot` and follow the prompts
3. Save the bot token you receive
4. Repeat for each companion you want

---

### 2. Configure Secrets

Set per-companion bot tokens as Cloudflare secrets:

```bash
# Per-companion tokens (add as many as you need)
wrangler secret put TELEGRAM_TOKEN_KAI
wrangler secret put TELEGRAM_TOKEN_LUCIAN
wrangler secret put TELEGRAM_TOKEN_AUREN
# ... etc

# Legacy single-bot fallback (maps to first companion)
wrangler secret put TELEGRAM_BOT_TOKEN

# Optional voice
wrangler secret put ELEVENLABS_API_KEY
wrangler secret put ELEVENLABS_VOICE_ID
wrangler secret put OPENAI_API_KEY

# Access gate for /mcp + /sse — SET THIS, or anyone with the worker URL can
# send Telegram as your companions. Then send it: Authorization: Bearer <MCP_KEY>
wrangler secret put MCP_KEY
```

**Customizing companion names:** Edit the `COMPANIONS` array and `getTokenForCompanion()` in `src/index.ts` to match your companion names and token env vars.

For local development, create a `.dev.vars` file:

```
TELEGRAM_TOKEN_KAI=your_token_here
TELEGRAM_TOKEN_LUCIAN=your_token_here
```

---

### 3. Deploy

```bash
npm install
npm run deploy
```

---

## Endpoints

| Endpoint | Method | Description |
|----------|--------|-------------|
| `/` | GET | Service info, configured companions, available tools |
| `/health` | GET | Health check |
| `/mcp` | POST | MCP JSON-RPC endpoint |
| `/sse` | GET | MCP SSE endpoint for client discovery |

---

## MCP Client Configuration

Add to your MCP client config:

```json
{
  "mcpServers": {
    "telegram": {
      "type": "http",
      "url": "https://your-worker.workers.dev/mcp"
    }
  }
}
```

---

## Media Sending

All media tools accept a URL or Telegram `file_id` as the media source. This means you can send:

- Images from any public URL (e.g., from an image generation API)
- Videos, audio, or documents hosted anywhere
- Previously sent Telegram media by reusing its `file_id`

Captions support Markdown formatting.

---

## Voice Notes

Voice notes use ElevenLabs as the primary TTS provider, falling back to OpenAI if ElevenLabs is not configured. If neither is configured, voice commands will return an error with details.

**Note:** ElevenLabs free tier may be blocked when called from Cloudflare Workers due to shared IP detection. Self-hosted TTS or a paid ElevenLabs plan resolves this.

---

## License

MIT

---

## Support

If this helped you, consider supporting my work :)

[![Ko-fi](https://img.shields.io/badge/Ko--fi-Support%20Me-FF5E5B?style=flat&logo=ko-fi&logoColor=white)](https://ko-fi.com/maii983083)

---

*Built by the Triad (Mai, Kai Stryder and Lucian Vale) for the community.*