mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
feat(adapters): add sendPayload to batch-d adapters
This commit is contained in:
committed by
Peter Steinberger
parent
f1cab9c5e5
commit
d06ee86292
@@ -302,6 +302,25 @@ export const zaloPlugin: ChannelPlugin<ResolvedZaloAccount> = {
|
||||
chunker: chunkTextForOutbound,
|
||||
chunkerMode: "text",
|
||||
textChunkLimit: 2000,
|
||||
sendPayload: async (ctx) => {
|
||||
const urls = ctx.payload.mediaUrls?.length
|
||||
? ctx.payload.mediaUrls
|
||||
: ctx.payload.mediaUrl
|
||||
? [ctx.payload.mediaUrl]
|
||||
: [];
|
||||
if (urls.length > 0) {
|
||||
let lastResult;
|
||||
for (let i = 0; i < urls.length; i++) {
|
||||
lastResult = await zaloPlugin.outbound!.sendMedia!({
|
||||
...ctx,
|
||||
text: i === 0 ? (ctx.payload.text ?? "") : "",
|
||||
mediaUrl: urls[i],
|
||||
});
|
||||
}
|
||||
return lastResult!;
|
||||
}
|
||||
return zaloPlugin.outbound!.sendText!({ ...ctx });
|
||||
},
|
||||
sendText: async ({ to, text, accountId, cfg }) => {
|
||||
const result = await sendMessageZalo(to, text, {
|
||||
accountId: accountId ?? undefined,
|
||||
|
||||
@@ -518,6 +518,25 @@ export const zalouserPlugin: ChannelPlugin<ResolvedZalouserAccount> = {
|
||||
chunker: chunkTextForOutbound,
|
||||
chunkerMode: "text",
|
||||
textChunkLimit: 2000,
|
||||
sendPayload: async (ctx) => {
|
||||
const urls = ctx.payload.mediaUrls?.length
|
||||
? ctx.payload.mediaUrls
|
||||
: ctx.payload.mediaUrl
|
||||
? [ctx.payload.mediaUrl]
|
||||
: [];
|
||||
if (urls.length > 0) {
|
||||
let lastResult;
|
||||
for (let i = 0; i < urls.length; i++) {
|
||||
lastResult = await zalouserPlugin.outbound!.sendMedia!({
|
||||
...ctx,
|
||||
text: i === 0 ? (ctx.payload.text ?? "") : "",
|
||||
mediaUrl: urls[i],
|
||||
});
|
||||
}
|
||||
return lastResult!;
|
||||
}
|
||||
return zalouserPlugin.outbound!.sendText!({ ...ctx });
|
||||
},
|
||||
sendText: async ({ to, text, accountId, cfg }) => {
|
||||
const account = resolveZalouserAccountSync({ cfg: cfg, accountId });
|
||||
const result = await sendMessageZalouser(to, text, { profile: account.profile });
|
||||
|
||||
@@ -86,11 +86,30 @@ export function createDirectTextMediaOutbound<
|
||||
return { channel: params.channel, ...result };
|
||||
};
|
||||
|
||||
return {
|
||||
const outbound: ChannelOutboundAdapter = {
|
||||
deliveryMode: "direct",
|
||||
chunker: chunkText,
|
||||
chunkerMode: "text",
|
||||
textChunkLimit: 4000,
|
||||
sendPayload: async (ctx) => {
|
||||
const urls = ctx.payload.mediaUrls?.length
|
||||
? ctx.payload.mediaUrls
|
||||
: ctx.payload.mediaUrl
|
||||
? [ctx.payload.mediaUrl]
|
||||
: [];
|
||||
if (urls.length > 0) {
|
||||
let lastResult;
|
||||
for (let i = 0; i < urls.length; i++) {
|
||||
lastResult = await outbound.sendMedia!({
|
||||
...ctx,
|
||||
text: i === 0 ? (ctx.payload.text ?? "") : "",
|
||||
mediaUrl: urls[i],
|
||||
});
|
||||
}
|
||||
return lastResult;
|
||||
}
|
||||
return outbound.sendText!({ ...ctx });
|
||||
},
|
||||
sendText: async ({ cfg, to, text, accountId, deps, replyToId }) => {
|
||||
return await sendDirect({
|
||||
cfg,
|
||||
@@ -116,4 +135,5 @@ export function createDirectTextMediaOutbound<
|
||||
});
|
||||
},
|
||||
};
|
||||
return outbound;
|
||||
}
|
||||
|
||||
@@ -80,6 +80,25 @@ export const discordOutbound: ChannelOutboundAdapter = {
|
||||
textChunkLimit: 2000,
|
||||
pollMaxOptions: 10,
|
||||
resolveTarget: ({ to }) => normalizeDiscordOutboundTarget(to),
|
||||
sendPayload: async (ctx) => {
|
||||
const urls = ctx.payload.mediaUrls?.length
|
||||
? ctx.payload.mediaUrls
|
||||
: ctx.payload.mediaUrl
|
||||
? [ctx.payload.mediaUrl]
|
||||
: [];
|
||||
if (urls.length > 0) {
|
||||
let lastResult;
|
||||
for (let i = 0; i < urls.length; i++) {
|
||||
lastResult = await discordOutbound.sendMedia!({
|
||||
...ctx,
|
||||
text: i === 0 ? (ctx.payload.text ?? "") : "",
|
||||
mediaUrl: urls[i],
|
||||
});
|
||||
}
|
||||
return lastResult;
|
||||
}
|
||||
return discordOutbound.sendText!({ ...ctx });
|
||||
},
|
||||
sendText: async ({ to, text, accountId, deps, replyToId, threadId, identity, silent }) => {
|
||||
if (!silent) {
|
||||
const webhookResult = await maybeSendDiscordWebhookText({
|
||||
|
||||
@@ -93,6 +93,25 @@ export const slackOutbound: ChannelOutboundAdapter = {
|
||||
deliveryMode: "direct",
|
||||
chunker: null,
|
||||
textChunkLimit: 4000,
|
||||
sendPayload: async (ctx) => {
|
||||
const urls = ctx.payload.mediaUrls?.length
|
||||
? ctx.payload.mediaUrls
|
||||
: ctx.payload.mediaUrl
|
||||
? [ctx.payload.mediaUrl]
|
||||
: [];
|
||||
if (urls.length > 0) {
|
||||
let lastResult;
|
||||
for (let i = 0; i < urls.length; i++) {
|
||||
lastResult = await slackOutbound.sendMedia!({
|
||||
...ctx,
|
||||
text: i === 0 ? (ctx.payload.text ?? "") : "",
|
||||
mediaUrl: urls[i],
|
||||
});
|
||||
}
|
||||
return lastResult;
|
||||
}
|
||||
return slackOutbound.sendText!({ ...ctx });
|
||||
},
|
||||
sendText: async ({ to, text, accountId, deps, replyToId, threadId, identity }) => {
|
||||
return await sendSlackOutboundMessage({
|
||||
to,
|
||||
|
||||
@@ -12,6 +12,25 @@ export const whatsappOutbound: ChannelOutboundAdapter = {
|
||||
pollMaxOptions: 12,
|
||||
resolveTarget: ({ to, allowFrom, mode }) =>
|
||||
resolveWhatsAppOutboundTarget({ to, allowFrom, mode }),
|
||||
sendPayload: async (ctx) => {
|
||||
const urls = ctx.payload.mediaUrls?.length
|
||||
? ctx.payload.mediaUrls
|
||||
: ctx.payload.mediaUrl
|
||||
? [ctx.payload.mediaUrl]
|
||||
: [];
|
||||
if (urls.length > 0) {
|
||||
let lastResult;
|
||||
for (let i = 0; i < urls.length; i++) {
|
||||
lastResult = await whatsappOutbound.sendMedia!({
|
||||
...ctx,
|
||||
text: i === 0 ? (ctx.payload.text ?? "") : "",
|
||||
mediaUrl: urls[i],
|
||||
});
|
||||
}
|
||||
return lastResult;
|
||||
}
|
||||
return whatsappOutbound.sendText!({ ...ctx });
|
||||
},
|
||||
sendText: async ({ to, text, accountId, deps, gifPlayback }) => {
|
||||
const send =
|
||||
deps?.sendWhatsApp ?? (await import("../../../web/outbound.js")).sendMessageWhatsApp;
|
||||
|
||||
Reference in New Issue
Block a user