@poli-digital/n8n-nodes-poli
Version:
Nó para interagir com a API da Poli
78 lines • 2.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SendMessageByContactId = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const transport_1 = require("./transport");
class SendMessageByContactId {
constructor() {
this.description = {
displayName: 'Send Message By Contact ID',
name: 'sendMessageByContactId',
icon: 'file:poli.svg',
group: ['output'],
version: 1,
description: 'Send a message to a contact by ID',
defaults: {
name: 'Send Message By Contact ID',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'poliApi',
required: true,
},
],
properties: [
{
displayName: 'Contact ID',
name: 'contactId',
type: 'string',
default: '',
required: true,
},
{
displayName: 'Account Channel ID',
name: 'accountChannelUuid',
type: 'string',
default: '',
required: true,
},
{
displayName: 'Text',
name: 'text',
type: 'string',
default: 'Teste de mensagem',
},
],
};
}
async execute() {
const items = this.getInputData();
const returnData = [];
for (let i = 0; i < items.length; i++) {
try {
const contactId = this.getNodeParameter('contactId', i);
const accountChannelUuid = this.getNodeParameter('accountChannelUuid', i);
const text = this.getNodeParameter('text', i);
const body = {
provider: 'WHATSAPP',
account_channel_uuid: accountChannelUuid,
type: 'TEXT',
version: 'v3',
direction: 'OUT',
components: { body: { text } },
};
const endpoint = `/contacts/${contactId}/messages`;
const responseData = await transport_1.apiRequest.call(this, 'POST', endpoint, body);
returnData.push({ json: responseData });
}
catch (error) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
}
}
return [returnData];
}
}
exports.SendMessageByContactId = SendMessageByContactId;
//# sourceMappingURL=SendMessageByContactId.operation.js.map