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;