feat(adapters): add sendPayload to batch-d adapters

This commit is contained in:
David Friedland
2026-02-28 15:36:08 -08:00
committed by Peter Steinberger
parent f1cab9c5e5
commit d06ee86292
6 changed files with 116 additions and 1 deletions

View File

@@ -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,

View File

@@ -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 });

View File

@@ -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;
}

View File

@@ -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({

View File

@@ -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,

View File

@@ -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;