feat(routing): route replies to originating channel

Implement reply routing based on OriginatingChannel/OriginatingTo fields.
This ensures replies go back to the provider where the message originated
instead of using the session's lastChannel.

Changes:
- Add OriginatingChannel/OriginatingTo fields to MsgContext (templating.ts)
- Add originatingChannel/originatingTo fields to FollowupRun (queue.ts)
- Create route-reply.ts with provider-agnostic router
- Update all providers (Telegram, Slack, Discord, Signal, iMessage)
  to pass originating channel info
- Update reply.ts to pass originating channel to followupRun
- Update followup-runner.ts to use route-reply for originating channels

This addresses the issue where messages from one provider (e.g., Slack)
would receive replies on a different provider (e.g., Telegram) because
the queue used the last active dispatcher instead of the originating one.
This commit is contained in:
Josh Lehman
2026-01-06 10:58:45 -08:00
committed by Peter Steinberger
parent 514fcfe77e
commit 9d50ebad7d
10 changed files with 238 additions and 12 deletions

View File

@@ -414,6 +414,7 @@ export function createTelegramBot(opts: TelegramBotOptions) {
SenderId: senderId || undefined,
SenderUsername: senderUsername || undefined,
Provider: "telegram",
Surface: "telegram",
MessageSid: String(msg.message_id),
ReplyToId: replyTarget?.id,
ReplyToBody: replyTarget?.body,
@@ -433,6 +434,9 @@ export function createTelegramBot(opts: TelegramBotOptions) {
CommandAuthorized: commandAuthorized,
MessageThreadId: messageThreadId,
IsForum: isForum,
// Originating channel for reply routing.
OriginatingChannel: "telegram" as const,
OriginatingTo: `telegram:${chatId}`,
};
if (replyTarget && shouldLogVerbose()) {