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.
This commit is contained in:
hope 2026-03-04 19:35:04 +08:00
parent 2c5fd8e0c1
commit 43c8cde3de

View File

@ -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;
}