Skip to content

Commit c2410d2

Browse files
feat: WeCom Stream Mode (WebSocket long-connection)
1 parent a78299e commit c2410d2

File tree

5 files changed

+877
-0
lines changed

5 files changed

+877
-0
lines changed

crates/openfang-api/src/channel_bridge.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use openfang_channels::teams::TeamsAdapter;
1818
use openfang_channels::telegram::TelegramAdapter;
1919
use openfang_channels::twitch::TwitchAdapter;
2020
use openfang_channels::types::ChannelAdapter;
21+
use openfang_channels::wecom_stream::WeComStreamAdapter;
2122
use openfang_channels::whatsapp::WhatsAppAdapter;
2223
use openfang_channels::xmpp::XmppAdapter;
2324
use openfang_channels::zulip::ZulipAdapter;
@@ -812,6 +813,7 @@ impl ChannelBridgeHandle for KernelBridgeAdapter {
812813
"linkedin" => channels.linkedin.as_ref().map(|c| c.overrides.clone()),
813814
"wecom" => channels.wecom.as_ref().map(|c| c.overrides.clone()),
814815
"mqtt" => channels.mqtt.as_ref().map(|c| c.overrides.clone()),
816+
"wecom_stream" => channels.wecom_stream.as_ref().map(|c| c.overrides.clone()),
815817
_ => None,
816818
}
817819
}
@@ -1116,6 +1118,7 @@ pub async fn start_channel_bridge_with_config(
11161118
|| config.ntfy.is_some()
11171119
|| config.gotify.is_some()
11181120
|| config.webhook.is_some()
1121+
|| config.wecom_stream.is_some()
11191122
|| config.linkedin.is_some();
11201123

11211124
if !has_any {
@@ -1477,6 +1480,14 @@ pub async fn start_channel_bridge_with_config(
14771480
}
14781481
}
14791482

1483+
// WeCom Stream
1484+
if let Some(ref ws_config) = config.wecom_stream {
1485+
if let Some(secret) = read_token(&ws_config.secret_env, "WECOM_WS_SECRET") {
1486+
let adapter = Arc::new(WeComStreamAdapter::new(ws_config.bot_id.clone(), secret));
1487+
adapters.push((adapter, ws_config.default_agent.clone()));
1488+
}
1489+
}
1490+
14801491
// ── Wave 4 ──────────────────────────────────────────────────
14811492

14821493
// Nextcloud Talk

crates/openfang-api/src/routes.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,6 +2208,20 @@ const CHANNEL_REGISTRY: &[ChannelMeta] = &[
22082208
setup_steps: &["Create a WeCom application at work.weixin.qq.com", "Get Corp ID, Agent ID, and Secret", "Configure callback URL to your webhook endpoint"],
22092209
config_template: "[channels.wecom]\ncorp_id = \"\"\nagent_id = \"\"\nsecret_env = \"WECOM_SECRET\"",
22102210
},
2211+
ChannelMeta {
2212+
name: "wecom_stream", display_name: "WeCom Stream", icon: "WC",
2213+
description: "WeCom Stream Mode (WebSocket long-connection)",
2214+
category: "enterprise", difficulty: "Easy", setup_time: "~5 min",
2215+
quick_setup: "Create an Enterprise Internal App with Stream Mode enabled",
2216+
setup_type: "form",
2217+
fields: &[
2218+
ChannelField { key: "bot_id", label: "Bot ID (Corp ID)", field_type: FieldType::Text, env_var: None, required: true, placeholder: "ww...", advanced: false },
2219+
ChannelField { key: "secret_env", label: "Secret", field_type: FieldType::Secret, env_var: Some("WECOM_WS_SECRET"), required: true, placeholder: "secret...", advanced: false },
2220+
ChannelField { key: "default_agent", label: "Default Agent", field_type: FieldType::Text, env_var: None, required: false, placeholder: "assistant", advanced: true },
2221+
],
2222+
setup_steps: &["Create an Enterprise Internal App in WeCom Open Platform", "Enable Stream Mode in the app settings", "Copy Bot ID (Corp ID) and Secret below"],
2223+
config_template: "[channels.wecom_stream]\nbot_id = \"\"\nsecret_env = \"WECOM_WS_SECRET\"",
2224+
},
22112225
];
22122226

22132227
/// Check if a channel is configured (has a `[channels.xxx]` section in config).
@@ -2255,6 +2269,7 @@ fn is_channel_configured(config: &openfang_types::config::ChannelsConfig, name:
22552269
"webhook" => config.webhook.is_some(),
22562270
"mumble" => config.mumble.is_some(),
22572271
"wecom" => config.wecom.is_some(),
2272+
"wecom_stream" => config.wecom_stream.is_some(),
22582273
_ => false,
22592274
}
22602275
}

crates/openfang-channels/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ pub mod mumble;
5353
pub mod ntfy;
5454
pub mod webhook;
5555
pub mod wecom;
56+
pub mod wecom_stream;

0 commit comments

Comments
 (0)