



























@@ -1,10 +1,5 @@
11import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
2-import {
3-createReplyDispatcher,
4-resetInboundDedupe,
5-type GetReplyOptions,
6-type MsgContext,
7-} from "openclaw/plugin-sdk/reply-runtime";
2+import type { GetReplyOptions, MsgContext } from "openclaw/plugin-sdk/reply-runtime";
83import type { MockFn } from "openclaw/plugin-sdk/testing";
94import { beforeEach, vi } from "vitest";
105import type { TelegramBotDeps } from "./bot-deps.js";
@@ -31,12 +26,6 @@ type ReplyPayloadLike = {
3126replyToId?: string;
3227};
332834-const _EMPTY_REPLY_COUNTS: DispatchReplyWithBufferedBlockDispatcherResult["counts"] = {
35-block: 0,
36-final: 0,
37-tool: 0,
38-};
39-4029const { sessionStorePath } = vi.hoisted(() => ({
4130sessionStorePath: `/tmp/openclaw-telegram-${process.pid}-${process.env.VITEST_POOL_ID ?? "0"}.json`,
4231}));
@@ -133,29 +122,22 @@ async function dispatchHarnessReplies(
133122const reply = await runReply(params);
134123const payloads: ReplyPayloadLike[] =
135124reply === undefined ? [] : Array.isArray(reply) ? reply : [reply];
136-const dispatcher = createReplyDispatcher({
137-deliver: async (payload, info) => {
138-await params.dispatcherOptions.deliver?.(payload, info);
139-},
140-responsePrefix: params.dispatcherOptions.responsePrefix,
141-responsePrefixContextProvider: params.dispatcherOptions.responsePrefixContextProvider,
142-responsePrefixContext: params.dispatcherOptions.responsePrefixContext,
143-onHeartbeatStrip: params.dispatcherOptions.onHeartbeatStrip,
144-onSkip: (payload, info) => {
145-params.dispatcherOptions.onSkip?.(payload, info);
146-},
147-onError: (err, info) => {
148-params.dispatcherOptions.onError?.(err, info);
149-},
150-});
151125let finalCount = 0;
152126for (const payload of payloads) {
153-if (dispatcher.sendFinalReply(payload)) {
127+const text =
128+typeof payload.text === "string" &&
129+params.dispatcherOptions.responsePrefix &&
130+!payload.text.startsWith(params.dispatcherOptions.responsePrefix)
131+ ? `${params.dispatcherOptions.responsePrefix} ${payload.text}`
132+ : payload.text;
133+const finalPayload = text === payload.text ? payload : { ...payload, text };
134+try {
135+await params.dispatcherOptions.deliver?.(finalPayload, { kind: "final" });
154136finalCount += 1;
137+} catch (err) {
138+params.dispatcherOptions.onError?.(err, { kind: "final" });
155139}
156140}
157-dispatcher.markComplete();
158-await dispatcher.waitForIdle();
159141return {
160142queuedFinal: finalCount > 0,
161143counts: {
@@ -472,7 +454,6 @@ export function makeForumGroupMessageCtx(params?: {
472454}
473455474456beforeEach(() => {
475-resetInboundDedupe();
476457loadConfig.mockReset();
477458loadConfig.mockReturnValue(DEFAULT_TELEGRAM_TEST_CONFIG);
478459sessionStoreEntries.value = {};
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。