


























@@ -0,0 +1,80 @@
1+import { buildChannelInboundEventContext } from "openclaw/plugin-sdk/channel-inbound";
2+import { describe, expect, it, vi } from "vitest";
3+import { buildTelegramMessageContextForTest } from "./bot-message-context.test-harness.js";
4+import type { TelegramSendChatActionHandler } from "./sendchataction-401-backoff.js";
5+6+function createSendChatActionHandler(
7+sendChatAction = vi.fn(async () => undefined),
8+): TelegramSendChatActionHandler & { sendChatAction: typeof sendChatAction } {
9+return {
10+ sendChatAction,
11+isSuspended: () => false,
12+reset: () => undefined,
13+};
14+}
15+16+describe("buildTelegramMessageContext typing", () => {
17+it("sends direct typing after body resolution and before session context construction", async () => {
18+const buildInboundContext = vi.fn(buildChannelInboundEventContext);
19+const sendChatActionHandler = createSendChatActionHandler();
20+21+await expect(
22+buildTelegramMessageContextForTest({
23+message: {
24+chat: { id: 42, type: "private", first_name: "Pat" },
25+from: { id: 42, first_name: "Pat" },
26+text: "hello",
27+},
28+ sendChatActionHandler,
29+sessionRuntime: {
30+buildChannelInboundEventContext: buildInboundContext,
31+},
32+}),
33+).resolves.not.toBeNull();
34+35+expect(sendChatActionHandler.sendChatAction).toHaveBeenCalledWith(42, "typing", undefined);
36+expect(sendChatActionHandler.sendChatAction.mock.invocationCallOrder[0]).toBeLessThan(
37+buildInboundContext.mock.invocationCallOrder[0],
38+);
39+});
40+41+it("does not send direct typing when there is no replyable body", async () => {
42+const sendChatActionHandler = createSendChatActionHandler();
43+44+await expect(
45+buildTelegramMessageContextForTest({
46+message: {
47+chat: { id: 42, type: "private", first_name: "Pat" },
48+from: { id: 42, first_name: "Pat" },
49+text: undefined,
50+},
51+ sendChatActionHandler,
52+}),
53+).resolves.toBeNull();
54+55+expect(sendChatActionHandler.sendChatAction).not.toHaveBeenCalled();
56+});
57+58+it("does not send early direct typing before DM access passes", async () => {
59+const sendChatActionHandler = createSendChatActionHandler();
60+61+await expect(
62+buildTelegramMessageContextForTest({
63+message: {
64+chat: { id: 42, type: "private", first_name: "Pat" },
65+from: { id: 42, first_name: "Pat" },
66+text: "hello",
67+},
68+cfg: {
69+agents: { defaults: { model: "anthropic/claude-opus-4-5", workspace: "/tmp/openclaw" } },
70+channels: { telegram: { dmPolicy: "disabled", allowFrom: [] } },
71+messages: { groupChat: { mentionPatterns: [] } },
72+},
73+dmPolicy: "disabled",
74+ sendChatActionHandler,
75+}),
76+).resolves.toBeNull();
77+78+expect(sendChatActionHandler.sendChatAction).not.toHaveBeenCalled();
79+});
80+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。