UNPKG

n8n-nodes-nqdev

Version:

Tích hợp dịch vụ eSMS.vn vào n8n, cho phép bạn dễ dàng gửi tin nhắn SMS, Zalo hoặc Viber trực tiếp từ quy trình tự động hóa. Với node này, bạn có thể nhanh chóng kết nối API eSMS.vn, gửi tin nhắn quảng cáo, chăm sóc khách hàng hoặc OTP chỉ trong vài bước

103 lines 6.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OttMessageResource = void 0; const n8n_workflow_1 = require("n8n-workflow"); const services_1 = require("../services"); const EsmsGenericFunctions_1 = require("../EsmsGenericFunctions"); class OttMessageResource { static async executeCommand(operation, itemIndex) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; const esmsCredentials = await EsmsGenericFunctions_1.getEsmsCredentials.call(this); const esmsSmsType = this.getNodeParameter('esmsSmsType', itemIndex, '2'), esmsZaloOA = (_b = (_a = this.getNodeParameter('esmsZaloOA', itemIndex, {})) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '', esmsTemplateId = (_d = (_c = this.getNodeParameter('esmsTemplateId', itemIndex, {})) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : ''; let responseData = { operation, status: 'backlog', timestamp: new Date().toISOString(), }; switch (operation) { case 'getListTemplate': { const esmsRequest = { smsType: esmsSmsType !== null && esmsSmsType !== void 0 ? esmsSmsType : '2', zaloOaId: esmsZaloOA !== null && esmsZaloOA !== void 0 ? esmsZaloOA : '', }; const esmsResponse = await services_1.getEsmsListTemplate.call(this, { ...esmsCredentials, ...esmsRequest, }); responseData['esmsRequest'] = esmsRequest; responseData['esmsResponse'] = esmsResponse; break; } case 'getZnsTemplateInfo': { const esmsRequest = { templateId: esmsTemplateId !== null && esmsTemplateId !== void 0 ? esmsTemplateId : '', zaloOaId: esmsZaloOA !== null && esmsZaloOA !== void 0 ? esmsZaloOA : '', }; const esmsResponse = await services_1.getEsmsZnsTemplateInfo.call(this, { ...esmsCredentials, ...esmsRequest, }); responseData['esmsRequest'] = esmsRequest; responseData['esmsResponse'] = esmsResponse; break; } case 'sendZnsMessage': { const esmsZaloOA = (_f = (_e = this.getNodeParameter('esmsZaloOA', itemIndex, {})) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : '', esmsTemplateId = (_h = (_g = this.getNodeParameter('esmsTemplateId', itemIndex, {})) === null || _g === void 0 ? void 0 : _g.value) !== null && _h !== void 0 ? _h : '', esmsZnsTemplateParameters = this.getNodeParameter('esmsZnsTemplateParameters', { parameters: [] }), options = this.getNodeParameter('options', {}); const parameters = Array.isArray(esmsZnsTemplateParameters.parameters) ? esmsZnsTemplateParameters.parameters : []; const znsTempData = parameters.reduce((acc, { paramKey, paramValue }) => { acc[paramKey] = paramValue; return acc; }, {}); let postData = { OAID: esmsZaloOA !== null && esmsZaloOA !== void 0 ? esmsZaloOA : '', TempID: esmsTemplateId !== null && esmsTemplateId !== void 0 ? esmsTemplateId : '', Phone: this.getNodeParameter('esmsPhonenumber', itemIndex, ''), TempData: znsTempData, IsUnicode: options['esmsIsUnicode'] ? '1' : '0', Sandbox: options['esmsIsSandbox'] ? '1' : '0', PartnerSource: (_j = options['esmsPartnerSource']) !== null && _j !== void 0 ? _j : '0', }; if (options['esmsIsLoggingRequest']) { responseData['esmsRequest'] = postData; } let esmsResponse = await services_1.sendZaloZnsMessage.call(this, { ...esmsCredentials, ...postData, }); responseData['esmsResponse'] = esmsResponse; break; } case 'sendViberMessage': { const esmsBrandname = (_l = (_k = this.getNodeParameter('esmsBrandname', itemIndex, {})) === null || _k === void 0 ? void 0 : _k.value) !== null && _l !== void 0 ? _l : '', options = this.getNodeParameter('options', {}); let postData = { SmsType: this.getNodeParameter('esmsSmsType', itemIndex, '2'), Brandname: esmsBrandname !== null && esmsBrandname !== void 0 ? esmsBrandname : '', Phone: this.getNodeParameter('esmsPhonenumber', itemIndex, ''), Content: this.getNodeParameter('esmsContent', itemIndex, ''), IsUnicode: options['esmsIsUnicode'] ? '1' : '0', Sandbox: options['esmsIsSandbox'] ? '1' : '0', PartnerSource: (_m = options['esmsPartnerSource']) !== null && _m !== void 0 ? _m : '0', }; if (options['esmsIsLoggingRequest']) { responseData['esmsRequest'] = postData; } let esmsResponse = await services_1.sendSmsMessage.call(this, { ...esmsCredentials, ...postData, }); responseData['esmsResponse'] = esmsResponse; break; } default: { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `The operation "${operation}" is not known!`, { itemIndex: itemIndex }); } } responseData['status'] = 'completed'; return responseData; } } exports.OttMessageResource = OttMessageResource; OttMessageResource.NAME_RESOURCE = 'ott_message'; //# sourceMappingURL=ott_message.resource.js.map