mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 10:55:07 +00:00
refactor: unify queueing and normalize telegram slack flows
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { markdownToSlackMrkdwn } from "./format.js";
|
||||
import { markdownToSlackMrkdwn, normalizeSlackOutboundText } from "./format.js";
|
||||
import { escapeSlackMrkdwn } from "./monitor/mrkdwn.js";
|
||||
|
||||
describe("markdownToSlackMrkdwn", () => {
|
||||
@@ -72,3 +72,9 @@ describe("escapeSlackMrkdwn", () => {
|
||||
expect(escapeSlackMrkdwn("mode_*`~<&>\\")).toBe("mode\\_\\*\\`\\~<&>\\\\");
|
||||
});
|
||||
});
|
||||
|
||||
describe("normalizeSlackOutboundText", () => {
|
||||
it("normalizes markdown for outbound send/update paths", () => {
|
||||
expect(normalizeSlackOutboundText(" **bold** ")).toBe("*bold*");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -128,6 +128,10 @@ export function markdownToSlackMrkdwn(
|
||||
return renderMarkdownWithMarkers(ir, buildSlackRenderOptions());
|
||||
}
|
||||
|
||||
export function normalizeSlackOutboundText(markdown: string): string {
|
||||
return markdownToSlackMrkdwn(markdown ?? "");
|
||||
}
|
||||
|
||||
export function markdownToSlackMrkdwnChunks(
|
||||
markdown: string,
|
||||
limit: number,
|
||||
|
||||
@@ -12,7 +12,7 @@ import { danger, logVerbose, shouldLogVerbose } from "../../../globals.js";
|
||||
import { resolveAgentOutboundIdentity } from "../../../infra/outbound/identity.js";
|
||||
import { removeSlackReaction } from "../../actions.js";
|
||||
import { createSlackDraftStream } from "../../draft-stream.js";
|
||||
import { markdownToSlackMrkdwn } from "../../format.js";
|
||||
import { normalizeSlackOutboundText } from "../../format.js";
|
||||
import { recordSlackThreadParticipation } from "../../sent-thread-cache.js";
|
||||
import {
|
||||
applyAppendOnlyStreamUpdate,
|
||||
@@ -291,7 +291,7 @@ export async function dispatchPreparedSlackMessage(prepared: PreparedSlackMessag
|
||||
token: ctx.botToken,
|
||||
channel: draftChannelId,
|
||||
ts: draftMessageId,
|
||||
text: markdownToSlackMrkdwn(finalText.trim()),
|
||||
text: normalizeSlackOutboundText(finalText.trim()),
|
||||
});
|
||||
return;
|
||||
} catch (err) {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
import type { WebClient } from "@slack/web-api";
|
||||
import type { ChatStreamer } from "@slack/web-api/dist/chat-stream.js";
|
||||
import { logVerbose } from "../globals.js";
|
||||
import { markdownToSlackMrkdwn } from "./format.js";
|
||||
import { normalizeSlackOutboundText } from "./format.js";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Types
|
||||
@@ -100,7 +100,7 @@ export async function startSlackStream(
|
||||
// If initial text is provided, send it as the first append which will
|
||||
// trigger the ChatStreamer to call chat.startStream under the hood.
|
||||
if (text) {
|
||||
await streamer.append({ markdown_text: markdownToSlackMrkdwn(text) });
|
||||
await streamer.append({ markdown_text: normalizeSlackOutboundText(text) });
|
||||
logVerbose(`slack-stream: appended initial text (${text.length} chars)`);
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ export async function appendSlackStream(params: AppendSlackStreamParams): Promis
|
||||
return;
|
||||
}
|
||||
|
||||
await session.streamer.append({ markdown_text: markdownToSlackMrkdwn(text) });
|
||||
await session.streamer.append({ markdown_text: normalizeSlackOutboundText(text) });
|
||||
logVerbose(`slack-stream: appended ${text.length} chars`);
|
||||
}
|
||||
|
||||
@@ -148,7 +148,9 @@ export async function stopSlackStream(params: StopSlackStreamParams): Promise<vo
|
||||
}`,
|
||||
);
|
||||
|
||||
await session.streamer.stop(text ? { markdown_text: markdownToSlackMrkdwn(text) } : undefined);
|
||||
await session.streamer.stop(
|
||||
text ? { markdown_text: normalizeSlackOutboundText(text) } : undefined,
|
||||
);
|
||||
|
||||
logVerbose("slack-stream: stream stopped");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user