feat: add @chat-adapter/telegram package#107
Conversation
Add a new Telegram adapter using grammy for Bot API interactions. Supports webhook handling, MarkdownV2 formatting, inline keyboard cards, reactions, typing indicators, and forum topic threads.
|
@reloadlife is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This pull request adds a new Telegram adapter to the chat SDK using the grammy library for Bot API interactions. The adapter enables Telegram bot integration with support for webhook handling, MarkdownV2 formatting, inline keyboard cards, reactions, typing indicators, and forum topic threads.
Changes:
- Adds
@chat-adapter/telegrampackage with full adapter implementation - Extends emoji placeholder conversion and card utilities to support Telegram platform
- Configures environment variables for Telegram bot token and secret token in turbo.json
Reviewed changes
Copilot reviewed 13 out of 15 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| turbo.json | Adds TELEGRAM_BOT_TOKEN and TELEGRAM_SECRET_TOKEN environment variables |
| pnpm-lock.yaml | Adds grammy dependency (v1.40.0) and related packages |
| packages/chat/src/emoji.ts | Extends convertEmojiPlaceholders to support "telegram" platform using unicode emoji |
| packages/adapter-shared/src/card-utils.ts | Adds "telegram" to PlatformName type and button style mappings |
| packages/adapter-telegram/package.json | Package configuration for the new adapter |
| packages/adapter-telegram/tsconfig.json | TypeScript configuration |
| packages/adapter-telegram/tsup.config.ts | Build configuration |
| packages/adapter-telegram/src/types.ts | Type definitions for Telegram-specific data structures |
| packages/adapter-telegram/src/markdown.ts | MarkdownV2 format converter implementation |
| packages/adapter-telegram/src/markdown.test.ts | Tests for markdown conversion |
| packages/adapter-telegram/src/index.ts | Main TelegramAdapter implementation |
| packages/adapter-telegram/src/index.test.ts | Tests for adapter functionality |
| packages/adapter-telegram/src/cards.ts | Card to Telegram inline keyboard converter |
| packages/adapter-telegram/src/cards.test.ts | Tests for card conversion |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (headerToken !== this.secretToken) { | ||
| return new Response("Invalid secret token", { status: 401 }); |
There was a problem hiding this comment.
The secret token comparison should use a timing-safe comparison function to prevent timing attacks. Simple string comparison (===) can leak information about the secret through timing side-channels. Use crypto.timingSafeEqual for comparing secrets, similar to how the Slack adapter does it (see packages/adapter-slack/src/index.ts around line 1095). Import timingSafeEqual from 'node:crypto' and convert both strings to buffers before comparing.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Summary
Add
@chat-adapter/telegrampackage implementing the Telegram Bot API adapter using the grammy framework (TypeScript-first, webhook-ready).setMessageReaction), inline keyboard buttons, typing indicators, and DMsX-Telegram-Bot-Api-Secret-Tokenheader validationInputFilewith Buffer conversion for cross-platform compatibilitymessage_thread_idturbo.json,@chat-adapter/shared(PlatformName), andchatemoji utilitiesDetails
Capabilities
sendChatAction("typing"))InputFile)Media support
Inbound photo messages are exposed as
Attachmentobjects on theMessagewith:type—"image"width/height— from largest photo sizesize— file size in bytes (when available)Outbound file uploads convert
FileUpload.data(Buffer/ArrayBuffer/Blob) to grammyInputFilewith caption support (1024 char limit).Thread ID format
telegram:{chatId}:{messageThreadId}telegram:123456789:0telegram:-1001234567890:42Environment variables
TELEGRAM_BOT_TOKEN— Bot API token from @BotfatherTELEGRAM_SECRET_TOKEN— Secret token for webhook signature verificationTest plan
pnpm typecheckpasses across all packagespnpm check(lint/format) passespnpm knip(unused exports/deps) passespnpm testpasses (54 Telegram adapter tests + all existing tests)