Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

n8n-nodes-whatsapp-buttons

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

n8n-nodes-whatsapp-buttons - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

10

dist/nodes/WhatsAppButtons/WhatsAppButtons.node.d.ts
import type { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from "n8n-workflow";
export declare type FieldsUiValues = Array<{
export declare type SectionArray = Array<{
sectionTitle: string;
buttonInSection: MidButtonArray;
}>;
export declare type MidButtonArray = {
buttons: ButtonArray;
};
export declare type ButtonArray = Array<{
buttonTitle: string;
buttonDescription: string;
}>;

@@ -5,0 +13,0 @@ export declare class WhatsAppButtons implements INodeType {

@@ -16,3 +16,3 @@ "use strict";

version: 1,
subtitle: "0.1.5",
subtitle: "0.1.6",
description: "Send Message With Buttons",

@@ -37,5 +37,9 @@ defaults: {

{
name: "Interactive",
name: "In-Message Buttons",
value: "interactive",
},
{
name: "List Buttons",
value: "listButtons",
},
],

@@ -45,2 +49,15 @@ default: "interactive",

{
displayName: "List Title",
name: "listTitle",
type: "string",
default: "",
required: true,
displayOptions: {
show: {
action: ["listButtons"],
},
},
description: "Enter the title of the list button",
},
{
displayName: "Message",

@@ -98,3 +115,3 @@ name: "message",

displayName: "Max 3 Buttons",
name: "fieldsUi",
name: "plainButton",
placeholder: "Add Button",

@@ -107,2 +124,7 @@ type: "fixedCollection",

},
displayOptions: {
show: {
action: ["interactive"],
},
},
default: {},

@@ -124,2 +146,71 @@ options: [

},
{
displayName: "Button List",
name: "buttonWithDescription",
placeholder: "Add Section",
type: "fixedCollection",
description: "Field must be defined in the collection, otherwise it will be ignored. If field defined in the collection is not set here, it will be set to null.",
typeOptions: {
multipleValues: true,
},
displayOptions: {
show: {
action: ["listButtons"],
},
},
default: {},
options: [
{
displayName: "Section",
name: "section",
default: {},
type: "fixedCollection",
placeholder: "Add Button",
typeOptions: {
multipleValues: true,
},
values: [
{
displayName: "Section Title",
name: "sectionTitle",
type: "string",
default: "",
},
{
displayName: "Buttons In Section",
name: "buttonInSection",
placeholder: "Add Button",
type: "fixedCollection",
typeOptions: {
multipleValues: true,
},
default: {},
options: [
{
displayName: "Button",
name: "buttons",
default: {},
type: "fixedCollection",
placeholder: "Add Button",
values: [
{
displayName: "Title",
name: "buttonTitle",
type: "string",
default: "",
},
{
displayName: "Description",
name: "buttonDescription",
type: "string",
default: "",
},
],
},
],
},
],
},
],
},
],

@@ -137,3 +228,2 @@ };

const credentials = await this.getCredentials("whatsAppButtonsApi");
const queryParams = this.getNodeParameter("fieldsUi.fieldValues", 0, "");
let responseData;

@@ -144,5 +234,14 @@ let request;

case "interactive":
request = handleQuery(`${baseURL}/${credentials.phoneNumberID}/messages`, message, phoneNumber, headerAction, headerImageURL, footer, queryParams, credentials);
console.log("interactive tapped");
const buttonFields = this.getNodeParameter("plainButton.fieldValues", 0, "");
request = handleInteractiveButtonsRequest(`${baseURL}/${credentials.phoneNumberID}/messages`, message, phoneNumber, headerAction, headerImageURL, footer, buttonFields, credentials);
responseData = (await request).data;
break;
case "listButtons":
console.log("listButtons tapped");
const buttonFieldsWithDescription = this.getNodeParameter("buttonWithDescription.section", 0, "");
const listTitle = this.getNodeParameter("listTitle", 0);
request = handleListButtonsRequest(`${baseURL}/${credentials.phoneNumberID}/messages`, message, phoneNumber, headerAction, headerImageURL, footer, listTitle, buttonFieldsWithDescription, credentials);
responseData = (await request).data;
break;
}

@@ -156,12 +255,12 @@ const outputData = [{ json: responseData }];

}
function handleQuery(url, message, phoneNumber, headerAction, headerImageURL, footer, queryParameters, credentials) {
const jsonPayload = {
function buildBaseJSON(phoneNumber, message, headerImageURL, footer) {
const json = {
messaging_product: "whatsapp",
recipient_type: "individual",
to: phoneNumber,
to: "",
type: "interactive",
interactive: {
type: "button",
type: "",
body: {
text: message,
text: "",
},

@@ -171,4 +270,6 @@ action: {},

};
json.to = phoneNumber;
json.interactive.body.text = message;
if (headerAction === "image") {
jsonPayload.interactive.header = {
json.interactive.header = {
type: "image",

@@ -181,12 +282,14 @@ image: {

if (footer.length > 0) {
jsonPayload.interactive.footer = {
json.interactive.footer = {
text: footer,
};
}
return json;
}
function handleInteractiveButtonsRequest(url, message, phoneNumber, headerAction, headerImageURL, footer, queryParameters, credentials) {
const json = buildBaseJSON(phoneNumber, message, headerImageURL, footer);
json.interactive.type = 'button';
if (queryParameters.length > 0) {
const parametersArray = queryParameters.map((x) => {
return x.buttonTitle;
});
let buttons = [];
parametersArray.forEach((button, index) => {
queryParameters.forEach((button, index) => {
buttons.push({

@@ -196,10 +299,10 @@ type: "reply",

id: `button_${index.toString()}`,
title: button,
title: button.buttonTitle,
},
});
});
jsonPayload.interactive.action.buttons = buttons;
json.interactive.action.buttons = buttons;
}
console.log(JSON.stringify(jsonPayload));
return axios_1.default.post(url, JSON.stringify(jsonPayload), {
console.log(JSON.stringify(json));
return axios_1.default.post(url, JSON.stringify(json), {
headers: {

@@ -211,2 +314,31 @@ Authorization: `Bearer ${credentials.apiKey}`,

}
function handleListButtonsRequest(url, message, phoneNumber, headerAction, headerImageURL, footer, listTitle, sections, credentials) {
const json = buildBaseJSON(phoneNumber, message, headerImageURL, footer);
json.interactive.type = 'list';
let sectionsDict = [];
sections.forEach((section) => {
const buttons = section.buttonInSection.buttons.map((button, index) => {
return {
id: `button_${index.toString()}`,
title: button.buttonTitle,
description: button.buttonDescription
};
});
sectionsDict.push({
title: section.sectionTitle,
rows: buttons
});
});
json.interactive.action = {
button: listTitle,
sections: sectionsDict
};
console.log(JSON.stringify(json));
return axios_1.default.post(url, JSON.stringify(json), {
headers: {
Authorization: `Bearer ${credentials.apiKey}`,
"Content-Type": "application/json"
},
});
}
}

@@ -213,0 +345,0 @@ }

2

dist/package.json
{
"name": "n8n-nodes-whatsapp-buttons",
"version": "0.1.5",
"version": "0.1.6",
"description": "Encapsulate WhatsApp Business API for sending messages with actions",

@@ -5,0 +5,0 @@ "keywords": [

{
"name": "n8n-nodes-whatsapp-buttons",
"version": "0.1.5",
"version": "0.1.6",
"description": "Encapsulate WhatsApp Business API for sending messages with actions",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc