import type { ChannelOutboundAdapter } from "openclaw/plugin-sdk"; import { getPopoRuntime } from "./runtime.js"; import { sendMessagePopo } from "./send.js"; import { sendMediaPopo } from "./media.js"; export const popoOutbound: ChannelOutboundAdapter = { deliveryMode: "direct", chunker: (text, limit) => getPopoRuntime().channel.text.chunkMarkdownText(text, limit), chunkerMode: "markdown", textChunkLimit: 4000, sendText: async ({ cfg, to, text }) => { const result = await sendMessagePopo({ cfg, to, text }); return { channel: "popo", ...result }; }, sendMedia: async ({ cfg, to, text, mediaUrl }) => { // Send text first if provided if (text?.trim()) { await sendMessagePopo({ cfg, to, text }); } // Upload and send media if URL provided if (mediaUrl) { try { const result = await sendMediaPopo({ cfg, to, mediaUrl }); return { channel: "popo", ...result }; } catch (err) { // Log the error for debugging console.error(`[popo] sendMediaPopo failed:`, err); // Fallback to URL link if upload fails const fallbackText = `📎 ${mediaUrl}`; const result = await sendMessagePopo({ cfg, to, text: fallbackText }); return { channel: "popo", ...result }; } } // No media URL, just return text result const result = await sendMessagePopo({ cfg, to, text: text ?? "" }); return { channel: "popo", ...result }; }, };