UNPKG

n8n-nodes-whatsapp

Version:

Nodes to trigger workflows from whatsapp events or send messages (using whatsapp web).

61 lines 2.71 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.WhatsApp = void 0; const debug = require('debug')('n8n-nodes-whatsapp'); const WhatsApp_node_description_1 = require("./WhatsApp.node.description"); const n8n_workflow_1 = require("n8n-workflow"); const whatsapp = __importStar(require("./client/client")); class WhatsApp { constructor() { this.description = WhatsApp_node_description_1.nodeDescription; } async execute() { const credential = (await this.getCredentials('whatsApp')); if (!credential) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), "credential is missing!"); } const items = this.getInputData(); const returnData = []; for (let i = 0; i < items.length; i++) { const operation = this.getNodeParameter('operation', i); switch (operation) { case 'sendMessage': const message = this.getNodeParameter('message', i); const recipientPhoneNumber = this.getNodeParameter('recipientPhoneNumber', i); debug('sendMessage', { recipientPhoneNumber, message }); const sentMessage = await whatsapp.sendMessageToPhoneNumber(credential, recipientPhoneNumber, message); debug('message sent', sentMessage); returnData.push({ json: { message: sentMessage } }); break; default: break; } } return [this.helpers.returnJsonArray(returnData)]; } } exports.WhatsApp = WhatsApp; //# sourceMappingURL=WhatsApp.node.js.map