mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
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:
@@ -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,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user