fix(whatsapp): use conversation id for context isolation (#911)
Thanks @tristanmanchester. Co-authored-by: Tristan Manchester <tmanchester96@gmail.com>
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
- Telegram: split long captions into media + follow-up text messages. (#907) - thanks @jalehman.
|
- Telegram: split long captions into media + follow-up text messages. (#907) - thanks @jalehman.
|
||||||
- Slack: drop Socket Mode events with mismatched `api_app_id`/`team_id`. (#889) — thanks @roshanasingh4.
|
- Slack: drop Socket Mode events with mismatched `api_app_id`/`team_id`. (#889) — thanks @roshanasingh4.
|
||||||
- Discord: isolate autoThread thread context. (#856) — thanks @davidguttman.
|
- Discord: isolate autoThread thread context. (#856) — thanks @davidguttman.
|
||||||
|
- WhatsApp: fix context isolation using wrong ID (was bot's number, now conversation ID). (#911) — thanks @tristanmanchester.
|
||||||
|
|
||||||
## 2026.1.13
|
## 2026.1.13
|
||||||
|
|
||||||
|
|||||||
41
src/auto-reply/reply/agent-runner-utils.test.ts
Normal file
41
src/auto-reply/reply/agent-runner-utils.test.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import type { ClawdbotConfig } from "../../config/config.js";
|
||||||
|
import type { TemplateContext } from "../templating.js";
|
||||||
|
import { buildThreadingToolContext } from "./agent-runner-utils.js";
|
||||||
|
|
||||||
|
describe("buildThreadingToolContext", () => {
|
||||||
|
const cfg = {} as ClawdbotConfig;
|
||||||
|
|
||||||
|
it("uses conversation id for WhatsApp", () => {
|
||||||
|
const sessionCtx = {
|
||||||
|
Provider: "whatsapp",
|
||||||
|
From: "123@g.us",
|
||||||
|
To: "+15550001",
|
||||||
|
} as TemplateContext;
|
||||||
|
|
||||||
|
const result = buildThreadingToolContext({
|
||||||
|
sessionCtx,
|
||||||
|
config: cfg,
|
||||||
|
hasRepliedRef: undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.currentChannelId).toBe("123@g.us");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses the recipient id for other channels", () => {
|
||||||
|
const sessionCtx = {
|
||||||
|
Provider: "telegram",
|
||||||
|
From: "user:42",
|
||||||
|
To: "chat:99",
|
||||||
|
} as TemplateContext;
|
||||||
|
|
||||||
|
const result = buildThreadingToolContext({
|
||||||
|
sessionCtx,
|
||||||
|
config: cfg,
|
||||||
|
hasRepliedRef: undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.currentChannelId).toBe("chat:99");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -25,13 +25,15 @@ export function buildThreadingToolContext(params: {
|
|||||||
if (!provider) return {};
|
if (!provider) return {};
|
||||||
const dock = getChannelDock(provider);
|
const dock = getChannelDock(provider);
|
||||||
if (!dock?.threading?.buildToolContext) return {};
|
if (!dock?.threading?.buildToolContext) return {};
|
||||||
|
// WhatsApp context isolation keys off conversation id, not the bot's own number.
|
||||||
|
const threadingTo = provider === "whatsapp" ? sessionCtx.From ?? sessionCtx.To : sessionCtx.To;
|
||||||
return (
|
return (
|
||||||
dock.threading.buildToolContext({
|
dock.threading.buildToolContext({
|
||||||
cfg: config,
|
cfg: config,
|
||||||
accountId: sessionCtx.AccountId,
|
accountId: sessionCtx.AccountId,
|
||||||
context: {
|
context: {
|
||||||
Channel: sessionCtx.Provider,
|
Channel: sessionCtx.Provider,
|
||||||
To: sessionCtx.To,
|
To: threadingTo,
|
||||||
ReplyToId: sessionCtx.ReplyToId,
|
ReplyToId: sessionCtx.ReplyToId,
|
||||||
ThreadLabel: sessionCtx.ThreadLabel,
|
ThreadLabel: sessionCtx.ThreadLabel,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user