UNPKG

n8n-nodes-megaapi

Version:

N8N Community Node for MegaAPI WhatsApp automation - Complete WhatsApp integration with messaging, groups, media, and more

61 lines 2.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getGroups = getGroups; const megaapiRequest_1 = require("../megaapiRequest"); async function getGroups(itemIndex) { var _a; const credentials = await this.getCredentials('megaApiCredentialsApi'); const instanceKey = credentials.instanceKey; console.log('🔐 MegaAPI Credentials loaded'); console.log(`📋 Operation: getGroups (item ${itemIndex + 1})`); console.log(`📱 Instance Key: ${instanceKey}`); try { const apiUrl = `/rest/group/list/${instanceKey}`; console.log(`🌐 Full URL: ${credentials.host}${apiUrl}`); console.log('📤 Request Options'); console.log(` Method: GET`); console.log(` Authorization: Bearer ${(_a = credentials.token) === null || _a === void 0 ? void 0 : _a.substring(0, 10)}...`); console.log(` Content-Type: application/json`); console.log('📋 Fetching groups list from MegaAPI...'); const response = await megaapiRequest_1.megaapiRequest.call(this, 'GET', apiUrl); console.log('📥 Response received', typeof response === 'string' ? response.substring(0, 50) + '...' : response); let groupsData; if (typeof response === 'string') { try { groupsData = JSON.parse(response); } catch { groupsData = { message: response, status: 'unknown' }; } } else { groupsData = response; } let groupCount = 0; if (Array.isArray(groupsData)) { groupCount = groupsData.length; } else if (groupsData && typeof groupsData === 'object' && groupsData.groups && Array.isArray(groupsData.groups)) { groupCount = groupsData.groups.length; } console.log(`✅ Groups list retrieved successfully. Found ${groupCount} groups.`); return { json: { success: true, operation: 'getGroups', instanceKey, groupCount, message: `Groups list retrieved successfully. Found ${groupCount} groups.`, data: groupsData, timestamp: new Date().toISOString(), }, pairedItem: { item: itemIndex }, }; } catch (error) { console.log('💥 Error in MegaAPI Get Groups operation'); console.log(error); throw error; } } //# sourceMappingURL=getGroups.js.map