Skip to content
Merged
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
31 changes: 27 additions & 4 deletions gateway/src/adapters/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,36 @@ pub async fn webhook(
let source = event.source.as_ref();
let (channel_id, channel_type) = match source {
Some(s) if s.source_type == "group" => {
(s.group_id.clone().unwrap_or_default(), "group".to_string())
match s.group_id.as_deref() {
Some(id) if !id.is_empty() => (id.to_string(), "group".to_string()),
_ => {
warn!("LINE group event missing groupId, skipping");
continue;
}
}
}
Some(s) if s.source_type == "room" => {
(s.room_id.clone().unwrap_or_default(), "room".to_string())
match s.room_id.as_deref() {
Some(id) if !id.is_empty() => (id.to_string(), "room".to_string()),
_ => {
warn!("LINE room event missing roomId, skipping");
continue;
}
}
}
Some(s) => {
match s.user_id.as_deref() {
Some(id) if !id.is_empty() => (id.to_string(), "user".to_string()),
_ => {
warn!("LINE user event missing userId, skipping");
continue;
}
}
}
None => {
warn!("LINE event missing source, skipping");
continue;
}
Some(s) => (s.user_id.clone().unwrap_or_default(), "user".to_string()),
None => continue,
};
let user_id = source
.and_then(|s| s.user_id.as_deref())
Expand Down
10 changes: 7 additions & 3 deletions gateway/src/adapters/telegram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use std::sync::Arc;
use tokio::sync::Mutex;
use tracing::{error, info, warn};

/// Base URL for Telegram Bot API. Extracted as constant for consistency
/// with LINE's `LINE_API_BASE` and to enable future mock testing.
pub const TELEGRAM_API_BASE: &str = "https://api.telegram.org";

// --- Telegram types ---

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -140,7 +144,7 @@ pub async fn handle_reply(
if reply.command.as_deref() == Some("create_topic") {
let req_id = reply.request_id.clone().unwrap_or_default();
info!(chat_id = %reply.channel.id, "creating forum topic");
let url = format!("https://api.telegram.org/bot{bot_token}/createForumTopic");
let url = format!("{TELEGRAM_API_BASE}/bot{bot_token}/createForumTopic");
let resp = client
.post(&url)
.json(&serde_json::json!({"chat_id": reply.channel.id, "name": reply.content.text}))
Expand Down Expand Up @@ -222,7 +226,7 @@ pub async fn handle_reply(
})
.unwrap_or_default()
};
let url = format!("https://api.telegram.org/bot{bot_token}/setMessageReaction");
let url = format!("{TELEGRAM_API_BASE}/bot{bot_token}/setMessageReaction");
let _ = client
.post(&url)
.json(&serde_json::json!({
Expand All @@ -242,7 +246,7 @@ pub async fn handle_reply(
thread_id = ?reply.channel.thread_id,
"gateway → telegram"
);
let url = format!("https://api.telegram.org/bot{bot_token}/sendMessage");
let url = format!("{TELEGRAM_API_BASE}/bot{bot_token}/sendMessage");
let _ = client
.post(&url)
.json(&serde_json::json!({
Expand Down
Loading