n8n-nodes-zuckzapgo
Version:
n8n community nodes for ZuckZapGo - WhatsApp Multi-Device REST API
545 lines • 23.3 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZuckZapGoStatus = void 0;
const GenericFunctions_1 = require("../GenericFunctions");
class ZuckZapGoStatus {
constructor() {
this.description = {
displayName: 'ZuckZapGo Status',
name: 'zuckzapgoStatus',
icon: 'file:zuckzapgo.svg',
group: ['transform'],
version: 1,
subtitle: '={{$parameter["operation"]}}',
description: 'Send WhatsApp status messages using ZuckZapGo API',
defaults: {
name: 'ZuckZapGo Status',
},
inputs: ["main" /* NodeConnectionType.Main */],
outputs: ["main" /* NodeConnectionType.Main */],
credentials: [
{
name: 'zuckzapgoApi',
required: true,
},
],
properties: [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Send Text Status',
value: 'sendTextStatus',
description: 'Send a text status message',
action: 'Send text status',
},
{
name: 'Send Image Status',
value: 'sendImageStatus',
description: 'Send an image status message',
action: 'Send image status',
},
{
name: 'Send Video Status',
value: 'sendVideoStatus',
description: 'Send a video status message',
action: 'Send video status',
},
{
name: 'Send Audio Status',
value: 'sendAudioStatus',
description: 'Send an audio status message',
action: 'Send audio status',
},
],
default: 'sendTextStatus',
},
// Text Status fields
{
displayName: 'Text',
name: 'text',
type: 'string',
default: '',
placeholder: 'Your status message',
description: 'The text content for the status',
required: true,
displayOptions: {
show: {
operation: ['sendTextStatus'],
},
},
},
{
displayName: 'Background Color',
name: 'backgroundColor',
type: 'color',
default: '',
placeholder: '4294967295',
description: 'Background color in ARGB decimal format (optional)',
displayOptions: {
show: {
operation: ['sendTextStatus'],
},
},
},
{
displayName: 'Text Color',
name: 'textColor',
type: 'color',
default: '',
placeholder: '4278190080',
description: 'Text color in ARGB decimal format (optional)',
displayOptions: {
show: {
operation: ['sendTextStatus'],
},
},
},
{
displayName: 'Font',
name: 'font',
type: 'number',
default: 0,
typeOptions: {
minValue: 0,
maxValue: 10,
},
description: 'Font type (0-10)',
displayOptions: {
show: {
operation: ['sendTextStatus'],
},
},
},
// Image Status fields
{
displayName: 'Image Source',
name: 'imageSource',
type: 'options',
default: 'binary',
options: [
{
name: 'Binary Data',
value: 'binary',
description: 'Use binary data from previous node',
},
{
name: 'Base64',
value: 'base64',
description: 'Provide base64 encoded image',
},
{
name: 'URL',
value: 'url',
description: 'Provide URL to image file',
},
],
displayOptions: {
show: {
operation: ['sendImageStatus'],
},
},
},
{
displayName: 'Binary Property',
name: 'binaryProperty',
type: 'string',
default: 'data',
description: 'Name of the binary property containing the image',
displayOptions: {
show: {
operation: ['sendImageStatus'],
imageSource: ['binary'],
},
},
},
{
displayName: 'Base64 Image',
name: 'imageBase64',
type: 'string',
default: '',
placeholder: 'data:image/jpeg;base64,iVBORw0...',
description: 'Base64 encoded image with data URL prefix',
displayOptions: {
show: {
operation: ['sendImageStatus'],
imageSource: ['base64'],
},
},
required: true,
},
{
displayName: 'Image URL',
name: 'imageUrl',
type: 'string',
default: '',
placeholder: 'https://example.com/image.jpg',
description: 'URL to the image file',
displayOptions: {
show: {
operation: ['sendImageStatus'],
imageSource: ['url'],
},
},
required: true,
},
{
displayName: 'Caption',
name: 'imageCaption',
type: 'string',
default: '',
placeholder: 'Image caption',
description: 'Caption for the image status (optional)',
displayOptions: {
show: {
operation: ['sendImageStatus'],
},
},
},
// Video Status fields
{
displayName: 'Video Source',
name: 'videoSource',
type: 'options',
default: 'binary',
options: [
{
name: 'Binary Data',
value: 'binary',
description: 'Use binary data from previous node',
},
{
name: 'Base64',
value: 'base64',
description: 'Provide base64 encoded video',
},
{
name: 'URL',
value: 'url',
description: 'Provide URL to video file',
},
],
displayOptions: {
show: {
operation: ['sendVideoStatus'],
},
},
},
{
displayName: 'Binary Property',
name: 'videoBinaryProperty',
type: 'string',
default: 'data',
description: 'Name of the binary property containing the video',
displayOptions: {
show: {
operation: ['sendVideoStatus'],
videoSource: ['binary'],
},
},
},
{
displayName: 'Base64 Video',
name: 'videoBase64',
type: 'string',
default: '',
placeholder: 'data:video/mp4;base64,AAAAIGZ0eXBpc29t...',
description: 'Base64 encoded video with data URL prefix',
displayOptions: {
show: {
operation: ['sendVideoStatus'],
videoSource: ['base64'],
},
},
required: true,
},
{
displayName: 'Video URL',
name: 'videoUrl',
type: 'string',
default: '',
placeholder: 'https://example.com/video.mp4',
description: 'URL to the video file',
displayOptions: {
show: {
operation: ['sendVideoStatus'],
videoSource: ['url'],
},
},
required: true,
},
{
displayName: 'Caption',
name: 'videoCaption',
type: 'string',
default: '',
placeholder: 'Video caption',
description: 'Caption for the video status (optional)',
displayOptions: {
show: {
operation: ['sendVideoStatus'],
},
},
},
// Audio Status fields
{
displayName: 'Audio Source',
name: 'audioSource',
type: 'options',
default: 'binary',
options: [
{
name: 'Binary Data',
value: 'binary',
description: 'Use binary data from previous node',
},
{
name: 'Base64',
value: 'base64',
description: 'Provide base64 encoded audio',
},
{
name: 'URL',
value: 'url',
description: 'Provide URL to audio file',
},
],
displayOptions: {
show: {
operation: ['sendAudioStatus'],
},
},
},
{
displayName: 'Binary Property',
name: 'audioBinaryProperty',
type: 'string',
default: 'data',
description: 'Name of the binary property containing the audio',
displayOptions: {
show: {
operation: ['sendAudioStatus'],
audioSource: ['binary'],
},
},
},
{
displayName: 'Base64 Audio',
name: 'audioBase64',
type: 'string',
default: '',
placeholder: 'data:audio/ogg;base64,T2dnUwACAA...',
description: 'Base64 encoded audio with data URL prefix',
displayOptions: {
show: {
operation: ['sendAudioStatus'],
audioSource: ['base64'],
},
},
required: true,
},
{
displayName: 'Audio URL',
name: 'audioUrl',
type: 'string',
default: '',
placeholder: 'https://example.com/audio.ogg',
description: 'URL to the audio file',
displayOptions: {
show: {
operation: ['sendAudioStatus'],
audioSource: ['url'],
},
},
required: true,
},
{
displayName: 'Voice Note',
name: 'ptt',
type: 'boolean',
default: true,
description: 'Whether to send as voice note (PTT) or audio file',
displayOptions: {
show: {
operation: ['sendAudioStatus'],
},
},
},
{
displayName: 'Caption',
name: 'audioCaption',
type: 'string',
default: '',
placeholder: 'Audio caption',
description: 'Caption for the audio status (optional)',
displayOptions: {
show: {
operation: ['sendAudioStatus'],
},
},
},
// Common fields for all operations
{
displayName: 'Additional Options',
name: 'additionalOptions',
type: 'collection',
placeholder: 'Add Option',
default: {},
options: [
{
displayName: 'Message ID',
name: 'id',
type: 'string',
default: '',
description: 'Custom message ID (optional)',
},
{
displayName: 'Audience',
name: 'audience',
type: 'string',
default: '',
placeholder: '5491155553934@s.whatsapp.net,5491155553935@s.whatsapp.net',
description: 'Comma-separated list of JIDs for specific audience (optional)',
},
{
displayName: 'Exclude List',
name: 'excludeList',
type: 'string',
default: '',
placeholder: '5491155553936@s.whatsapp.net,5491155553937@s.whatsapp.net',
description: 'Comma-separated list of JIDs to exclude from viewing (optional)',
},
],
},
],
};
}
async execute() {
const items = this.getInputData();
const returnData = [];
for (let i = 0; i < items.length; i++) {
try {
const operation = this.getNodeParameter('operation', i);
const additionalOptions = this.getNodeParameter('additionalOptions', i);
let endpoint = '';
let body = {};
// Add common fields
if (additionalOptions.id) {
body.id = additionalOptions.id;
}
if (additionalOptions.audience) {
const audience = additionalOptions.audience.split(',').map(jid => jid.trim());
body.audience = audience;
}
if (additionalOptions.excludeList) {
const excludeList = additionalOptions.excludeList.split(',').map(jid => jid.trim());
body.exclude_list = excludeList;
}
if (operation === 'sendTextStatus') {
endpoint = '/status/send/text';
body.text = this.getNodeParameter('text', i);
const backgroundColor = this.getNodeParameter('backgroundColor', i);
if (backgroundColor) {
body.background_color = backgroundColor;
}
const textColor = this.getNodeParameter('textColor', i);
if (textColor) {
body.text_color = textColor;
}
const font = this.getNodeParameter('font', i);
if (font >= 0 && font <= 10) {
body.font = font;
}
}
else if (operation === 'sendImageStatus') {
endpoint = '/status/send/image';
const imageSource = this.getNodeParameter('imageSource', i);
if (imageSource === 'binary') {
const binaryProperty = this.getNodeParameter('binaryProperty', i);
const binaryData = items[i].binary?.[binaryProperty];
if (!binaryData) {
throw new Error(`Binary property "${binaryProperty}" not found`);
}
const buffer = Buffer.from(binaryData.data, 'base64');
body.image = (0, GenericFunctions_1.prepareMediaData)(buffer.buffer, binaryData.mimeType || 'image/jpeg');
}
else if (imageSource === 'base64') {
body.image = this.getNodeParameter('imageBase64', i);
}
else if (imageSource === 'url') {
body.image = this.getNodeParameter('imageUrl', i);
}
const caption = this.getNodeParameter('imageCaption', i);
if (caption) {
body.caption = caption;
}
}
else if (operation === 'sendVideoStatus') {
endpoint = '/status/send/video';
const videoSource = this.getNodeParameter('videoSource', i);
if (videoSource === 'binary') {
const binaryProperty = this.getNodeParameter('videoBinaryProperty', i);
const binaryData = items[i].binary?.[binaryProperty];
if (!binaryData) {
throw new Error(`Binary property "${binaryProperty}" not found`);
}
const buffer = Buffer.from(binaryData.data, 'base64');
body.video = (0, GenericFunctions_1.prepareMediaData)(buffer.buffer, binaryData.mimeType || 'video/mp4');
}
else if (videoSource === 'base64') {
body.video = this.getNodeParameter('videoBase64', i);
}
else if (videoSource === 'url') {
body.video = this.getNodeParameter('videoUrl', i);
}
const caption = this.getNodeParameter('videoCaption', i);
if (caption) {
body.caption = caption;
}
}
else if (operation === 'sendAudioStatus') {
endpoint = '/status/send/audio';
const audioSource = this.getNodeParameter('audioSource', i);
if (audioSource === 'binary') {
const binaryProperty = this.getNodeParameter('audioBinaryProperty', i);
const binaryData = items[i].binary?.[binaryProperty];
if (!binaryData) {
throw new Error(`Binary property "${binaryProperty}" not found`);
}
const buffer = Buffer.from(binaryData.data, 'base64');
body.audio = (0, GenericFunctions_1.prepareMediaData)(buffer.buffer, binaryData.mimeType || 'audio/ogg');
}
else if (audioSource === 'base64') {
body.audio = this.getNodeParameter('audioBase64', i);
}
else if (audioSource === 'url') {
body.audio = this.getNodeParameter('audioUrl', i);
}
const ptt = this.getNodeParameter('ptt', i);
body.ptt = ptt;
const caption = this.getNodeParameter('audioCaption', i);
if (caption) {
body.caption = caption;
}
}
const responseData = await GenericFunctions_1.zuckzapgoApiRequest.call(this, 'POST', endpoint, body);
const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: i } });
returnData.push(...executionData);
}
catch (error) {
if (this.continueOnFail()) {
const executionErrorData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray({ error: error.message }), { itemData: { item: i } });
returnData.push(...executionErrorData);
continue;
}
throw error;
}
}
return [returnData];
}
}
exports.ZuckZapGoStatus = ZuckZapGoStatus;
//# sourceMappingURL=ZuckZapGoStatus.node.js.map