fix(whatsapp.gblib): SEND FILE and WPP providers.

This commit is contained in:
Rodrigo Rodriguez 2022-09-04 18:50:36 -03:00
parent e72b030e95
commit 5261691ba9
4 changed files with 116 additions and 99 deletions

52
package-lock.json generated
View file

@ -1,6 +1,6 @@
{ {
"name": "botserver", "name": "botserver",
"version": "2.0.167", "version": "2.0.168",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -5070,7 +5070,7 @@
"any-promise": { "any-promise": {
"version": "1.3.0", "version": "1.3.0",
"resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz", "resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz",
"integrity": "sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==" "integrity": "sha1-q8av7tzqUugJzcA3au0845Y10X8="
}, },
"any-shell-escape": { "any-shell-escape": {
"version": "0.1.1", "version": "0.1.1",
@ -5699,12 +5699,12 @@
"process-nextick-args": { "process-nextick-args": {
"version": "1.0.7", "version": "1.0.7",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz",
"integrity": "sha512-yN0WQmuCX63LP/TMvAg31nvT6m4vDqJEiiv2CAZqWOGNWutc9DfDk1NPYYmKUFmaVM2UwDowH4u5AHWYP/jxKw==" "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M="
}, },
"readable-stream": { "readable-stream": {
"version": "2.0.6", "version": "2.0.6",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.0.6.tgz", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.0.6.tgz",
"integrity": "sha512-TXcFfb63BQe1+ySzsHZI/5v1aJPCShfqvWJ64ayNImXMsN1Cd0YGk/wm8KB7/OeessgPc9QvS9Zou8QTkFzsLw==", "integrity": "sha1-j5A0HmilPMySh4jaz80Rs265t44=",
"requires": { "requires": {
"core-util-is": "~1.0.0", "core-util-is": "~1.0.0",
"inherits": "~2.0.1", "inherits": "~2.0.1",
@ -5717,22 +5717,22 @@
"sax": { "sax": {
"version": "0.5.8", "version": "0.5.8",
"resolved": "https://registry.npmjs.org/sax/-/sax-0.5.8.tgz", "resolved": "https://registry.npmjs.org/sax/-/sax-0.5.8.tgz",
"integrity": "sha512-c0YL9VcSfcdH3F1Qij9qpYJFpKFKMXNOkLWFssBL3RuF7ZS8oZhllR2rWlCRjDTJsfq3R6wbSsaRU6o0rkEdNw==" "integrity": "sha1-1HLbIo6zMcJQaw6MFVJK25OdEsE="
}, },
"string_decoder": { "string_decoder": {
"version": "0.10.31", "version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ==" "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
}, },
"underscore": { "underscore": {
"version": "1.8.3", "version": "1.8.3",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz", "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz",
"integrity": "sha512-5WsVTFcH1ut/kkhAaHf4PVgI8c7++GiVcpCGxPouI6ZVjsqPnSDf8h/8HtVqc0t4fzRXwnMK70EcZeAs3PIddg==" "integrity": "sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI="
}, },
"xml2js": { "xml2js": {
"version": "0.2.8", "version": "0.2.8",
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.2.8.tgz", "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.2.8.tgz",
"integrity": "sha512-ZHZBIAO55GHCn2jBYByVPHvHS+o3j8/a/qmpEe6kxO3cTnTCWC3Htq9RYJ5G4XMwMMClD2QkXA9SNdPadLyn3Q==", "integrity": "sha1-m4FpCTFjH/CdGVdUn69U9PmAs8I=",
"requires": { "requires": {
"sax": "0.5.x" "sax": "0.5.x"
} }
@ -5740,7 +5740,7 @@
"xmlbuilder": { "xmlbuilder": {
"version": "9.0.7", "version": "9.0.7",
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz", "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz",
"integrity": "sha512-7YXTQc3P2l9+0rjaUbLwMKRhtmwg1M1eDf6nag7urC7pIPYLD9W/jmzQ4ptRSUbodw5S0jfoGTflLemQibSpeQ==" "integrity": "sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0="
} }
} }
}, },
@ -6245,7 +6245,7 @@
"binary-search-bounds": { "binary-search-bounds": {
"version": "2.0.3", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/binary-search-bounds/-/binary-search-bounds-2.0.3.tgz", "resolved": "https://registry.npmjs.org/binary-search-bounds/-/binary-search-bounds-2.0.3.tgz",
"integrity": "sha512-GMGnMG7owGQwTBNWdOnWvU6KC2k/lULWdbdXq95kxJHdTzeDa9x8QNwMXCv/7pfPGx9Zdi1nmCDZ0j+Tmk+vRg==" "integrity": "sha1-X/hhbW3SylOIvIWy1iZuK52lAtw="
}, },
"bl": { "bl": {
"version": "4.1.0", "version": "4.1.0",
@ -6388,7 +6388,7 @@
"ms": { "ms": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
}, },
"tough-cookie": { "tough-cookie": {
"version": "2.5.0", "version": "2.5.0",
@ -7425,7 +7425,7 @@
"browserify-mime": { "browserify-mime": {
"version": "1.2.9", "version": "1.2.9",
"resolved": "https://registry.npmjs.org/browserify-mime/-/browserify-mime-1.2.9.tgz", "resolved": "https://registry.npmjs.org/browserify-mime/-/browserify-mime-1.2.9.tgz",
"integrity": "sha512-uz+ItyJXBLb6wgon1ELEiVowJBEsy03PUWGRQU7cxxx9S+DW2hujPp+DaMYEOClRPzsn7NB99NtJ6pGnt8y+CQ==" "integrity": "sha1-rrGvKN5sDXpqLOQK22j/GEIq8x8="
}, },
"browserslist": { "browserslist": {
"version": "4.19.1", "version": "4.19.1",
@ -8331,7 +8331,7 @@
"ansi-regex": { "ansi-regex": {
"version": "2.1.1", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
"integrity": "sha512-TIGnTpdo+E3+pCyAluZvtED5p5wCqLdezCyhPZzKPcxvFplEt4i+W7OONCKgeZFT3+y5NZZfOOS/Bdcanm1MYA==" "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8="
} }
} }
}, },
@ -10745,7 +10745,7 @@
"semaphore": { "semaphore": {
"version": "1.0.5", "version": "1.0.5",
"resolved": "https://registry.npmjs.org/semaphore/-/semaphore-1.0.5.tgz", "resolved": "https://registry.npmjs.org/semaphore/-/semaphore-1.0.5.tgz",
"integrity": "sha512-15WnK4TxpOk33fL0UoDnJ5myIWwJiodIZHtPRBoSxcaADt1Tm7kxEERd8n0vsw6OWsXwCCeROjSKU9MqfHaS1A==" "integrity": "sha1-tJJXbmavGT25XWXiXsU/Xxl5jWA="
}, },
"tunnel": { "tunnel": {
"version": "0.0.5", "version": "0.0.5",
@ -10755,7 +10755,7 @@
"underscore": { "underscore": {
"version": "1.8.3", "version": "1.8.3",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz", "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz",
"integrity": "sha512-5WsVTFcH1ut/kkhAaHf4PVgI8c7++GiVcpCGxPouI6ZVjsqPnSDf8h/8HtVqc0t4fzRXwnMK70EcZeAs3PIddg==" "integrity": "sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI="
} }
} }
}, },
@ -11641,7 +11641,7 @@
"event-emitter": { "event-emitter": {
"version": "0.3.5", "version": "0.3.5",
"resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz",
"integrity": "sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==", "integrity": "sha1-34xp7vFkeSPHFXuc6DhAYQsCzDk=",
"requires": { "requires": {
"d": "1", "d": "1",
"es5-ext": "~0.10.14" "es5-ext": "~0.10.14"
@ -13860,7 +13860,7 @@
"inflection": { "inflection": {
"version": "1.12.0", "version": "1.12.0",
"resolved": "https://registry.npmjs.org/inflection/-/inflection-1.12.0.tgz", "resolved": "https://registry.npmjs.org/inflection/-/inflection-1.12.0.tgz",
"integrity": "sha512-lRy4DxuIFWXlJU7ed8UiTJOSTqStqYdEb4CEbtXfNbkdj3nH1L+reUWiE10VWcJS2yR7tge8Z74pJjtBjNwj0w==" "integrity": "sha1-ogCTVlbW9fa8TcdQLhrstwMihBY="
}, },
"inflight": { "inflight": {
"version": "1.0.6", "version": "1.0.6",
@ -14082,7 +14082,7 @@
"int64-buffer": { "int64-buffer": {
"version": "0.1.10", "version": "0.1.10",
"resolved": "https://registry.npmjs.org/int64-buffer/-/int64-buffer-0.1.10.tgz", "resolved": "https://registry.npmjs.org/int64-buffer/-/int64-buffer-0.1.10.tgz",
"integrity": "sha512-v7cSY1J8ydZ0GyjUHqF+1bshJ6cnEVLo9EnjB8p+4HDRPZc9N5jjmvUV7NvEsqQOKyH0pmIBFWXVQbiS0+OBbA==" "integrity": "sha1-J3siiofZWtd30HwTgyAiQGpHNCM="
}, },
"internal-slot": { "internal-slot": {
"version": "1.0.3", "version": "1.0.3",
@ -14930,7 +14930,7 @@
"json-edm-parser": { "json-edm-parser": {
"version": "0.1.2", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/json-edm-parser/-/json-edm-parser-0.1.2.tgz", "resolved": "https://registry.npmjs.org/json-edm-parser/-/json-edm-parser-0.1.2.tgz",
"integrity": "sha512-J1U9mk6lf8dPULcaMwALXB6yel3cJyyhk9Z8FQ4sMwiazNwjaUhegIcpZyZFNMvLRtnXwh+TkCjX9uYUObBBYA==", "integrity": "sha1-HmCw/vG8CvZ7wNFG393lSGzWFbQ=",
"requires": { "requires": {
"jsonparse": "~1.2.0" "jsonparse": "~1.2.0"
} }
@ -16214,7 +16214,7 @@
"lru-queue": { "lru-queue": {
"version": "0.1.0", "version": "0.1.0",
"resolved": "https://registry.npmjs.org/lru-queue/-/lru-queue-0.1.0.tgz", "resolved": "https://registry.npmjs.org/lru-queue/-/lru-queue-0.1.0.tgz",
"integrity": "sha512-BpdYkt9EvGl8OfWHDQPISVpcl5xZthb+XPsbELj5AQXxIC8IriDZIQYjBJPEm5rS420sjZ0TLEzRcq5KdBhYrQ==", "integrity": "sha1-Jzi9nw089PhEkMVzbEhpmsYyzaM=",
"requires": { "requires": {
"es5-ext": "~0.10.2" "es5-ext": "~0.10.2"
} }
@ -16328,7 +16328,7 @@
"md5.js": { "md5.js": {
"version": "1.3.4", "version": "1.3.4",
"resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.4.tgz", "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.4.tgz",
"integrity": "sha512-cBB1zpoIg3GaI1IJyoc715xmWofOcXbMhVHAR/TLYk+RO+Y6xQfAp+UshPZTojAcju91Jyk5fw4CiLBuBVaQjw==", "integrity": "sha1-6b296UogpawYsENA/Fdk1bCdkB0=",
"requires": { "requires": {
"hash-base": "^3.0.0", "hash-base": "^3.0.0",
"inherits": "^2.0.1" "inherits": "^2.0.1"
@ -20986,7 +20986,7 @@
"priorityqueuejs": { "priorityqueuejs": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/priorityqueuejs/-/priorityqueuejs-1.0.0.tgz", "resolved": "https://registry.npmjs.org/priorityqueuejs/-/priorityqueuejs-1.0.0.tgz",
"integrity": "sha512-lg++21mreCEOuGWTbO5DnJKAdxfjrdN0S9ysoW9SzdSJvbkWpkaDdpG/cdsPCsEnoLUwmd9m3WcZhngW7yKA2g==" "integrity": "sha1-LuTyPCVgkT4IwHzlzN1t498sWvg="
}, },
"prism-media": { "prism-media": {
"version": "1.3.1", "version": "1.3.1",
@ -22897,7 +22897,7 @@
"is-fullwidth-code-point": { "is-fullwidth-code-point": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
"integrity": "sha512-VHskAKYM8RfSFXwee5t5cbN5PZeq1Wrh6qd5bkyiXIf6UQcN6w/A0eXM9r6t8d+GYOh+o6ZhiEnb88LN/Y8m2w==" "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8="
}, },
"locate-path": { "locate-path": {
"version": "3.0.0", "version": "3.0.0",
@ -22932,7 +22932,7 @@
"path-exists": { "path-exists": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz",
"integrity": "sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==" "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU="
}, },
"require-main-filename": { "require-main-filename": {
"version": "2.0.0", "version": "2.0.0",
@ -23414,7 +23414,7 @@
"simple-swizzle": { "simple-swizzle": {
"version": "0.2.2", "version": "0.2.2",
"resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz", "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz",
"integrity": "sha512-JA//kQgZtbuY83m+xT+tXJkmJncGMTFT+C+g2h2R9uxkYIrE2yy9sgmcLhCnw57/WSD+Eh3J97FPEDFnbXnDUg==", "integrity": "sha1-pNprY1/8zMoz9w0Xy5JZLeleVXo=",
"requires": { "requires": {
"is-arrayish": "^0.3.1" "is-arrayish": "^0.3.1"
} }
@ -26654,7 +26654,7 @@
"y18n": { "y18n": {
"version": "3.2.1", "version": "3.2.1",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz", "resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz",
"integrity": "sha512-Vd1yWKYGMtzFB6bAuTI7/POwJnwQStQXOe1PW1GmjUZgkaKYGc6/Pl3IDGFgplEklF65niuwBHeS5yve4+U01Q==" "integrity": "sha1-bRX7qITAhnnA136I53WegR4H+kE="
}, },
"yaeti": { "yaeti": {
"version": "0.0.6", "version": "0.0.6",

View file

@ -637,7 +637,6 @@ export class GBMinService {
await min.whatsAppDirectLine.setup(true); await min.whatsAppDirectLine.setup(true);
} else { } else {
const minBoot = GBServer.globals.minBoot as any; const minBoot = GBServer.globals.minBoot as any;
if (minBoot.instance.whatsappServiceUrl) {
min.whatsAppDirectLine = new WhatsappDirectLine( min.whatsAppDirectLine = new WhatsappDirectLine(
min, min,
min.botId, min.botId,
@ -648,7 +647,6 @@ export class GBMinService {
); );
await min.whatsAppDirectLine.setup(false); await min.whatsAppDirectLine.setup(false);
} }
}
// Setups default BOT Framework dialogs. // Setups default BOT Framework dialogs.

View file

@ -121,6 +121,14 @@ export class WhatsappDirectLine extends GBService {
switch (this.provider) { switch (this.provider) {
case 'GeneralBots': case 'GeneralBots':
const minBoot = GBServer.globals.minBoot as any;
if (minBoot.botId !== this.botId) {
this.customClient = minBoot.whatsAppDirectLine.customClient;
}
else {
// Initialize the browser using a local profile for each bot. // Initialize the browser using a local profile for each bot.
const gbaiName = `${this.min.botId}.gbai`; const gbaiName = `${this.min.botId}.gbai`;
@ -139,6 +147,7 @@ export class WhatsappDirectLine extends GBService {
// Dispatches messages to the received method. // Dispatches messages to the received method.
client.on('message', (async message => { client.on('message', (async message => {
await this.WhatsAppCallback(message, null); await this.WhatsAppCallback(message, null);
}).bind(this)); }).bind(this));
@ -181,6 +190,7 @@ export class WhatsappDirectLine extends GBService {
}); });
setUrl = false; setUrl = false;
}
break; break;
case 'chatapi': case 'chatapi':
@ -223,7 +233,7 @@ export class WhatsappDirectLine extends GBService {
break; break;
} }
if (setUrl) { if (setUrl && options) {
const express = require('express'); const express = require('express');
GBServer.globals.server.use(`/audios`, express.static('work')); GBServer.globals.server.use(`/audios`, express.static('work'));
@ -647,8 +657,8 @@ export class WhatsappDirectLine extends GBService {
let options; let options;
switch (this.provider) { switch (this.provider) {
case 'GeneralBots': case 'GeneralBots':
const attachment = MessageMedia.fromUrl(url); const attachment = await MessageMedia.fromUrl(url);
await this.customClient.sendMessage(to += '@c.us', attachment, { caption: caption }); await this.customClient.sendMessage(to + '@c.us', attachment, { caption: caption });
break; break;
case 'chatapi': case 'chatapi':
@ -698,6 +708,7 @@ export class WhatsappDirectLine extends GBService {
break; break;
} }
if (options) {
try { try {
// tslint:disable-next-line: await-promise // tslint:disable-next-line: await-promise
const result = await request.post(options); const result = await request.post(options);
@ -706,6 +717,7 @@ export class WhatsappDirectLine extends GBService {
GBLog.error(`Error sending file to Whatsapp provider ${error.message}`); GBLog.error(`Error sending file to Whatsapp provider ${error.message}`);
} }
} }
}
public async sendAudioToDevice(to, url, chatId) { public async sendAudioToDevice(to, url, chatId) {
@ -860,7 +872,7 @@ export class WhatsappDirectLine extends GBService {
switch (provider) { switch (provider) {
case "GeneralBots": case "GeneralBots":
id = req.author.split('@')[0]; id = req.from.split('@')[0];
senderName = req._data.notifyName; senderName = req._data.notifyName;
text = req.body; text = req.body;
@ -997,8 +1009,11 @@ export class WhatsappDirectLine extends GBService {
id, id,
`Olá! Seja bem-vinda(o)!\nMe chamo ${activeMin.instance.title}. Como posso ajudar? Pode me falar que eu te ouço, me manda um aúdio.` `Olá! Seja bem-vinda(o)!\nMe chamo ${activeMin.instance.title}. Como posso ajudar? Pode me falar que eu te ouço, me manda um aúdio.`
, null); , null);
if (res) {
res.end(); res.end();
} }
}
} else { } else {
// User wants to switch bots. // User wants to switch bots.
@ -1034,7 +1049,10 @@ export class WhatsappDirectLine extends GBService {
null null
); );
} }
if (res) {
res.end(); res.end();
}
} else { } else {
activeMin = GBServer.globals.minInstances.filter(p => p.instance.instanceId === user.instanceId)[0]; activeMin = GBServer.globals.minInstances.filter(p => p.instance.instanceId === user.instanceId)[0];
if (activeMin === undefined) { if (activeMin === undefined) {

View file

@ -112,6 +112,7 @@ export class GBServer {
try { try {
GBLog.info(`Now accepting connections on ${port}...`); GBLog.info(`Now accepting connections on ${port}...`);
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
// Reads basic configuration, initialize minimal services. // Reads basic configuration, initialize minimal services.