Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chat-stream-options-adapter-fallback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chat": patch
---

Pass configured fallback streaming options (`updateIntervalMs` and `fallbackPlaceholderText`) through native `adapter.stream()` calls so adapters can align their fallback behavior with `Chat` streaming config.
5 changes: 5 additions & 0 deletions .changeset/telegram-draft-streaming-polish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chat-adapter/telegram": patch
---

Add Telegram `sendMessageDraft` streaming in DMs with post+edit fallback, plus HTML markdown rendering for streamed and posted markdown content.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ See the [Getting Started guide](https://chat-sdk.dev/docs/getting-started) for a
| Microsoft Teams | `@chat-adapter/teams` | Yes | Read-only | Yes | No | Post+Edit | Yes |
| Google Chat | `@chat-adapter/gchat` | Yes | Yes | Yes | No | Post+Edit | Yes |
| Discord | `@chat-adapter/discord` | Yes | Yes | Yes | No | Post+Edit | Yes |
| Telegram | `@chat-adapter/telegram` | Yes | Yes | Partial | No | Post+Edit | Yes |
| Telegram | `@chat-adapter/telegram` | Yes | Yes | Partial | No | Draft API (DMs) + Post+Edit | Yes |
| GitHub | `@chat-adapter/github` | Yes | Yes | No | No | No | No |
| Linear | `@chat-adapter/linear` | Yes | Yes | No | No | No | No |

## Features

- [**Event handlers**](https://chat-sdk.dev/docs/usage) — mentions, messages, reactions, button clicks, slash commands, modals
- [**AI streaming**](https://chat-sdk.dev/docs/streaming) — stream LLM responses with native Slack streaming and post+edit fallback
- [**AI streaming**](https://chat-sdk.dev/docs/streaming) — stream LLM responses with native Slack/Telegram DM streaming and post+edit fallback
- [**Cards**](https://chat-sdk.dev/docs/cards) — JSX-based interactive cards (Block Kit, Adaptive Cards, Google Chat Cards)
- [**Actions**](https://chat-sdk.dev/docs/actions) — handle button clicks and dropdown selections
- [**Modals**](https://chat-sdk.dev/docs/modals) — form dialogs with text inputs, dropdowns, and validation
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/adapters/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Adapters handle webhook verification, message parsing, and API calls for each pl
| Edit message | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Delete message | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| File uploads | ✅ | ✅ | ❌ | ✅ | ⚠️ Single file | ❌ | ❌ |
| Streaming | ✅ Native | ⚠️ Post+Edit | ⚠️ Post+Edit | ⚠️ Post+Edit | ⚠️ Post+Edit | ❌ | ❌ |
| Streaming | ✅ Native | ⚠️ Post+Edit | ⚠️ Post+Edit | ⚠️ Post+Edit | ⚠️ Draft API (DMs) + Post+Edit | ❌ | ❌ |

### Rich content

Expand Down
4 changes: 3 additions & 1 deletion apps/docs/content/docs/adapters/telegram.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ TELEGRAM_API_BASE_URL=https://api.telegram.org
| Reactions (add/remove) | Yes |
| Cards | Text fallback + inline keyboard buttons/link buttons |
| Modals | No |
| Streaming | Post+Edit fallback |
| Streaming | `sendMessageDraft` in DMs + Post+Edit fallback |
| DMs | Yes |
| Ephemeral messages | No |
| File uploads | Single file (`sendDocument`) |
Expand All @@ -159,3 +159,5 @@ TELEGRAM_API_BASE_URL=https://api.telegram.org
- `Button` and `LinkButton` in card `Actions` render as inline keyboard buttons.
- Telegram callback data is limited to 64 bytes. Keep button `id`/`value` payloads short.
- Other rich card elements (images/select menus/radios) render as fallback text only.
- Native draft streaming (`sendMessageDraft`) is currently available in private chats; groups/channels use post+edit fallback.
- `{ markdown: ... }` and `{ ast: ... }` messages are sent with Telegram HTML parse mode for formatting support; plain strings and `{ raw: ... }` are sent as plain text.
2 changes: 1 addition & 1 deletion apps/docs/content/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Each adapter factory auto-detects credentials from environment variables (`SLACK
| Microsoft Teams | `@chat-adapter/teams` | Yes | Read-only | Yes | No | Post+Edit | Yes |
| Google Chat | `@chat-adapter/gchat` | Yes | Yes | Yes | No | Post+Edit | Yes |
| Discord | `@chat-adapter/discord` | Yes | Yes | Yes | No | Post+Edit | Yes |
| Telegram | `@chat-adapter/telegram` | Yes | Yes | Partial | No | Post+Edit | Yes |
| Telegram | `@chat-adapter/telegram` | Yes | Yes | Partial | No | Draft API (DMs) + Post+Edit | Yes |
| GitHub | `@chat-adapter/github` | Yes | Yes | No | No | No | No |
| Linear | `@chat-adapter/linear` | Yes | Yes | No | No | No | No |

Expand Down
1 change: 1 addition & 0 deletions apps/docs/content/docs/streaming.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ await thread.post(stream);
| Teams | Post + Edit | Posts a message then edits it as chunks arrive |
| Google Chat | Post + Edit | Posts a message then edits it as chunks arrive |
| Discord | Post + Edit | Posts a message then edits it as chunks arrive |
| Telegram | Draft API (DMs) + Post + Edit | Uses `sendMessageDraft` in private chats, falls back to post+edit in other chats |

The post+edit fallback throttles edits to avoid rate limits. Configure the update interval when creating your `Chat` instance:

Expand Down
52 changes: 51 additions & 1 deletion packages/adapter-telegram/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,57 @@ const bot = new Chat({
});
```

Features include mentions, reactions, typing indicators, file uploads, and card fallback rendering with inline keyboard buttons for card actions.
Features include mentions, reactions, typing indicators, file uploads, Markdown/AST formatting via Telegram HTML parse mode, Telegram draft streaming in DMs (`sendMessageDraft`) with post+edit fallback elsewhere, and card fallback rendering with inline keyboard buttons for card actions.

## Polling mode

When developing locally, you typically can't expose a public URL for Telegram to send webhooks to. Polling mode uses `getUpdates` to fetch messages directly from Telegram instead — no public endpoint needed.

The `longPolling` option is entirely optional. Sensible defaults are applied when omitted.

```typescript
import { createMemoryState } from "@chat-adapter/state-memory";

const telegram = createTelegramAdapter({
botToken: process.env.TELEGRAM_BOT_TOKEN!,
mode: "polling",
// Optional — fine-tune polling behavior:
// longPolling: { timeout: 30, dropPendingUpdates: false },
});

const bot = new Chat({
userName: "mybot",
adapters: { telegram },
state: createMemoryState(),
});

// Optional manual control
await telegram.resetWebhook();
await telegram.startPolling();
await telegram.stopPolling();
```

### Auto mode

With `mode: "auto"` (the default), the adapter picks the right strategy for you. In a serverless environment like Vercel it uses webhooks; everywhere else (e.g. local dev) it falls back to polling.

```typescript
const telegram = createTelegramAdapter({
botToken: process.env.TELEGRAM_BOT_TOKEN!,
mode: "auto", // default
});

const bot = new Chat({
userName: "mybot",
adapters: { telegram },
state: createMemoryState(),
});

// Call initialize() so polling can start in long-running local processes:
void bot.initialize();

console.log(telegram.runtimeMode); // "webhook" | "polling"
```

## Polling mode

Expand Down
Loading