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

@@ -809,12 +809,13 @@ export async function monitorSlackProvider(opts: MonitorSlackOpts = {}) {
});
const isRoomish = isRoom || isGroupDm;
const slackTo = isDirectMessage
? `user:${message.user}`
: `channel:${message.channel}`;
const ctxPayload = {
Body: body,
From: slackFrom,
To: isDirectMessage
? `user:${message.user}`
: `channel:${message.channel}`,
To: slackTo,
SessionKey: route.sessionKey,
AccountId: route.accountId,
ChatType: isDirectMessage ? "direct" : isRoom ? "room" : "group",
@@ -830,6 +831,9 @@ export async function monitorSlackProvider(opts: MonitorSlackOpts = {}) {
MediaType: media?.contentType,
MediaUrl: media?.path,
CommandAuthorized: commandAuthorized,
// Originating channel for reply routing.
OriginatingChannel: "slack" as const,
OriginatingTo: slackTo,
};
const replyTarget = ctxPayload.To ?? undefined;
@@ -1570,6 +1574,9 @@ export async function monitorSlackProvider(opts: MonitorSlackOpts = {}) {
AccountId: route.accountId,
CommandSource: "native" as const,
CommandAuthorized: commandAuthorized,
// Originating channel for reply routing.
OriginatingChannel: "slack" as const,
OriginatingTo: `user:${command.user_id}`,
};
const replyResult = await getReplyFromConfig(ctxPayload, undefined, cfg);