UNPKG

n8n-nodes-walichat

Version:

n8n plugin for WaliChat

147 lines (146 loc) 4.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.executeCatalogOperations = exports.catalogProperties = void 0; const request_1 = require("../request"); exports.catalogProperties = [ { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['catalog'], }, }, options: [ { name: 'Get My Catalog', value: 'getCatalog', description: 'Get your WhatsApp Business catalog information', }, { name: 'Query Business Catalog', value: 'queryCatalog', description: 'Query catalog for any WhatsApp Business number', }, ], default: 'getCatalog', }, { displayName: 'WhatsApp Number', name: 'device', type: 'string', required: true, default: '', typeOptions: { loadOptionsMethod: 'getDevices', }, displayOptions: { show: { resource: ['catalog'], }, }, description: 'The ID of your WhatsApp Business number', }, // GET CATALOG OPTIONS { displayName: 'Pagination', name: 'pagination', type: 'collection', placeholder: 'Add Pagination Option', default: {}, displayOptions: { show: { resource: ['catalog'], operation: ['getCatalog'], }, }, options: [ { displayName: 'Page Size', name: 'size', type: 'number', default: 100, description: 'Number of products to return per page', typeOptions: { minValue: 1, maxValue: 500, }, }, { displayName: 'Page Number', name: 'page', type: 'number', default: 0, description: 'Page number to return (starting from 0)', typeOptions: { minValue: 0, }, }, ], }, // QUERY CATALOG OPTIONS { displayName: 'Business Phone Number', name: 'phone', type: 'string', required: true, default: '', displayOptions: { show: { resource: ['catalog'], operation: ['queryCatalog'], }, }, description: 'The phone number of the WhatsApp Business account to query (e.g. +1234567890)', }, { displayName: 'Products to Return', name: 'size', type: 'number', required: false, default: 100, displayOptions: { show: { resource: ['catalog'], operation: ['queryCatalog'], }, }, description: 'Number of catalog product items to retrieve (max 500)', typeOptions: { minValue: 1, maxValue: 500, }, }, ]; async function executeCatalogOperations(index) { const operation = this.getNodeParameter('operation', index); const device = this.getNodeParameter('device', index); // GET MY CATALOG if (operation === 'getCatalog') { const pagination = this.getNodeParameter('pagination', index, {}); const queryParameters = {}; if (pagination.size) { queryParameters.size = pagination.size.toString(); } if (pagination.page !== undefined) { queryParameters.page = pagination.page.toString(); } return (0, request_1.request)(this, 'GET', `/devices/${device}/catalog`, undefined, queryParameters); } // QUERY BUSINESS CATALOG if (operation === 'queryCatalog') { const phone = this.getNodeParameter('phone', index); const size = this.getNodeParameter('size', index, 100); const body = { phone, }; if (size !== 100) { body.size = size; } return (0, request_1.request)(this, 'POST', `/devices/${device}/catalog`, body); } throw new Error(`The operation "${operation}" is not supported for catalog!`); } exports.executeCatalogOperations = executeCatalogOperations;