22 * Outbound ClickClack delivery helpers for channel messages, thread replies,
33 * and direct messages.
44 */
5+ import { sanitizeAssistantVisibleText } from "openclaw/plugin-sdk/text-chunking" ;
56import { resolveClickClackAccount } from "./accounts.js" ;
67import { createClickClackClient } from "./http-client.js" ;
78import { resolveChannelId , resolveWorkspaceId } from "./resolve.js" ;
89import { parseClickClackTarget } from "./target.js" ;
910import type { ClickClackMessageProvenance , CoreConfig } from "./types.js" ;
1011
1112/**
12- * Sends text to a normalized ClickClack target and returns the created message
13- * id for receipt/session tracking .
13+ * Sends visible text to a normalized ClickClack target and returns the created
14+ * message id, or undefined when sanitization removes all content .
1415 */
1516export async function sendClickClackText ( params : {
1617 cfg : CoreConfig ;
@@ -23,7 +24,13 @@ export async function sendClickClackText(params: {
2324 correlationId ?: string ;
2425 /** Optional model/thinking attribution stamped onto the created message. */
2526 provenance ?: ClickClackMessageProvenance ;
26- } ) {
27+ } ) : Promise < string | undefined > {
28+ // Custom inbound replies bypass shared outbound normalization, so this private
29+ // sender owns ClickClack assistant-text sanitization for every delivery path.
30+ const text = sanitizeAssistantVisibleText ( params . text ) ;
31+ if ( ! text ) {
32+ return undefined ;
33+ }
2734 const account = resolveClickClackAccount ( { cfg : params . cfg , accountId : params . accountId } ) ;
2835 const client = createClickClackClient ( {
2936 baseUrl : account . baseUrl ,
@@ -41,25 +48,25 @@ export async function sendClickClackText(params: {
4148 // below — otherwise every channel reply spawns its own thread and the main
4249 // timeline goes silent.
4350 const rootId = explicitThreadId || parsed . id ;
44- const message = await client . createThreadReply ( rootId , params . text , {
51+ const message = await client . createThreadReply ( rootId , text , {
4552 provenance : params . provenance ,
4653 } ) ;
47- return { to : params . to , messageId : message . id } ;
54+ return message . id ;
4855 }
4956 if ( parsed . kind === "dm" ) {
5057 const dm = await client . createDirectConversation ( workspaceId , [ parsed . id ] ) ;
51- const message = await client . createDirectMessage ( dm . id , params . text , {
58+ const message = await client . createDirectMessage ( dm . id , text , {
5259 quotedMessageId : replyToId || undefined ,
5360 } ) ;
54- return { to : params . to , messageId : message . id } ;
61+ return message . id ;
5562 }
5663 const channelId = await resolveChannelId ( client , workspaceId , parsed . id ) ;
5764 // A reply to a top-level channel message is delivered to the main channel as a
5865 // quote-reply (quoted_message_id), matching the reply-to affordance of the
5966 // Discord/Slack/Telegram channels, instead of opening a per-reply thread.
60- const message = await client . createChannelMessage ( channelId , params . text , {
67+ const message = await client . createChannelMessage ( channelId , text , {
6168 provenance : params . provenance ,
6269 quotedMessageId : replyToId || undefined ,
6370 } ) ;
64- return { to : params . to , messageId : message . id } ;
71+ return message . id ;
6572}
0 commit comments