Skip to content

Commit 2e1684a

Browse files
committed
fix(review): add platform context to renders_native_tables() and standalone rich_messages check
- Add platform parameter to ChatAdapter::renders_native_tables() trait method so unified adapter can make per-platform decisions (fixes regression where all platforms would skip table wrapping when telegram_rich_messages=true) - UnifiedGatewayAdapter now checks platform == "telegram" && rich_messages - GatewayAdapter (standalone) now checks both platform_name and a new telegram_rich_messages config field (added to GatewayConfig/GatewayParams) - Update all call sites (AdapterRouter, Slack, tests) to pass platform arg Fixes: unified mode multi-platform regression (F1) Fixes: standalone mode Rich Messages assumption (F2)
1 parent 0ff4a2f commit 2e1684a

6 files changed

Lines changed: 27 additions & 10 deletions

File tree

crates/openab-core/src/adapter.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,10 @@ pub trait ChatAdapter: Send + Sync + 'static {
407407
/// lets the platform render the raw Markdown table itself.
408408
/// Default: `false` (keep converting). Overridden by Slack (Block Kit
409409
/// `markdown` blocks / `markdown_text` stream chunks render tables natively).
410-
fn renders_native_tables(&self) -> bool {
410+
/// The `platform` parameter allows shared adapters (e.g. UnifiedGatewayAdapter)
411+
/// to make per-platform decisions.
412+
fn renders_native_tables(&self, platform: &str) -> bool {
413+
let _ = platform;
411414
false
412415
}
413416

@@ -697,7 +700,7 @@ impl AdapterRouter {
697700
// Platforms that render Markdown tables natively (e.g. Slack Block Kit
698701
// `markdown` blocks / `markdown_text` stream chunks) skip the
699702
// table→code/bullets pre-pass so the raw table renders natively.
700-
let table_mode = if adapter.renders_native_tables() {
703+
let table_mode = if adapter.renders_native_tables(&thread_channel.platform) {
701704
TableMode::Off
702705
} else {
703706
self.table_mode
@@ -1794,7 +1797,7 @@ mod tests {
17941797
assert!(!adapter.use_streaming(false));
17951798
// renders_native_tables defaults to false: platforms that don't override
17961799
// it keep the table→code/bullets conversion (e.g. Discord, Gateway).
1797-
assert!(!adapter.renders_native_tables());
1800+
assert!(!adapter.renders_native_tables("discord"));
17981801
}
17991802

18001803
#[test]

crates/openab-core/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,11 @@ pub struct GatewayConfig {
567567
/// Show "…" placeholder at streaming start. Default: true. Set false for platforms using drafts.
568568
#[serde(default = "default_true")]
569569
pub streaming_placeholder: bool,
570+
/// Whether the connected gateway renders tables natively (e.g. Telegram Rich Messages).
571+
/// Default: true (matches Telegram default). Set false if Rich Messages is disabled
572+
/// on the gateway daemon to preserve table code-block wrapping.
573+
#[serde(default = "default_true")]
574+
pub telegram_rich_messages: bool,
570575
/// Message dispatch mode. Default: per-message.
571576
#[serde(default)]
572577
pub message_processing_mode: MessageProcessingMode,

crates/openab-core/src/gateway.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ pub struct GatewayAdapter {
233233
platform_name: &'static str,
234234
streaming: bool,
235235
streaming_placeholder: bool,
236+
telegram_rich_messages: bool,
236237
}
237238

238239
impl GatewayAdapter {
@@ -242,13 +243,15 @@ impl GatewayAdapter {
242243
platform_name: &'static str,
243244
streaming: bool,
244245
streaming_placeholder: bool,
246+
telegram_rich_messages: bool,
245247
) -> Self {
246248
Self {
247249
ws_tx,
248250
pending,
249251
platform_name,
250252
streaming,
251253
streaming_placeholder,
254+
telegram_rich_messages,
252255
}
253256
}
254257

@@ -731,10 +734,11 @@ impl ChatAdapter for GatewayAdapter {
731734
self.streaming_placeholder
732735
}
733736

734-
fn renders_native_tables(&self) -> bool {
737+
fn renders_native_tables(&self, _platform: &str) -> bool {
735738
// Telegram renders markdown tables natively via Rich Messages;
736-
// skip the table→code-block pre-pass for that platform.
737-
self.platform_name == "telegram"
739+
// skip the table→code-block pre-pass for that platform only when
740+
// Rich Messages is confirmed enabled.
741+
self.platform_name == "telegram" && self.telegram_rich_messages
738742
}
739743
}
740744

@@ -754,6 +758,7 @@ pub struct GatewayParams {
754758
pub trusted_bot_ids: Vec<String>,
755759
pub streaming: bool,
756760
pub streaming_placeholder: bool,
761+
pub telegram_rich_messages: bool,
757762
pub stt: crate::config::SttConfig,
758763
}
759764

@@ -788,6 +793,7 @@ pub async fn run_gateway_adapter(
788793
params.streaming
789794
};
790795
let streaming_placeholder = params.streaming_placeholder;
796+
let telegram_rich_messages = params.telegram_rich_messages;
791797
let stt_config = params.stt;
792798

793799
let connect_url = match &params.token {
@@ -838,6 +844,7 @@ pub async fn run_gateway_adapter(
838844
platform,
839845
streaming,
840846
streaming_placeholder,
847+
telegram_rich_messages,
841848
));
842849
let slash_ws_tx = ws_tx.clone(); // for fire-and-forget slash command responses
843850
let mut tasks: tokio::task::JoinSet<()> = tokio::task::JoinSet::new();

crates/openab-core/src/slack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ impl ChatAdapter for SlackAdapter {
544544
self.streaming && !other_bot_present
545545
}
546546

547-
fn renders_native_tables(&self) -> bool {
547+
fn renders_native_tables(&self, _platform: &str) -> bool {
548548
true
549549
}
550550

@@ -2307,7 +2307,7 @@ mod tests {
23072307
fn slack_renders_native_tables() {
23082308
let ttl = std::time::Duration::from_secs(300);
23092309
let adapter = SlackAdapter::new("xoxb-test".into(), ttl, AllowBots::Mentions, true, crate::multibot_cache::MultibotCache::load("/dev/null".into()), true);
2310-
assert!(adapter.renders_native_tables());
2310+
assert!(adapter.renders_native_tables("slack"));
23112311
}
23122312
}
23132313

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ async fn main() -> anyhow::Result<()> {
587587
trusted_bot_ids: gw_cfg.trusted_bot_ids,
588588
streaming: gw_cfg.streaming,
589589
streaming_placeholder: gw_cfg.streaming_placeholder,
590+
telegram_rich_messages: gw_cfg.telegram_rich_messages,
590591
stt: cfg.stt.clone(),
591592
};
592593
let gw_router = router.clone();

src/unified_adapter.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,10 @@ impl ChatAdapter for UnifiedGatewayAdapter {
218218
false
219219
}
220220

221-
fn renders_native_tables(&self) -> bool {
221+
fn renders_native_tables(&self, platform: &str) -> bool {
222222
// Telegram Rich Messages render markdown tables natively — skip the
223223
// table→code-block pre-pass so tables display with proper formatting.
224-
self.gw_state.telegram_rich_messages
224+
// Only applies to Telegram; other platforms in unified mode keep wrapping.
225+
platform == "telegram" && self.gw_state.telegram_rich_messages
225226
}
226227
}

0 commit comments

Comments
 (0)