mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +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:
@@ -1,8 +1,19 @@
|
||||
import type { INodeType, INodeTypeDescription } from 'n8n-workflow';
|
||||
import { NodeConnectionType } from 'n8n-workflow';
|
||||
import type { IExecuteFunctions, INodeType, INodeTypeDescription } from 'n8n-workflow';
|
||||
import { NodeConnectionType, NodeOperationError, SEND_AND_WAIT_OPERATION } from 'n8n-workflow';
|
||||
|
||||
import { createMessage, WHATSAPP_BASE_URL } from './GenericFunctions';
|
||||
import { mediaFields, mediaTypeFields } from './MediaDescription';
|
||||
import { sanitizePhoneNumber } from './MessageFunctions';
|
||||
import { messageFields, messageTypeFields } from './MessagesDescription';
|
||||
import { configureWaitTillDate } from '../../utils/sendAndWait/configureWaitTillDate.util';
|
||||
import { sendAndWaitWebhooksDescription } from '../../utils/sendAndWait/descriptions';
|
||||
import {
|
||||
getSendAndWaitConfig,
|
||||
getSendAndWaitProperties,
|
||||
sendAndWaitWebhook,
|
||||
} from '../../utils/sendAndWait/utils';
|
||||
|
||||
const WHATSAPP_CREDENTIALS_TYPE = 'whatsAppApi';
|
||||
|
||||
export class WhatsApp implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -19,14 +30,15 @@ export class WhatsApp implements INodeType {
|
||||
usableAsTool: true,
|
||||
inputs: [NodeConnectionType.Main],
|
||||
outputs: [NodeConnectionType.Main],
|
||||
webhooks: sendAndWaitWebhooksDescription,
|
||||
credentials: [
|
||||
{
|
||||
name: 'whatsAppApi',
|
||||
name: WHATSAPP_CREDENTIALS_TYPE,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
requestDefaults: {
|
||||
baseURL: 'https://graph.facebook.com/v13.0/',
|
||||
baseURL: WHATSAPP_BASE_URL,
|
||||
},
|
||||
properties: [
|
||||
{
|
||||
@@ -50,6 +62,42 @@ export class WhatsApp implements INodeType {
|
||||
...mediaFields,
|
||||
...messageTypeFields,
|
||||
...mediaTypeFields,
|
||||
...getSendAndWaitProperties([], 'message', undefined, {
|
||||
noButtonStyle: true,
|
||||
defaultApproveLabel: '✓ Approve',
|
||||
defaultDisapproveLabel: '✗ Decline',
|
||||
}).filter((p) => p.name !== 'subject'),
|
||||
],
|
||||
};
|
||||
|
||||
webhook = sendAndWaitWebhook;
|
||||
|
||||
customOperations = {
|
||||
message: {
|
||||
async [SEND_AND_WAIT_OPERATION](this: IExecuteFunctions) {
|
||||
try {
|
||||
const phoneNumberId = this.getNodeParameter('phoneNumberId', 0) as string;
|
||||
|
||||
const recipientPhoneNumber = sanitizePhoneNumber(
|
||||
this.getNodeParameter('recipientPhoneNumber', 0) as string,
|
||||
);
|
||||
|
||||
const config = getSendAndWaitConfig(this);
|
||||
|
||||
await this.helpers.httpRequestWithAuthentication.call(
|
||||
this,
|
||||
WHATSAPP_CREDENTIALS_TYPE,
|
||||
createMessage(config, phoneNumberId, recipientPhoneNumber),
|
||||
);
|
||||
|
||||
const waitTill = configureWaitTillDate(this);
|
||||
|
||||
await this.putExecutionToWait(waitTill);
|
||||
return [this.getInputData()];
|
||||
} catch (error) {
|
||||
throw new NodeOperationError(this.getNode(), error);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user