refactor: share whatsapp outbound adapter base

This commit is contained in:
Peter Steinberger
2026-03-14 01:11:11 +00:00
parent d4b193b581
commit 7285e04ead
4 changed files with 108 additions and 86 deletions

View File

@@ -8,6 +8,7 @@ import {
buildChannelConfigSchema,
collectWhatsAppStatusIssues,
createActionGate,
createWhatsAppOutboundBase,
DEFAULT_ACCOUNT_ID,
getChatChannelMeta,
listWhatsAppAccountIds,
@@ -283,52 +284,16 @@ export const whatsappPlugin: ChannelPlugin<ResolvedWhatsAppAccount> = {
);
},
},
outbound: {
deliveryMode: "gateway",
outbound: createWhatsAppOutboundBase({
chunker: (text, limit) => getWhatsAppRuntime().channel.text.chunkText(text, limit),
chunkerMode: "text",
textChunkLimit: 4000,
pollMaxOptions: 12,
sendMessageWhatsApp: async (...args) =>
await getWhatsAppRuntime().channel.whatsapp.sendMessageWhatsApp(...args),
sendPollWhatsApp: async (...args) =>
await getWhatsAppRuntime().channel.whatsapp.sendPollWhatsApp(...args),
shouldLogVerbose: () => getWhatsAppRuntime().logging.shouldLogVerbose(),
resolveTarget: ({ to, allowFrom, mode }) =>
resolveWhatsAppOutboundTarget({ to, allowFrom, mode }),
sendText: async ({ cfg, to, text, accountId, deps, gifPlayback }) => {
const send = deps?.sendWhatsApp ?? getWhatsAppRuntime().channel.whatsapp.sendMessageWhatsApp;
const result = await send(to, text, {
verbose: false,
cfg,
accountId: accountId ?? undefined,
gifPlayback,
});
return { channel: "whatsapp", ...result };
},
sendMedia: async ({
cfg,
to,
text,
mediaUrl,
mediaLocalRoots,
accountId,
deps,
gifPlayback,
}) => {
const send = deps?.sendWhatsApp ?? getWhatsAppRuntime().channel.whatsapp.sendMessageWhatsApp;
const result = await send(to, text, {
verbose: false,
cfg,
mediaUrl,
mediaLocalRoots,
accountId: accountId ?? undefined,
gifPlayback,
});
return { channel: "whatsapp", ...result };
},
sendPoll: async ({ cfg, to, poll, accountId }) =>
await getWhatsAppRuntime().channel.whatsapp.sendPollWhatsApp(to, poll, {
verbose: getWhatsAppRuntime().logging.shouldLogVerbose(),
accountId: accountId ?? undefined,
cfg,
}),
},
}),
auth: {
login: async ({ cfg, accountId, runtime, verbose }) => {
const resolvedAccountId = accountId?.trim() || resolveDefaultWhatsAppAccountId(cfg);