mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 12:00:22 +00:00
refactor: deduplicate reply payload helpers
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
type MarkdownTableMode,
|
||||
type MSTeamsReplyStyle,
|
||||
type ReplyPayload,
|
||||
resolveOutboundMediaUrls,
|
||||
SILENT_REPLY_TOKEN,
|
||||
sleep,
|
||||
} from "../runtime-api.js";
|
||||
@@ -216,7 +217,7 @@ export function renderReplyPayloadsToMessages(
|
||||
});
|
||||
|
||||
for (const payload of replies) {
|
||||
const mediaList = payload.mediaUrls ?? (payload.mediaUrl ? [payload.mediaUrl] : []);
|
||||
const mediaList = resolveOutboundMediaUrls(payload);
|
||||
const text = getMSTeamsRuntime().channel.text.convertMarkdownTables(
|
||||
payload.text ?? "",
|
||||
tableMode,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { resolveOutboundSendDep } from "openclaw/plugin-sdk/channel-runtime";
|
||||
import { createAttachedChannelResultAdapter } from "openclaw/plugin-sdk/channel-send-result";
|
||||
import type { ChannelOutboundAdapter } from "../runtime-api.js";
|
||||
import { createMSTeamsPollStoreFs } from "./polls.js";
|
||||
import { getMSTeamsRuntime } from "./runtime.js";
|
||||
@@ -10,56 +11,57 @@ export const msteamsOutbound: ChannelOutboundAdapter = {
|
||||
chunkerMode: "markdown",
|
||||
textChunkLimit: 4000,
|
||||
pollMaxOptions: 12,
|
||||
sendText: async ({ cfg, to, text, deps }) => {
|
||||
type SendFn = (
|
||||
to: string,
|
||||
text: string,
|
||||
) => Promise<{ messageId: string; conversationId: string }>;
|
||||
const send =
|
||||
resolveOutboundSendDep<SendFn>(deps, "msteams") ??
|
||||
((to, text) => sendMessageMSTeams({ cfg, to, text }));
|
||||
const result = await send(to, text);
|
||||
return { channel: "msteams", ...result };
|
||||
},
|
||||
sendMedia: async ({ cfg, to, text, mediaUrl, mediaLocalRoots, deps }) => {
|
||||
type SendFn = (
|
||||
to: string,
|
||||
text: string,
|
||||
opts?: { mediaUrl?: string; mediaLocalRoots?: readonly string[] },
|
||||
) => Promise<{ messageId: string; conversationId: string }>;
|
||||
const send =
|
||||
resolveOutboundSendDep<SendFn>(deps, "msteams") ??
|
||||
((to, text, opts) =>
|
||||
sendMessageMSTeams({
|
||||
cfg,
|
||||
to,
|
||||
text,
|
||||
mediaUrl: opts?.mediaUrl,
|
||||
mediaLocalRoots: opts?.mediaLocalRoots,
|
||||
}));
|
||||
const result = await send(to, text, { mediaUrl, mediaLocalRoots });
|
||||
return { channel: "msteams", ...result };
|
||||
},
|
||||
sendPoll: async ({ cfg, to, poll }) => {
|
||||
const maxSelections = poll.maxSelections ?? 1;
|
||||
const result = await sendPollMSTeams({
|
||||
cfg,
|
||||
to,
|
||||
question: poll.question,
|
||||
options: poll.options,
|
||||
maxSelections,
|
||||
});
|
||||
const pollStore = createMSTeamsPollStoreFs();
|
||||
await pollStore.createPoll({
|
||||
id: result.pollId,
|
||||
question: poll.question,
|
||||
options: poll.options,
|
||||
maxSelections,
|
||||
createdAt: new Date().toISOString(),
|
||||
conversationId: result.conversationId,
|
||||
messageId: result.messageId,
|
||||
votes: {},
|
||||
});
|
||||
return result;
|
||||
},
|
||||
...createAttachedChannelResultAdapter({
|
||||
channel: "msteams",
|
||||
sendText: async ({ cfg, to, text, deps }) => {
|
||||
type SendFn = (
|
||||
to: string,
|
||||
text: string,
|
||||
) => Promise<{ messageId: string; conversationId: string }>;
|
||||
const send =
|
||||
resolveOutboundSendDep<SendFn>(deps, "msteams") ??
|
||||
((to, text) => sendMessageMSTeams({ cfg, to, text }));
|
||||
return await send(to, text);
|
||||
},
|
||||
sendMedia: async ({ cfg, to, text, mediaUrl, mediaLocalRoots, deps }) => {
|
||||
type SendFn = (
|
||||
to: string,
|
||||
text: string,
|
||||
opts?: { mediaUrl?: string; mediaLocalRoots?: readonly string[] },
|
||||
) => Promise<{ messageId: string; conversationId: string }>;
|
||||
const send =
|
||||
resolveOutboundSendDep<SendFn>(deps, "msteams") ??
|
||||
((to, text, opts) =>
|
||||
sendMessageMSTeams({
|
||||
cfg,
|
||||
to,
|
||||
text,
|
||||
mediaUrl: opts?.mediaUrl,
|
||||
mediaLocalRoots: opts?.mediaLocalRoots,
|
||||
}));
|
||||
return await send(to, text, { mediaUrl, mediaLocalRoots });
|
||||
},
|
||||
sendPoll: async ({ cfg, to, poll }) => {
|
||||
const maxSelections = poll.maxSelections ?? 1;
|
||||
const result = await sendPollMSTeams({
|
||||
cfg,
|
||||
to,
|
||||
question: poll.question,
|
||||
options: poll.options,
|
||||
maxSelections,
|
||||
});
|
||||
const pollStore = createMSTeamsPollStoreFs();
|
||||
await pollStore.createPoll({
|
||||
id: result.pollId,
|
||||
question: poll.question,
|
||||
options: poll.options,
|
||||
maxSelections,
|
||||
createdAt: new Date().toISOString(),
|
||||
conversationId: result.conversationId,
|
||||
messageId: result.messageId,
|
||||
votes: {},
|
||||
});
|
||||
return result;
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user