n8n-nodes-wa-webjs
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -1,254 +0,270 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.WaWebJS = void 0; | ||
class WaWebJS { | ||
constructor() { | ||
this.description = { | ||
properties: [ | ||
{ | ||
displayName: 'Resource', | ||
name: 'resource', | ||
type: 'options', | ||
noDataExpression: true, | ||
options: [ | ||
{ | ||
name: 'Chatting', | ||
value: 'chatting', | ||
}, | ||
{ | ||
name: 'Session', | ||
value: 'session', | ||
}, | ||
{ | ||
name: 'Auth', | ||
value: 'auth', | ||
}, | ||
], | ||
default: 'chatting', | ||
}, | ||
{ | ||
displayName: 'Operation', | ||
name: 'operation', | ||
type: 'options', | ||
noDataExpression: true, | ||
displayOptions: { | ||
show: { | ||
resource: ['chatting'], | ||
}, | ||
}, | ||
options: [ | ||
{ | ||
name: 'SendText', | ||
value: 'sendText', | ||
action: 'Send text', | ||
description: 'Send Text Message', | ||
}, | ||
], | ||
default: 'sendText', | ||
}, | ||
{ | ||
displayName: 'Operation', | ||
name: 'operation', | ||
type: 'options', | ||
noDataExpression: true, | ||
displayOptions: { | ||
show: { | ||
resource: ['session'], | ||
}, | ||
}, | ||
options: [ | ||
{ | ||
name: 'Me', | ||
value: 'me', | ||
action: 'Me', | ||
}, | ||
{ | ||
name: 'Sessions', | ||
value: 'sessions', | ||
action: 'Sessions', | ||
}, | ||
{ | ||
name: 'Start', | ||
value: 'start', | ||
action: 'Start', | ||
}, | ||
{ | ||
name: 'Stop', | ||
value: 'stop', | ||
action: 'Stop', | ||
}, | ||
], | ||
default: 'start', | ||
}, | ||
{ | ||
displayName: 'Chat ID', | ||
name: 'chatId', | ||
type: 'string', | ||
required: true, | ||
displayOptions: { | ||
show: { | ||
operation: ['sendText'], | ||
resource: ['chatting'], | ||
}, | ||
}, | ||
default: '', | ||
placeholder: 'xxxxxxx@c.us', | ||
}, | ||
{ | ||
displayName: 'Text', | ||
name: 'text', | ||
type: 'string', | ||
required: true, | ||
displayOptions: { | ||
show: { | ||
operation: ['sendText'], | ||
resource: ['chatting'], | ||
}, | ||
}, | ||
default: '', | ||
placeholder: '', | ||
description: 'Text to send', | ||
}, | ||
{ | ||
displayName: 'Operation', | ||
name: 'operation', | ||
type: 'options', | ||
noDataExpression: true, | ||
displayOptions: { | ||
show: { | ||
resource: ['auth'], | ||
}, | ||
}, | ||
options: [ | ||
{ | ||
name: 'QR', | ||
value: 'qr', | ||
action: 'QR', | ||
}, | ||
], | ||
default: 'qr', | ||
}, | ||
{ | ||
displayName: 'Webhook URL', | ||
name: 'webhookUrl', | ||
type: 'string', | ||
required: true, | ||
displayOptions: { | ||
show: { | ||
operation: ['start'], | ||
resource: ['session'], | ||
}, | ||
}, | ||
default: '', | ||
placeholder: 'https://n8n.gms.church/xxxxxxxxx', | ||
}, | ||
], | ||
version: 1, | ||
defaults: { | ||
name: 'WaWebJS', | ||
}, | ||
inputs: ['main'], | ||
outputs: ['main'], | ||
displayName: 'Whatsapp WebJS', | ||
name: 'WaWebJS', | ||
icon: 'file:wa.svg', | ||
group: ['whatsapp'], | ||
description: 'Connect with Whatsapp WebJS API', | ||
credentials: [ | ||
{ | ||
name: 'waWebJSApi', | ||
required: true, | ||
}, | ||
], | ||
requestDefaults: { | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
baseURL: '={{$credentials.url}}', | ||
}, | ||
}; | ||
} | ||
async execute() { | ||
const cred = await this.getCredentials('waWebJSApi'); | ||
const session = cred.session; | ||
const items = this.getInputData(); | ||
const returnData = []; | ||
const resource = this.getNodeParameter('resource', 0); | ||
const operation = this.getNodeParameter('operation', 0); | ||
var options = { | ||
uri: `${cred.url}`, | ||
json: true, | ||
}; | ||
for (let i = 0; i < items.length; i++) { | ||
if (resource === 'chatting') { | ||
if (operation === 'sendText') { | ||
const chatId = this.getNodeParameter('chatId', i); | ||
const text = this.getNodeParameter('text', i); | ||
const session = 'default'; | ||
options.method = 'POST'; | ||
options.uri += `/${session}/messages/send-text`; | ||
options.body = { | ||
chatId: chatId, | ||
text: text | ||
}; | ||
const responseData = await this.helpers.requestWithAuthentication.call(this, 'waWebJSApi', options); | ||
returnData.push({ | ||
json: responseData, | ||
}); | ||
} | ||
} | ||
else if (resource === 'session') { | ||
if (operation === 'start') { | ||
const url = this.getNodeParameter('webhookUrl', i); | ||
options.method = 'POST'; | ||
options.uri += `/sessions/${session}/start`; | ||
options.body = { | ||
webhookUrl: url | ||
}; | ||
const responseData = await this.helpers.requestWithAuthentication.call(this, 'waWebJSApi', options); | ||
returnData.push({ | ||
json: responseData, | ||
}); | ||
} | ||
else if (operation === 'stop') { | ||
options.method = 'POST'; | ||
options.uri += `/sessions/${session}/stop`; | ||
const responseData = await this.helpers.requestWithAuthentication.call(this, 'waWebJSApi', options); | ||
returnData.push({ | ||
json: responseData, | ||
}); | ||
} | ||
else if (operation === 'me') { | ||
options.method = 'GET'; | ||
options.uri += `/sessions/${session}/me`; | ||
const responseData = await this.helpers.requestWithAuthentication.call(this, 'waWebJSApi', options); | ||
returnData.push({ | ||
json: responseData, | ||
}); | ||
} | ||
} | ||
else if (resource === 'auth') { | ||
if (operation === 'qr') { | ||
options.method = 'GET'; | ||
options.uri += `/sessions/${cred.session}/auth/qr`; | ||
const responseData = await this.helpers.requestWithAuthentication.call(this, 'waWebJSApi', options); | ||
let fileName = 'qrcode.png'; | ||
const mimeType = responseData.mimetype; | ||
const binaryPropertyName = 'qrcode'; | ||
const data = responseData.data; | ||
const binary = { | ||
[binaryPropertyName]: { data, fileName, mimeType }, | ||
}; | ||
returnData.push({ | ||
json: responseData, | ||
binary, | ||
}); | ||
} | ||
} | ||
} | ||
return this.prepareOutputData(returnData); | ||
} | ||
constructor() { | ||
this.description = { | ||
properties: [ | ||
{ | ||
displayName: 'Resource', | ||
name: 'resource', | ||
type: 'options', | ||
noDataExpression: true, | ||
options: [ | ||
{ | ||
name: 'Chatting', | ||
value: 'chatting', | ||
}, | ||
{ | ||
name: 'Session', | ||
value: 'session', | ||
}, | ||
{ | ||
name: 'Auth', | ||
value: 'auth', | ||
}, | ||
], | ||
default: 'chatting', | ||
}, | ||
{ | ||
displayName: 'Operation', | ||
name: 'operation', | ||
type: 'options', | ||
noDataExpression: true, | ||
displayOptions: { | ||
show: { | ||
resource: ['chatting'], | ||
}, | ||
}, | ||
options: [ | ||
{ | ||
name: 'SendText', | ||
value: 'sendText', | ||
action: 'Send text', | ||
description: 'Send Text Message', | ||
}, | ||
], | ||
default: 'sendText', | ||
}, | ||
{ | ||
displayName: 'Operation', | ||
name: 'operation', | ||
type: 'options', | ||
noDataExpression: true, | ||
displayOptions: { | ||
show: { | ||
resource: ['session'], | ||
}, | ||
}, | ||
options: [ | ||
{ | ||
name: 'Me', | ||
value: 'me', | ||
action: 'Me', | ||
}, | ||
{ | ||
name: 'Sessions', | ||
value: 'sessions', | ||
action: 'Sessions', | ||
}, | ||
{ | ||
name: 'Start', | ||
value: 'start', | ||
action: 'Start', | ||
}, | ||
{ | ||
name: 'Stop', | ||
value: 'stop', | ||
action: 'Stop', | ||
}, | ||
], | ||
default: 'start', | ||
}, | ||
{ | ||
displayName: 'Chat ID', | ||
name: 'chatId', | ||
type: 'string', | ||
required: true, | ||
displayOptions: { | ||
show: { | ||
operation: ['sendText'], | ||
resource: ['chatting'], | ||
}, | ||
}, | ||
default: '', | ||
placeholder: 'xxxxxxx@c.us', | ||
}, | ||
{ | ||
displayName: 'Text', | ||
name: 'text', | ||
type: 'string', | ||
required: true, | ||
displayOptions: { | ||
show: { | ||
operation: ['sendText'], | ||
resource: ['chatting'], | ||
}, | ||
}, | ||
default: '', | ||
placeholder: '', | ||
description: 'Text to send', | ||
}, | ||
{ | ||
displayName: 'Operation', | ||
name: 'operation', | ||
type: 'options', | ||
noDataExpression: true, | ||
displayOptions: { | ||
show: { | ||
resource: ['auth'], | ||
}, | ||
}, | ||
options: [ | ||
{ | ||
name: 'QR', | ||
value: 'qr', | ||
action: 'QR', | ||
}, | ||
], | ||
default: 'qr', | ||
}, | ||
{ | ||
displayName: 'Webhook URL', | ||
name: 'webhookUrl', | ||
type: 'string', | ||
required: true, | ||
displayOptions: { | ||
show: { | ||
operation: ['start'], | ||
resource: ['session'], | ||
}, | ||
}, | ||
default: '', | ||
placeholder: 'https://n8n.gms.church/xxxxxxxxx', | ||
}, | ||
], | ||
version: 1, | ||
defaults: { | ||
name: 'WaWebJS', | ||
}, | ||
inputs: ['main'], | ||
outputs: ['main'], | ||
displayName: 'Whatsapp WebJS', | ||
name: 'WaWebJS', | ||
icon: 'file:wa.svg', | ||
group: ['whatsapp'], | ||
description: 'Connect with Whatsapp WebJS API', | ||
credentials: [ | ||
{ | ||
name: 'waWebJSApi', | ||
required: true, | ||
}, | ||
], | ||
requestDefaults: { | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
baseURL: '={{$credentials.url}}', | ||
}, | ||
}; | ||
} | ||
async execute() { | ||
const cred = await this.getCredentials('waWebJSApi'); | ||
const session = cred.session; | ||
const items = this.getInputData(); | ||
const returnData = []; | ||
const resource = this.getNodeParameter('resource', 0); | ||
const operation = this.getNodeParameter('operation', 0); | ||
var options = { | ||
uri: `${cred.url}`, | ||
json: true, | ||
}; | ||
for (let i = 0; i < items.length; i++) { | ||
if (resource === 'chatting') { | ||
if (operation === 'sendText') { | ||
const chatId = this.getNodeParameter('chatId', i); | ||
const text = this.getNodeParameter('text', i); | ||
const session = 'default'; | ||
options.method = 'POST'; | ||
options.uri += `/${session}/messages/send-text`; | ||
options.body = { | ||
chatId: chatId, | ||
text: text, | ||
}; | ||
const responseData = await this.helpers.requestWithAuthentication.call( | ||
this, | ||
'waWebJSApi', | ||
options, | ||
); | ||
returnData.push({ | ||
json: responseData, | ||
}); | ||
} | ||
} else if (resource === 'session') { | ||
if (operation === 'start') { | ||
const url = this.getNodeParameter('webhookUrl', i); | ||
options.method = 'POST'; | ||
options.uri += `/sessions/${session}/start`; | ||
options.body = { | ||
webhookUrl: url, | ||
}; | ||
const responseData = await this.helpers.requestWithAuthentication.call( | ||
this, | ||
'waWebJSApi', | ||
options, | ||
); | ||
returnData.push({ | ||
json: responseData, | ||
}); | ||
} else if (operation === 'stop') { | ||
options.method = 'POST'; | ||
options.uri += `/sessions/${session}/stop`; | ||
const responseData = await this.helpers.requestWithAuthentication.call( | ||
this, | ||
'waWebJSApi', | ||
options, | ||
); | ||
returnData.push({ | ||
json: responseData, | ||
}); | ||
} else if (operation === 'me') { | ||
options.method = 'GET'; | ||
options.uri += `/sessions/${session}/me`; | ||
const responseData = await this.helpers.requestWithAuthentication.call( | ||
this, | ||
'waWebJSApi', | ||
options, | ||
); | ||
returnData.push({ | ||
json: responseData, | ||
}); | ||
} | ||
} else if (resource === 'auth') { | ||
if (operation === 'qr') { | ||
options.method = 'GET'; | ||
options.uri += `/sessions/${cred.session}/auth/qr`; | ||
const responseData = await this.helpers.requestWithAuthentication.call( | ||
this, | ||
'waWebJSApi', | ||
options, | ||
); | ||
let fileName = 'qrcode.png'; | ||
const mimeType = 'image/png'; | ||
const binaryPropertyName = 'qrcode'; | ||
const data = responseData; | ||
const binary = { | ||
[binaryPropertyName]: { data, fileName, mimeType }, | ||
}; | ||
returnData.push({ | ||
json: responseData, | ||
binary, | ||
}); | ||
} | ||
} | ||
} | ||
return this.prepareOutputData(returnData); | ||
} | ||
} | ||
exports.WaWebJS = WaWebJS; | ||
//# sourceMappingURL=WaWebJS.node.js.map | ||
//# sourceMappingURL=WaWebJS.node.js.map |
{ | ||
"name": "n8n-nodes-wa-webjs", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "n8n to connect with WA Web JS API", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
{ | ||
"name": "n8n-nodes-wa-webjs", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "n8n to connect with WA Web JS API", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
337
46230