n8n-nodes-megaapi
Version:
N8N Community Node for MegaAPI WhatsApp automation - Complete WhatsApp integration with messaging, groups, media, and more
35 lines • 1.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.megaapiRequest = megaapiRequest;
async function megaapiRequest(method, endpoint, body = {}, qs = {}, customHeaders = {}) {
const credentials = await this.getCredentials('megaApiCredentialsApi');
const defaultHeaders = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${credentials.token}`,
};
const options = {
method,
body,
qs,
url: `${credentials.host}${endpoint}`,
headers: {
...defaultHeaders,
...customHeaders,
},
json: true,
};
this.logger.info(`[MegaAPI] Request URL: ${options.url}`);
this.logger.info(`[MegaAPI] Method: ${method}`);
this.logger.info(`[MegaAPI] Body:`, body);
this.logger.info(`[MegaAPI] Query params:`, qs);
try {
const response = await this.helpers.request(options);
this.logger.info(`[MegaAPI] Response:`, response);
return response;
}
catch (error) {
this.logger.error(`[MegaAPI] Error:`, error);
throw error;
}
}
//# sourceMappingURL=megaapiRequest.js.map