n8n-nodes-megaapi
Version:
N8N Community Node for MegaAPI WhatsApp automation - Complete WhatsApp integration with messaging, groups, media, and more
49 lines • 2.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateQrCode = generateQrCode;
const n8n_workflow_1 = require("n8n-workflow");
const megaapiRequest_1 = require("../megaapiRequest");
async function generateQrCode(index) {
const credentials = await this.getCredentials('megaApiCredentialsApi');
this.logger.info('📱 Generating QR Code for WhatsApp connection');
try {
const endpoint = `/rest/instance/qrcode_base64/${credentials.instanceKey}`;
const response = await megaapiRequest_1.megaapiRequest.call(this, 'GET', endpoint);
if (response.error) {
this.logger.error('❌ MegaAPI returned error', response);
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `MegaAPI Error: ${response.message || 'Unknown error'}`, { itemIndex: index });
}
let qrCodeData;
if (typeof response === 'string') {
qrCodeData = response;
}
else if (response && typeof response === 'object') {
qrCodeData = response.qrcode || response.qr_code || response.data || response.base64 || response;
}
else {
qrCodeData = response;
}
this.logger.info('✅ QR Code generated successfully', {
qrCodeLength: typeof qrCodeData === 'string' ? qrCodeData.length : 'Object received',
});
return {
json: {
success: true,
qrCode: qrCodeData,
qrCodeBase64: qrCodeData,
message: response.message || 'QR Code generated successfully',
instanceKey: credentials.instanceKey,
timestamp: new Date().toISOString(),
...response,
},
pairedItem: { item: index },
};
}
catch (error) {
this.logger.error('💥 Error generating QR code', {
error: error.message,
});
throw error;
}
}
//# sourceMappingURL=qrCode.js.map