Simplify Telegram channel config with host-injected tunnel/webhook settings

The WASM channel no longer needs its own polling_enabled/tunnel_url settings.
Instead, the host injects tunnel_url and webhook_secret into the channel config
at runtime before start() is called.

Changes:
- Add update_config() method to WasmChannel for runtime config injection
- Simplify TelegramConfig to only have bot_username, respond_to_all_group_messages
- Host injects tunnel_url (from Settings) and webhook_secret (from secrets store)
- Channel checks if tunnel_url is present to determine webhook vs polling mode
- Add delete_webhook() for clean transition to polling mode when no tunnel

Co-Authored-By: Claude Opus 4.5 <[email protected]>
This commit is contained in:
Illia Polosukhin
2026-02-05 00:05:32 -08:00
co-authored by Claude Opus 4.5
parent e6946172f7
commit 9edc666ee3
3 changed files with 141 additions and 36 deletions
+30 -3
View File
@@ -373,7 +373,8 @@ pub struct WasmChannel {
capabilities: ChannelCapabilities,
/// Channel configuration JSON (passed to on_start).
config_json: String,
/// Wrapped in RwLock to allow updating before start.
config_json: RwLock<String>,
/// Channel configuration returned by on_start.
channel_config: RwLock<Option<ChannelConfig>>,
@@ -420,7 +421,7 @@ impl WasmChannel {
runtime,
prepared,
capabilities,
config_json,
config_json: RwLock::new(config_json),
channel_config: RwLock::new(None),
message_tx: Arc::new(RwLock::new(None)),
pending_responses: RwLock::new(HashMap::new()),
@@ -432,6 +433,32 @@ impl WasmChannel {
}
}
/// Update the channel config before starting.
///
/// Merges the provided values into the existing config JSON.
/// Call this before `start()` to inject runtime values like tunnel_url.
pub async fn update_config(&self, updates: HashMap<String, serde_json::Value>) {
let mut config_guard = self.config_json.write().await;
// Parse existing config
let mut config: HashMap<String, serde_json::Value> =
serde_json::from_str(&config_guard).unwrap_or_default();
// Merge updates
for (key, value) in updates {
config.insert(key, value);
}
// Serialize back
*config_guard = serde_json::to_string(&config).unwrap_or_else(|_| "{}".to_string());
tracing::debug!(
channel = %self.name,
config = %*config_guard,
"Updated channel config"
);
}
/// Set a credential for URL injection.
pub async fn set_credential(&self, name: &str, value: String) {
self.credentials
@@ -590,7 +617,7 @@ impl WasmChannel {
let runtime = Arc::clone(&self.runtime);
let prepared = Arc::clone(&self.prepared);
let capabilities = self.capabilities.clone();
let config_json = self.config_json.clone();
let config_json = self.config_json.read().await.clone();
let timeout = self.runtime.config().callback_timeout;
let channel_name = self.name.clone();
let credentials = self.get_credentials().await;
+31 -1
View File
@@ -399,6 +399,36 @@ async fn main() -> anyhow::Result<()> {
let channel_arc = Arc::new(loaded.channel);
// Inject runtime config into the channel (tunnel_url, webhook_secret)
// This must be done before start() is called
{
let mut config_updates = std::collections::HashMap::new();
if let Some(ref tunnel_url) = config.tunnel.public_url {
config_updates.insert(
"tunnel_url".to_string(),
serde_json::Value::String(tunnel_url.clone()),
);
}
if let Some(ref secret) = webhook_secret {
config_updates.insert(
"webhook_secret".to_string(),
serde_json::Value::String(secret.clone()),
);
}
if !config_updates.is_empty() {
channel_arc.update_config(config_updates).await;
tracing::info!(
channel = %channel_name,
has_tunnel = config.tunnel.public_url.is_some(),
has_webhook_secret = webhook_secret.is_some(),
"Injected runtime config into channel"
);
}
}
tracing::info!(
channel = %channel_name,
has_webhook_secret = webhook_secret.is_some(),
@@ -410,7 +440,7 @@ async fn main() -> anyhow::Result<()> {
.register(
Arc::clone(&channel_arc),
endpoints,
webhook_secret,
webhook_secret.clone(),
secret_header,
)
.await;