From 43c8cde3de2c4ec2e4c7312cee8a8722954e9fbc Mon Sep 17 00:00:00 2001 From: hope Date: Wed, 4 Mar 2026 19:35:04 +0800 Subject: [PATCH] fix: deliver inter-session replies to bound channel (Telegram) Fixes #34308 When a session has a deliveryContext bound to an external channel (e.g., Telegram), replies to inter-session messages (via sessions_send) were not being delivered to the bound channel - they were only stored in session history. This fix adds logic to resolveLastChannelRaw and resolveLastToRaw: - When incoming channel is INTERNAL but session has a persisted external channel (deliveryContext), use the persisted channel for reply delivery. --- src/auto-reply/reply/session-delivery.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/auto-reply/reply/session-delivery.ts b/src/auto-reply/reply/session-delivery.ts index 9a112a6829e..e69c3c7267f 100644 --- a/src/auto-reply/reply/session-delivery.ts +++ b/src/auto-reply/reply/session-delivery.ts @@ -117,6 +117,14 @@ export function resolveLastChannelRaw(params: { resolved = sessionKeyChannelHint; } } + // Fix #34308: When channel is INTERNAL but session has a persisted external channel + // (deliveryContext), use the persisted channel for reply delivery. + if ( + originatingChannel === INTERNAL_MESSAGE_CHANNEL && + isExternalRoutingChannel(persistedChannel) + ) { + resolved = persistedChannel; + } return resolved; } @@ -151,6 +159,15 @@ export function resolveLastToRaw(params: { } } + // Fix #34308: When channel is INTERNAL but session has a persisted external channel + // (deliveryContext), use the persisted to address for reply delivery. + if ( + originatingChannel === INTERNAL_MESSAGE_CHANNEL && + isExternalRoutingChannel(persistedChannel) + ) { + return params.persistedLastTo; + } + return params.originatingToRaw || params.toRaw || params.persistedLastTo; }