mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 11:38:38 +00:00
Slack: forward reply blocks in DM delivery
This commit is contained in:
@@ -5,9 +5,22 @@ import { isSilentReplyText, SILENT_REPLY_TOKEN } from "../../auto-reply/tokens.j
|
|||||||
import type { ReplyPayload } from "../../auto-reply/types.js";
|
import type { ReplyPayload } from "../../auto-reply/types.js";
|
||||||
import type { MarkdownTableMode } from "../../config/types.base.js";
|
import type { MarkdownTableMode } from "../../config/types.base.js";
|
||||||
import type { RuntimeEnv } from "../../runtime.js";
|
import type { RuntimeEnv } from "../../runtime.js";
|
||||||
|
import { parseSlackBlocksInput } from "../blocks-input.js";
|
||||||
import { markdownToSlackMrkdwnChunks } from "../format.js";
|
import { markdownToSlackMrkdwnChunks } from "../format.js";
|
||||||
import { sendMessageSlack, type SlackSendIdentity } from "../send.js";
|
import { sendMessageSlack, type SlackSendIdentity } from "../send.js";
|
||||||
|
|
||||||
|
export function readSlackReplyBlocks(payload: ReplyPayload) {
|
||||||
|
const slackData = payload.channelData?.slack;
|
||||||
|
if (!slackData || typeof slackData !== "object" || Array.isArray(slackData)) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return parseSlackBlocksInput((slackData as { blocks?: unknown }).blocks);
|
||||||
|
} catch {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function deliverReplies(params: {
|
export async function deliverReplies(params: {
|
||||||
replies: ReplyPayload[];
|
replies: ReplyPayload[];
|
||||||
target: string;
|
target: string;
|
||||||
@@ -26,19 +39,24 @@ export async function deliverReplies(params: {
|
|||||||
const threadTs = inlineReplyToId ?? params.replyThreadTs;
|
const threadTs = inlineReplyToId ?? params.replyThreadTs;
|
||||||
const mediaList = payload.mediaUrls ?? (payload.mediaUrl ? [payload.mediaUrl] : []);
|
const mediaList = payload.mediaUrls ?? (payload.mediaUrl ? [payload.mediaUrl] : []);
|
||||||
const text = payload.text ?? "";
|
const text = payload.text ?? "";
|
||||||
if (!text && mediaList.length === 0) {
|
const slackBlocks = readSlackReplyBlocks(payload);
|
||||||
|
if (!text && mediaList.length === 0 && !slackBlocks?.length) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mediaList.length === 0) {
|
if (mediaList.length === 0) {
|
||||||
const trimmed = text.trim();
|
const trimmed = text.trim();
|
||||||
if (!trimmed || isSilentReplyText(trimmed, SILENT_REPLY_TOKEN)) {
|
if (!trimmed && !slackBlocks?.length) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (trimmed && isSilentReplyText(trimmed, SILENT_REPLY_TOKEN)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
await sendMessageSlack(params.target, trimmed, {
|
await sendMessageSlack(params.target, trimmed, {
|
||||||
token: params.token,
|
token: params.token,
|
||||||
threadTs,
|
threadTs,
|
||||||
accountId: params.accountId,
|
accountId: params.accountId,
|
||||||
|
...(slackBlocks?.length ? { blocks: slackBlocks } : {}),
|
||||||
...(params.identity ? { identity: params.identity } : {}),
|
...(params.identity ? { identity: params.identity } : {}),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user