@yaoyuanchao/dingtalk 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/channel.ts +4 -3
- package/src/monitor.ts +22 -3
package/package.json
CHANGED
package/src/channel.ts
CHANGED
|
@@ -206,10 +206,11 @@ export const dingtalkPlugin = {
|
|
|
206
206
|
const account = resolveDingTalkAccount({ cfg, accountId });
|
|
207
207
|
const [type, id] = to.split(':');
|
|
208
208
|
|
|
209
|
-
// Build text message with image URL
|
|
209
|
+
// Build text message with image URL as markdown image
|
|
210
|
+
const imageMarkdown = ``;
|
|
210
211
|
const textMessage = text
|
|
211
|
-
? `${text}\n\n
|
|
212
|
-
:
|
|
212
|
+
? `${text}\n\n${imageMarkdown}`
|
|
213
|
+
: imageMarkdown;
|
|
213
214
|
|
|
214
215
|
if (type === 'dm') {
|
|
215
216
|
await sendDingTalkRestMessage({
|
package/src/monitor.ts
CHANGED
|
@@ -577,8 +577,9 @@ async function processInboundMessage(
|
|
|
577
577
|
cfg: actualCfg,
|
|
578
578
|
dispatcherOptions: {
|
|
579
579
|
deliver: async (payload: any) => {
|
|
580
|
-
|
|
581
|
-
|
|
580
|
+
const textToSend = resolveDeliverText(payload, log);
|
|
581
|
+
if (textToSend) {
|
|
582
|
+
await deliverReply(replyTarget, textToSend, log);
|
|
582
583
|
setStatus?.({ lastOutboundAt: Date.now() });
|
|
583
584
|
}
|
|
584
585
|
},
|
|
@@ -679,7 +680,7 @@ async function dispatchWithFullPipeline(params: {
|
|
|
679
680
|
responsePrefix: '',
|
|
680
681
|
deliver: async (payload: any) => {
|
|
681
682
|
try {
|
|
682
|
-
const textToSend = payload
|
|
683
|
+
const textToSend = resolveDeliverText(payload, log);
|
|
683
684
|
if (!textToSend) return { ok: true };
|
|
684
685
|
await deliverReply(replyTarget, textToSend, log);
|
|
685
686
|
setStatus?.({ lastOutboundAt: Date.now() });
|
|
@@ -702,6 +703,24 @@ async function dispatchWithFullPipeline(params: {
|
|
|
702
703
|
rt.channel?.activity?.record?.('dingtalk', account.accountId, 'message');
|
|
703
704
|
}
|
|
704
705
|
|
|
706
|
+
/**
|
|
707
|
+
* Extract text + media URL from a deliver payload.
|
|
708
|
+
* The Clawdbot platform may send media URLs in separate fields (e.g. from the `message` tool).
|
|
709
|
+
* We merge them into the text as markdown image syntax so DingTalk can render them.
|
|
710
|
+
*/
|
|
711
|
+
function resolveDeliverText(payload: any, log?: any): string | undefined {
|
|
712
|
+
let text = payload.markdown || payload.text;
|
|
713
|
+
const mediaUrl = payload.mediaUrl || payload.media || payload.imageUrl || payload.image;
|
|
714
|
+
|
|
715
|
+
if (mediaUrl && typeof mediaUrl === 'string' && mediaUrl.startsWith('http')) {
|
|
716
|
+
log?.info?.("[dingtalk] Deliver payload includes media URL: " + mediaUrl);
|
|
717
|
+
const imageMarkdown = ``;
|
|
718
|
+
text = text ? `${text}\n\n${imageMarkdown}` : imageMarkdown;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
return text || undefined;
|
|
722
|
+
}
|
|
723
|
+
|
|
705
724
|
async function deliverReply(target: any, text: string, log?: any): Promise<void> {
|
|
706
725
|
const now = Date.now();
|
|
707
726
|
const chunkLimit = 2000;
|