Skip to content

Commit 0ff4a2f

Browse files
committed
feat(telegram): auto-disable table code-block wrapping for native rendering
Telegram Rich Messages render markdown tables natively, but OAB's default table mode wraps them in code blocks — requiring every Telegram deployment to manually set [markdown] tables = "off" in config.toml. Now both adapters (unified and standalone gateway) implement renders_native_tables() to return true for Telegram, so the table pre-pass is automatically skipped. No config change needed for new or existing Telegram deployments. - UnifiedGatewayAdapter: returns true when telegram_rich_messages is enabled - GatewayAdapter: returns true when platform_name == "telegram" - Updated docs/telegram.md to remove the manual [markdown] requirement
1 parent 4f28c2d commit 0ff4a2f

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

crates/openab-core/src/gateway.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,12 @@ impl ChatAdapter for GatewayAdapter {
730730
fn show_streaming_placeholder(&self) -> bool {
731731
self.streaming_placeholder
732732
}
733+
734+
fn renders_native_tables(&self) -> bool {
735+
// Telegram renders markdown tables natively via Rich Messages;
736+
// skip the table→code-block pre-pass for that platform.
737+
self.platform_name == "telegram"
738+
}
733739
}
734740

735741
// --- Run the gateway adapter (connects to gateway WS, routes events to AdapterRouter) ---

docs/telegram.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,24 @@ Set environment variables:
4040

4141
OAB config (`config.toml`):
4242

43-
**Minimal**just pass the API key to the agent:
43+
**Minimal**bot token via env var, API key passed to agent:
4444

4545
```toml
46+
[telegram]
47+
bot_token = "${TELEGRAM_BOT_TOKEN}"
48+
allow_all_users = true
49+
4650
[agent]
4751
env = { KIRO_API_KEY = "${KIRO_API_KEY}" }
4852
```
4953

50-
**Recommended** — with tuned pool, streaming, and native table rendering:
54+
**Recommended** — with access control, tuned pool, and streaming:
5155

5256
```toml
57+
[telegram]
58+
bot_token = "${TELEGRAM_BOT_TOKEN}"
59+
allowed_users = ["176096071"]
60+
5361
[agent]
5462
env = { KIRO_API_KEY = "${KIRO_API_KEY}" }
5563

@@ -59,9 +67,13 @@ session_ttl_hours = 1
5967

6068
[reactions]
6169
tool_display = "compact"
70+
```
71+
72+
Table rendering is automatically disabled for Telegram (tables pass through as native markdown for Rich Messages). To force code-block wrapping, set explicitly:
6273

74+
```toml
6375
[markdown]
64-
tables = "off"
76+
tables = "code"
6577
```
6678

6779
Streaming is enabled by default when Rich Messages are active — replies are streamed live via `sendRichMessageDraft` with rich formatting, then finalized with `sendRichMessage`. If `TELEGRAM_RICH_MESSAGES=false`, streaming is also disabled by default. To override, set `TELEGRAM_STREAMING=true` or `TELEGRAM_STREAMING=false` explicitly.
@@ -356,11 +368,11 @@ Agent replies are rendered with Telegram Markdown: **bold**, `code`, and code bl
356368

357369
With **Rich Messages** enabled (default, requires Bot API 10.1+), headings (`##`) and tables render with full formatting via `sendRichMessage`. Code blocks remain on the legacy path for syntax highlighting and copy-button support. Content exceeding 4096 characters is automatically handled via rich messages (up to 32768 chars).
358370

359-
> **Important:** OAB's default table mode wraps markdown tables in code blocks before they reach the gateway. To allow native Telegram table rendering via Rich Messages, disable this conversion in your `config.toml`:
371+
> **Note:** As of v0.9.0, OAB automatically disables table code-block wrapping for Telegram adapters (both unified and standalone gateway) when Rich Messages are enabled. Tables pass through as raw markdown and render natively. No `[markdown]` config is needed. To override this and force code-block wrapping, add:
360372
>
361373
> ```toml
362374
> [markdown]
363-
> tables = "off"
375+
> tables = "code"
364376
> ```
365377
>
366378
> Rich Messages requires gateway version **v0.6.0-rc.1** or above (`ghcr.io/openabdev/openab-gateway:v0.6.0-rc.1`+).

src/unified_adapter.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,10 @@ impl ChatAdapter for UnifiedGatewayAdapter {
217217
// The draft mechanism handles the "typing" indicator natively.
218218
false
219219
}
220+
221+
fn renders_native_tables(&self) -> bool {
222+
// Telegram Rich Messages render markdown tables natively — skip the
223+
// table→code-block pre-pass so tables display with proper formatting.
224+
self.gw_state.telegram_rich_messages
225+
}
220226
}

0 commit comments

Comments
 (0)