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

@@ -741,14 +741,13 @@ export function createDiscordMessageHandler(params: {
combinedBody = `[Replied message - for context]\n${replyContext}\n\n${combinedBody}`;
}
const discordTo = `channel:${message.channelId}`;
const ctxPayload = {
Body: combinedBody,
From: isDirectMessage
? `discord:${author.id}`
: `group:${message.channelId}`,
To: isDirectMessage
? `user:${author.id}`
: `channel:${message.channelId}`,
To: discordTo,
SessionKey: route.sessionKey,
AccountId: route.accountId,
ChatType: isDirectMessage ? "direct" : "group",
@@ -772,6 +771,9 @@ export function createDiscordMessageHandler(params: {
MediaUrl: media?.path,
CommandAuthorized: commandAuthorized,
CommandSource: "text" as const,
// Originating channel for reply routing.
OriginatingChannel: "discord" as const,
OriginatingTo: discordTo,
};
const replyTarget = ctxPayload.To ?? undefined;
if (!replyTarget) {