mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-30 22:41:45 +00:00
feat(telegram/acp): Topic Binding, Pin Binding Message, Fix Spawn Param Parsing (#36683)
* fix(acp): normalize unicode flags and Telegram topic binding * feat(telegram/acp): restore topic-bound ACP and session bindings * fix(acpx): clarify permission-denied guidance * feat(telegram/acp): pin spawn bind notice in topics * docs(telegram): document ACP topic thread binding behavior * refactor(reply): share Telegram conversation-id resolver * fix(telegram/acp): preserve bound session routing semantics * fix(telegram): respect binding persistence and expiry reporting * refactor(telegram): simplify binding lifecycle persistence * fix(telegram): bind acp spawns in direct messages * fix: document telegram ACP topic binding changelog (#36683) (thanks @huntharo) --------- Co-authored-by: Onur <2453968+osolmaz@users.noreply.github.com>
This commit is contained in:
116
src/telegram/bot-message-context.thread-binding.test.ts
Normal file
116
src/telegram/bot-message-context.thread-binding.test.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const hoisted = vi.hoisted(() => {
|
||||
const resolveByConversationMock = vi.fn();
|
||||
const touchMock = vi.fn();
|
||||
return {
|
||||
resolveByConversationMock,
|
||||
touchMock,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../infra/outbound/session-binding-service.js", async (importOriginal) => {
|
||||
const actual =
|
||||
await importOriginal<typeof import("../infra/outbound/session-binding-service.js")>();
|
||||
return {
|
||||
...actual,
|
||||
getSessionBindingService: () => ({
|
||||
bind: vi.fn(),
|
||||
getCapabilities: vi.fn(),
|
||||
listBySession: vi.fn(),
|
||||
resolveByConversation: (ref: unknown) => hoisted.resolveByConversationMock(ref),
|
||||
touch: (bindingId: string, at?: number) => hoisted.touchMock(bindingId, at),
|
||||
unbind: vi.fn(),
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
const { buildTelegramMessageContextForTest } =
|
||||
await import("./bot-message-context.test-harness.js");
|
||||
|
||||
describe("buildTelegramMessageContext bound conversation override", () => {
|
||||
beforeEach(() => {
|
||||
hoisted.resolveByConversationMock.mockReset().mockReturnValue(null);
|
||||
hoisted.touchMock.mockReset();
|
||||
});
|
||||
|
||||
it("routes forum topic messages to the bound session", async () => {
|
||||
hoisted.resolveByConversationMock.mockReturnValue({
|
||||
bindingId: "default:-100200300:topic:77",
|
||||
targetSessionKey: "agent:codex-acp:session-1",
|
||||
});
|
||||
|
||||
const ctx = await buildTelegramMessageContextForTest({
|
||||
message: {
|
||||
message_id: 1,
|
||||
chat: { id: -100200300, type: "supergroup", is_forum: true },
|
||||
message_thread_id: 77,
|
||||
date: 1_700_000_000,
|
||||
text: "hello",
|
||||
from: { id: 42, first_name: "Alice" },
|
||||
},
|
||||
options: { forceWasMentioned: true },
|
||||
resolveGroupActivation: () => true,
|
||||
});
|
||||
|
||||
expect(hoisted.resolveByConversationMock).toHaveBeenCalledWith({
|
||||
channel: "telegram",
|
||||
accountId: "default",
|
||||
conversationId: "-100200300:topic:77",
|
||||
});
|
||||
expect(ctx?.ctxPayload?.SessionKey).toBe("agent:codex-acp:session-1");
|
||||
expect(hoisted.touchMock).toHaveBeenCalledWith("default:-100200300:topic:77", undefined);
|
||||
});
|
||||
|
||||
it("treats named-account bound conversations as explicit route matches", async () => {
|
||||
hoisted.resolveByConversationMock.mockReturnValue({
|
||||
bindingId: "work:-100200300:topic:77",
|
||||
targetSessionKey: "agent:codex-acp:session-2",
|
||||
});
|
||||
|
||||
const ctx = await buildTelegramMessageContextForTest({
|
||||
accountId: "work",
|
||||
message: {
|
||||
message_id: 1,
|
||||
chat: { id: -100200300, type: "supergroup", is_forum: true },
|
||||
message_thread_id: 77,
|
||||
date: 1_700_000_000,
|
||||
text: "hello",
|
||||
from: { id: 42, first_name: "Alice" },
|
||||
},
|
||||
options: { forceWasMentioned: true },
|
||||
resolveGroupActivation: () => true,
|
||||
});
|
||||
|
||||
expect(ctx).not.toBeNull();
|
||||
expect(ctx?.route.accountId).toBe("work");
|
||||
expect(ctx?.route.matchedBy).toBe("binding.channel");
|
||||
expect(ctx?.ctxPayload?.SessionKey).toBe("agent:codex-acp:session-2");
|
||||
expect(hoisted.touchMock).toHaveBeenCalledWith("work:-100200300:topic:77", undefined);
|
||||
});
|
||||
|
||||
it("routes dm messages to the bound session", async () => {
|
||||
hoisted.resolveByConversationMock.mockReturnValue({
|
||||
bindingId: "default:1234",
|
||||
targetSessionKey: "agent:codex-acp:session-dm",
|
||||
});
|
||||
|
||||
const ctx = await buildTelegramMessageContextForTest({
|
||||
message: {
|
||||
message_id: 1,
|
||||
chat: { id: 1234, type: "private" },
|
||||
date: 1_700_000_000,
|
||||
text: "hello",
|
||||
from: { id: 42, first_name: "Alice" },
|
||||
},
|
||||
});
|
||||
|
||||
expect(hoisted.resolveByConversationMock).toHaveBeenCalledWith({
|
||||
channel: "telegram",
|
||||
accountId: "default",
|
||||
conversationId: "1234",
|
||||
});
|
||||
expect(ctx?.ctxPayload?.SessionKey).toBe("agent:codex-acp:session-dm");
|
||||
expect(hoisted.touchMock).toHaveBeenCalledWith("default:1234", undefined);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user