n8n-nodes-zuckzapgo
Version:
n8n community nodes for ZuckZapGo - WhatsApp Multi-Device REST API
437 lines • 20.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZuckZapGoUser = void 0;
const GenericFunctions_1 = require("../GenericFunctions");
class ZuckZapGoUser {
constructor() {
this.description = {
displayName: 'ZuckZapGo User',
name: 'zuckzapgoUser',
icon: 'file:zuckzapgo.svg',
group: ['transform'],
version: 1,
subtitle: '={{$parameter["operation"]}}',
description: 'Get user information and manage presence with ZuckZapGo WhatsApp API',
defaults: {
name: 'ZuckZapGo User',
},
inputs: ["main" /* NodeConnectionType.Main */],
outputs: ["main" /* NodeConnectionType.Main */],
credentials: [
{
name: 'zuckzapgoApi',
required: true,
},
],
properties: [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Check Users',
value: 'check',
description: 'Check if users have WhatsApp',
action: 'Check users',
},
{
name: 'Get Avatar',
value: 'avatar',
description: 'Get user profile picture',
action: 'Get avatar',
},
{
name: 'Get Business Profile',
value: 'businessProfile',
description: 'Get complete business profile information',
action: 'Get business profile',
},
{
name: 'Get Contacts',
value: 'contacts',
description: 'Get all contacts',
action: 'Get contacts',
},
{
name: 'Get LID From Phone',
value: 'getLID',
description: 'Get Local ID (LID) from phone number/JID',
action: 'Get LID from phone',
},
{
name: 'Get My Status',
value: 'getMyStatus',
description: 'Get current user status message',
action: 'Get my status',
},
{
name: 'Get Phone From LID',
value: 'getPhoneFromLID',
description: 'Get phone number/JID from Local ID (LID)',
action: 'Get phone from LID',
},
{
name: 'Get Privacy Settings',
value: 'privacySettings',
description: 'Get privacy settings for the current user',
action: 'Get privacy settings',
},
{
name: 'Get User Info',
value: 'info',
description: 'Get detailed user information',
action: 'Get user info',
},
{
name: 'List LID Mappings',
value: 'listLIDMappings',
description: 'List all LID-Phone mappings',
action: 'List LID mappings',
},
{
name: 'Set My Status',
value: 'setMyStatus',
description: 'Set current user status message',
action: 'Set my status',
},
{
name: 'Set Presence',
value: 'presence',
description: 'Set global user presence',
action: 'Set presence',
},
{
name: 'Update Push Name',
value: 'updatePushName',
description: 'Update display name (push name)',
action: 'Update push name',
},
],
default: 'check',
},
// Check Users & Get User Info
{
displayName: 'Phone Numbers/LIDs',
name: 'phoneNumbers',
type: 'string',
default: '',
placeholder: 'e.g. 5491155553934,5491155553935,5491155554335@lid,5491435554335@lid',
description: 'Comma-separated list of phone numbers or LIDs (@lid) to check',
required: true,
displayOptions: {
show: {
operation: ['check', 'info'],
},
},
},
// Get Avatar
{
displayName: 'Target',
name: 'avatarPhone',
type: 'string',
default: '',
placeholder: 'e.g. 5491155553934 or 120363312246943103@g.us or 120363025246943103@newsletter or 5491155553935@lid',
description: 'Phone number, Group ID (@g.us), Newsletter ID (@newsletter), or LID (@lid) to get avatar for',
required: true,
displayOptions: {
show: {
operation: ['avatar'],
},
},
},
{
displayName: 'Preview',
name: 'preview',
type: 'boolean',
default: true,
description: 'Whether to get thumbnail (true) or full picture (false)',
displayOptions: {
show: {
operation: ['avatar'],
},
},
},
{
displayName: 'Save as Binary',
name: 'saveAsBinary',
type: 'boolean',
default: false,
description: 'Whether to save the avatar as binary data',
displayOptions: {
show: {
operation: ['avatar'],
},
},
},
{
displayName: 'Binary Property Name',
name: 'binaryPropertyName',
type: 'string',
default: 'avatar',
description: 'Name of the binary property to store the avatar',
displayOptions: {
show: {
operation: ['avatar'],
saveAsBinary: [true],
},
},
},
// LID Operations
{
displayName: 'Phone Number or JID',
name: 'lidPhone',
type: 'string',
default: '',
placeholder: 'e.g. 5491155553934 or 5491155553934@s.whatsapp.net',
description: 'Phone number or JID to get LID for',
required: true,
displayOptions: {
show: {
operation: ['getLID'],
},
},
},
{
displayName: 'Local ID (LID)',
name: 'lid',
type: 'string',
default: '',
placeholder: 'e.g. 1234567890@lid.whatsapp.net',
description: 'Local ID to get phone number for',
required: true,
displayOptions: {
show: {
operation: ['getPhoneFromLID'],
},
},
},
// Set Presence
{
displayName: 'Presence Type',
name: 'presenceType',
type: 'options',
default: 'available',
options: [
{
name: 'Available',
value: 'available',
description: 'Show as online',
},
{
name: 'Unavailable',
value: 'unavailable',
description: 'Show as offline',
},
],
description: 'Global presence status to set',
displayOptions: {
show: {
operation: ['presence'],
},
},
},
// Business Profile
{
displayName: 'Phone Number/JID',
name: 'businessPhone',
type: 'string',
default: '',
placeholder: 'e.g. 5491155553934 or 5491155553934@s.whatsapp.net',
description: 'Phone number or JID to get business profile for',
required: true,
displayOptions: {
show: {
operation: ['businessProfile'],
},
},
},
// Update Push Name
{
displayName: 'Push Name',
name: 'pushName',
type: 'string',
default: '',
placeholder: 'e.g. John Doe',
description: 'New display name (push name) to set',
required: true,
displayOptions: {
show: {
operation: ['updatePushName'],
},
},
},
// Set My Status
{
displayName: 'Status Message',
name: 'statusMessage',
type: 'string',
default: '',
placeholder: 'e.g. Available',
description: 'Status message to set',
required: true,
displayOptions: {
show: {
operation: ['setMyStatus'],
},
},
},
],
};
}
async execute() {
const items = this.getInputData();
const returnData = [];
for (let i = 0; i < items.length; i++) {
try {
const operation = this.getNodeParameter('operation', i);
let responseData;
if (operation === 'check') {
const phoneNumbers = this.getNodeParameter('phoneNumbers', i);
const phones = phoneNumbers.split(',').map(phone => {
const trimmed = phone.trim();
// Don't validate LIDs - they have @lid format
if (trimmed.includes('@lid')) {
return trimmed;
}
return (0, GenericFunctions_1.validatePhoneNumber)(trimmed);
});
const body = {
Phone: phones,
};
responseData = await GenericFunctions_1.zuckzapgoApiRequest.call(this, 'POST', '/user/check', body);
}
else if (operation === 'info') {
const phoneNumbers = this.getNodeParameter('phoneNumbers', i);
const phones = phoneNumbers.split(',').map(phone => {
const trimmed = phone.trim();
// Don't validate LIDs - they have @lid format
if (trimmed.includes('@lid')) {
return trimmed;
}
return (0, GenericFunctions_1.validatePhoneNumber)(trimmed);
});
const body = {
Phone: phones,
};
responseData = await GenericFunctions_1.zuckzapgoApiRequest.call(this, 'POST', '/user/info', body);
}
else if (operation === 'avatar') {
const phone = this.getNodeParameter('avatarPhone', i);
const preview = this.getNodeParameter('preview', i);
const saveAsBinary = this.getNodeParameter('saveAsBinary', i);
// Format target properly - all types use the same endpoint with Phone field
let formattedPhone;
if (phone.includes('@')) {
// Already has @ format (groups, newsletters, LIDs) - use as is
formattedPhone = phone;
}
else {
// Plain phone number - add @s.whatsapp.net
formattedPhone = `${phone}.whatsapp.net`;
}
const body = {
Phone: formattedPhone,
Preview: preview,
};
responseData = await GenericFunctions_1.zuckzapgoApiRequest.call(this, 'POST', '/user/avatar', body);
// Handle binary data if requested
if (saveAsBinary && responseData.data) {
const avatarUrl = responseData.data.URL || responseData.data;
if (avatarUrl && typeof avatarUrl === 'string') {
// If it's a URL, we need to fetch it
if (avatarUrl.startsWith('http')) {
// Store the URL for user to fetch separately
responseData.data.Note = 'Use HTTP Request node to download the image from the URL';
}
else if (avatarUrl.startsWith('data:')) {
// It's a data URL, extract the base64
const matches = avatarUrl.match(/^data:([^;]+);base64,(.+)$/);
if (matches && matches[2]) {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const mimeType = matches[1] || 'image/jpeg';
const base64Data = matches[2];
items[i].binary = items[i].binary || {};
items[i].binary[binaryPropertyName] = {
data: base64Data,
mimeType,
fileExtension: mimeType.split('/')[1] || 'jpg',
fileName: `avatar-${phone}.${mimeType.split('/')[1] || 'jpg'}`,
};
}
}
}
}
}
else if (operation === 'contacts') {
responseData = await GenericFunctions_1.zuckzapgoApiRequest.call(this, 'GET', '/user/contacts');
}
else if (operation === 'getLID') {
const phone = this.getNodeParameter('lidPhone', i);
const body = {
phone: phone,
};
responseData = await GenericFunctions_1.zuckzapgoApiRequest.call(this, 'POST', '/user/lid/get', body);
}
else if (operation === 'getPhoneFromLID') {
const lid = this.getNodeParameter('lid', i);
const body = {
lid: lid,
};
responseData = await GenericFunctions_1.zuckzapgoApiRequest.call(this, 'POST', '/user/lid/from-lid', body);
}
else if (operation === 'listLIDMappings') {
responseData = await GenericFunctions_1.zuckzapgoApiRequest.call(this, 'GET', '/user/lid/mappings');
}
else if (operation === 'presence') {
const presenceType = this.getNodeParameter('presenceType', i);
const body = {
type: presenceType,
};
responseData = await GenericFunctions_1.zuckzapgoApiRequest.call(this, 'POST', '/user/presence', body);
}
else if (operation === 'businessProfile') {
const phone = this.getNodeParameter('businessPhone', i);
const body = {
phone: phone,
};
responseData = await GenericFunctions_1.zuckzapgoApiRequest.call(this, 'POST', '/user/business/profile', body);
}
else if (operation === 'privacySettings') {
responseData = await GenericFunctions_1.zuckzapgoApiRequest.call(this, 'GET', '/user/privacy/settings');
}
else if (operation === 'updatePushName') {
const pushName = this.getNodeParameter('pushName', i);
const body = {
push_name: pushName,
};
responseData = await GenericFunctions_1.zuckzapgoApiRequest.call(this, 'POST', '/user/pushname', body);
}
else if (operation === 'getMyStatus') {
responseData = await GenericFunctions_1.zuckzapgoApiRequest.call(this, 'GET', '/user/status');
}
else if (operation === 'setMyStatus') {
const statusMessage = this.getNodeParameter('statusMessage', i);
const body = {
status: statusMessage,
};
responseData = await GenericFunctions_1.zuckzapgoApiRequest.call(this, 'POST', '/user/status', 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.ZuckZapGoUser = ZuckZapGoUser;
//# sourceMappingURL=ZuckZapGoUser.node.js.map