feat: WhatsApp Business Cloud Node - new operation sendAndWait (#12941)

Co-authored-by: Tomi Turtiainen <10324676+tomi@users.noreply.github.com>
This commit is contained in:
Michael Kret
2025-02-27 07:20:37 +02:00
committed by GitHub
parent 83d03d53eb
commit 97defb3a83
13 changed files with 457 additions and 74 deletions

View File

@@ -14,6 +14,8 @@ import type {
WhatsAppAppWebhookSubscriptionsResponse,
WhatsAppAppWebhookSubscription,
} from './types';
import type { SendAndWaitConfig } from '../../utils/sendAndWait/utils';
export const WHATSAPP_BASE_URL = 'https://graph.facebook.com/v13.0/';
async function appAccessTokenRead(
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions,
@@ -102,3 +104,27 @@ export async function appWebhookSubscriptionDelete(
payload: { object },
});
}
export const createMessage = (
sendAndWaitConfig: SendAndWaitConfig,
phoneNumberId: string,
recipientPhoneNumber: string,
): IHttpRequestOptions => {
const buttons = sendAndWaitConfig.options.map((option) => {
return `*${option.label}:*\n_${sendAndWaitConfig.url}?approved=${option.value}_\n\n`;
});
return {
baseURL: WHATSAPP_BASE_URL,
method: 'POST',
url: `${phoneNumberId}/messages`,
body: {
messaging_product: 'whatsapp',
text: {
body: `${sendAndWaitConfig.message}\n\n${buttons.join('')}`,
},
type: 'text',
to: recipientPhoneNumber,
},
};
};