UNPKG

n8n-nodes-wuzapi

Version:

n8n community nodes for Wuzapi - WhatsApp Multi-Device REST API

208 lines 9.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WuzapiMention = void 0; const GenericFunctions_1 = require("../GenericFunctions"); class WuzapiMention { constructor() { this.description = { displayName: 'Wuzapi Mention', name: 'wuzapiMention', icon: 'file:wuzapi.svg', group: ['transform'], version: 1, subtitle: '={{$parameter["operation"]}}', description: 'Send WhatsApp messages with mentions using Wuzapi API', defaults: { name: 'Wuzapi Mention', }, inputs: ["main" /* NodeConnectionType.Main */], outputs: ["main" /* NodeConnectionType.Main */], credentials: [ { name: 'wuzapiApi', required: true, }, ], properties: [ { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, options: [ { name: 'Send Text with Mentions', value: 'sendTextWithMentions', description: 'Send text message mentioning specific users', action: 'Send text with mentions', }, { name: 'Send Text Mention All', value: 'sendTextMentionAll', description: 'Send text message mentioning all group members', action: 'Send text mention all', }, ], default: 'sendTextWithMentions', }, // Send Text with Mentions { displayName: 'Recipient', name: 'to', type: 'string', default: '', placeholder: 'e.g. 5491155553934@s.whatsapp.net or 120363312246943103@g.us', description: 'Phone number or Group JID to send message to', required: true, }, { displayName: 'Message Text', name: 'text', type: 'string', default: '', placeholder: 'Hello @user1, how are you?', description: 'Text message to send (use @username in text for mentions)', required: true, }, { displayName: 'User JIDs to Mention', name: 'mentions', type: 'string', default: '', placeholder: 'e.g. 5491155553934@s.whatsapp.net,5491155553935@s.whatsapp.net', description: 'Comma-separated list of user JIDs to mention', required: true, displayOptions: { show: { operation: ['sendTextWithMentions'], }, }, }, { displayName: 'Group ID', name: 'groupId', type: 'string', default: '', placeholder: 'e.g. 120363312246943103@g.us', description: 'Group JID to mention all members', required: true, displayOptions: { show: { operation: ['sendTextMentionAll'], }, }, }, // Additional Options { displayName: 'Additional Options', name: 'additionalOptions', type: 'collection', placeholder: 'Add Option', default: {}, options: [ { displayName: 'Message ID', name: 'id', type: 'string', default: '', description: 'Custom message ID (auto-generated if not provided)', }, { displayName: 'Reply To Message', name: 'contextInfo', type: 'fixedCollection', default: {}, description: 'Reply to a specific message', options: [ { name: 'context', displayName: 'Context', values: [ { displayName: 'Message ID', name: 'stanzaId', type: 'string', default: '', description: 'ID of the message to reply to', required: true, }, { displayName: 'Participant', name: 'participant', type: 'string', default: '', placeholder: 'e.g. 5491155553935@s.whatsapp.net', description: 'JID of the message sender', required: true, }, ], }, ], }, ], }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; for (let i = 0; i < items.length; i++) { try { const operation = this.getNodeParameter('operation', i); const to = this.getNodeParameter('to', i); const text = this.getNodeParameter('text', i); const additionalOptions = this.getNodeParameter('additionalOptions', i); let endpoint = ''; let body = {}; // Add common fields if (additionalOptions.id) { body.id = additionalOptions.id; } // Add context info if provided if (additionalOptions.contextInfo && additionalOptions.contextInfo.context) { const context = additionalOptions.contextInfo.context; if (context.stanzaId && context.participant) { body.ContextInfo = { StanzaId: context.stanzaId, Participant: context.participant, }; } } if (operation === 'sendTextWithMentions') { endpoint = '/chat/send/text/mention'; const mentions = this.getNodeParameter('mentions', i); body = { ...body, to: to, text: text, mentions: mentions.split(',').map(jid => jid.trim()), }; } else if (operation === 'sendTextMentionAll') { endpoint = '/chat/send/text/mention-all'; const groupId = this.getNodeParameter('groupId', i); body = { ...body, group_id: groupId, text: text, }; } const response = await GenericFunctions_1.wuzapiApiRequest.call(this, 'POST', endpoint, body); const executionData = this.helpers.constructExecutionMetaData([{ json: response }], { itemData: { item: i } }); returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { const executionData = this.helpers.constructExecutionMetaData([{ json: { error: error.message } }], { itemData: { item: i } }); returnData.push(...executionData); continue; } throw error; } } return [returnData]; } } exports.WuzapiMention = WuzapiMention; //# sourceMappingURL=WuzapiMention.node.js.map