diff --git a/extensions/zalo/src/channel.ts b/extensions/zalo/src/channel.ts index 1b2e013a167..024fb38aea2 100644 --- a/extensions/zalo/src/channel.ts +++ b/extensions/zalo/src/channel.ts @@ -309,15 +309,19 @@ export const zaloPlugin: ChannelPlugin = { ? [ctx.payload.mediaUrl] : []; if (urls.length > 0) { - let lastResult; - for (let i = 0; i < urls.length; i++) { + let lastResult = await zaloPlugin.outbound!.sendMedia!({ + ...ctx, + text: ctx.payload.text ?? "", + mediaUrl: urls[0], + }); + for (let i = 1; i < urls.length; i++) { lastResult = await zaloPlugin.outbound!.sendMedia!({ ...ctx, - text: i === 0 ? (ctx.payload.text ?? "") : "", + text: "", mediaUrl: urls[i], }); } - return lastResult!; + return lastResult; } return zaloPlugin.outbound!.sendText!({ ...ctx }); }, diff --git a/extensions/zalouser/src/channel.ts b/extensions/zalouser/src/channel.ts index 4d8931f60a3..20671276d42 100644 --- a/extensions/zalouser/src/channel.ts +++ b/extensions/zalouser/src/channel.ts @@ -525,15 +525,19 @@ export const zalouserPlugin: ChannelPlugin = { ? [ctx.payload.mediaUrl] : []; if (urls.length > 0) { - let lastResult; - for (let i = 0; i < urls.length; i++) { + let lastResult = await zalouserPlugin.outbound!.sendMedia!({ + ...ctx, + text: ctx.payload.text ?? "", + mediaUrl: urls[0], + }); + for (let i = 1; i < urls.length; i++) { lastResult = await zalouserPlugin.outbound!.sendMedia!({ ...ctx, - text: i === 0 ? (ctx.payload.text ?? "") : "", + text: "", mediaUrl: urls[i], }); } - return lastResult!; + return lastResult; } return zalouserPlugin.outbound!.sendText!({ ...ctx }); }, diff --git a/src/channels/plugins/outbound/direct-text-media.ts b/src/channels/plugins/outbound/direct-text-media.ts index 098e861880f..47453f6d1db 100644 --- a/src/channels/plugins/outbound/direct-text-media.ts +++ b/src/channels/plugins/outbound/direct-text-media.ts @@ -98,11 +98,15 @@ export function createDirectTextMediaOutbound< ? [ctx.payload.mediaUrl] : []; if (urls.length > 0) { - let lastResult; - for (let i = 0; i < urls.length; i++) { + let lastResult = await outbound.sendMedia!({ + ...ctx, + text: ctx.payload.text ?? "", + mediaUrl: urls[0], + }); + for (let i = 1; i < urls.length; i++) { lastResult = await outbound.sendMedia!({ ...ctx, - text: i === 0 ? (ctx.payload.text ?? "") : "", + text: "", mediaUrl: urls[i], }); } diff --git a/src/channels/plugins/outbound/discord.ts b/src/channels/plugins/outbound/discord.ts index 76dd0165bea..81992fc82af 100644 --- a/src/channels/plugins/outbound/discord.ts +++ b/src/channels/plugins/outbound/discord.ts @@ -87,11 +87,15 @@ export const discordOutbound: ChannelOutboundAdapter = { ? [ctx.payload.mediaUrl] : []; if (urls.length > 0) { - let lastResult; - for (let i = 0; i < urls.length; i++) { + let lastResult = await discordOutbound.sendMedia!({ + ...ctx, + text: ctx.payload.text ?? "", + mediaUrl: urls[0], + }); + for (let i = 1; i < urls.length; i++) { lastResult = await discordOutbound.sendMedia!({ ...ctx, - text: i === 0 ? (ctx.payload.text ?? "") : "", + text: "", mediaUrl: urls[i], }); } diff --git a/src/channels/plugins/outbound/slack.ts b/src/channels/plugins/outbound/slack.ts index b18da300e5e..ecbf010dae9 100644 --- a/src/channels/plugins/outbound/slack.ts +++ b/src/channels/plugins/outbound/slack.ts @@ -100,11 +100,15 @@ export const slackOutbound: ChannelOutboundAdapter = { ? [ctx.payload.mediaUrl] : []; if (urls.length > 0) { - let lastResult; - for (let i = 0; i < urls.length; i++) { + let lastResult = await slackOutbound.sendMedia!({ + ...ctx, + text: ctx.payload.text ?? "", + mediaUrl: urls[0], + }); + for (let i = 1; i < urls.length; i++) { lastResult = await slackOutbound.sendMedia!({ ...ctx, - text: i === 0 ? (ctx.payload.text ?? "") : "", + text: "", mediaUrl: urls[i], }); } diff --git a/src/channels/plugins/outbound/whatsapp.ts b/src/channels/plugins/outbound/whatsapp.ts index d8a17842b41..fc5dbcac81c 100644 --- a/src/channels/plugins/outbound/whatsapp.ts +++ b/src/channels/plugins/outbound/whatsapp.ts @@ -19,11 +19,15 @@ export const whatsappOutbound: ChannelOutboundAdapter = { ? [ctx.payload.mediaUrl] : []; if (urls.length > 0) { - let lastResult; - for (let i = 0; i < urls.length; i++) { + let lastResult = await whatsappOutbound.sendMedia!({ + ...ctx, + text: ctx.payload.text ?? "", + mediaUrl: urls[0], + }); + for (let i = 1; i < urls.length; i++) { lastResult = await whatsappOutbound.sendMedia!({ ...ctx, - text: i === 0 ? (ctx.payload.text ?? "") : "", + text: "", mediaUrl: urls[i], }); }