new(whatsapp.gblib): New providers.

This commit is contained in:
Rodrigo Rodriguez 2022-07-15 09:05:16 -03:00
parent 9e82beaf19
commit 963202a31a
7 changed files with 276 additions and 33 deletions

1
.gitignore vendored
View file

@ -18,3 +18,4 @@
.env
*.env
.vscode/launch.json
.wwebjs_auth

BIN
logo.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 8 KiB

235
package-lock.json generated
View file

@ -5023,7 +5023,7 @@
"any-promise": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz",
"integrity": "sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A=="
"integrity": "sha1-q8av7tzqUugJzcA3au0845Y10X8="
},
"any-shell-escape": {
"version": "0.1.1",
@ -6326,7 +6326,7 @@
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"tough-cookie": {
"version": "2.5.0",
@ -8587,7 +8587,7 @@
"ansi-regex": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
"integrity": "sha512-TIGnTpdo+E3+pCyAluZvtED5p5wCqLdezCyhPZzKPcxvFplEt4i+W7OONCKgeZFT3+y5NZZfOOS/Bdcanm1MYA=="
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8="
}
}
},
@ -10912,6 +10912,16 @@
"resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-26.6.2.tgz",
"integrity": "sha512-Mv/TDa3nZ9sbc5soK+OoA74BsS3mL37yixCvUAQkiuA4Wz6YtwP/K47n2rv2ovzHZvoiQeA5FTQOschKkEwB0Q=="
},
"dijkstrajs": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/dijkstrajs/-/dijkstrajs-1.0.2.tgz",
"integrity": "sha512-QV6PMaHTCNmKSeP6QoXhVTw9snc9VD8MulTT0Bd99Pacp4SS1cjcrYPgBPmibqKVtMJJfqC6XvOXgPMEEPH/fg=="
},
"dingbat-to-unicode": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dingbat-to-unicode/-/dingbat-to-unicode-1.0.1.tgz",
"integrity": "sha512-98l0sW87ZT58pU4i61wa2OHwxbiYSbuxsCBozaVnYX2iCnr3bLM3fIes1/ej7h1YdOKuKt/MLs706TVnALA65w=="
},
"dir-glob": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz",
@ -10983,6 +10993,21 @@
}
}
},
"docxtemplater": {
"version": "3.31.1",
"resolved": "https://registry.npmjs.org/docxtemplater/-/docxtemplater-3.31.1.tgz",
"integrity": "sha512-29sYBrZ/7bwObIv+DS+tIE0EJCEVCnAIcPDQxGHphEgKPLwTe90BKJ/4YeYaT435siImUSN1dQ2I/2nIMbNQIw==",
"requires": {
"@xmldom/xmldom": "^0.8.2"
},
"dependencies": {
"@xmldom/xmldom": {
"version": "0.8.2",
"resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.8.2.tgz",
"integrity": "sha512-+R0juSseERyoPvnBQ/cZih6bpF7IpCXlWbHRoCRzYzqpz6gWHOgf8o4MOEf6KBVuOyqU+gCNLkCWVIJAro8XyQ=="
}
}
},
"dom-serializer": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.1.1.tgz",
@ -11092,6 +11117,14 @@
"resolved": "https://registry.npmjs.org/doublearray/-/doublearray-0.0.2.tgz",
"integrity": "sha512-aw55FtZzT6AmiamEj2kvmR6BuFqvYgKZUkfQ7teqVRNqD5UE0rw8IeW/3gieHNKQ5sPuDKlljWEn4bzv5+1bHw=="
},
"duck": {
"version": "0.1.12",
"resolved": "https://registry.npmjs.org/duck/-/duck-0.1.12.tgz",
"integrity": "sha512-wkctla1O6VfP89gQ+J/yDesM0S7B7XLXjKGzXxMDVFg7uEn706niAtyYovKbyq1oT9YwDcly721/iUWoc8MVRg==",
"requires": {
"underscore": "^1.13.1"
}
},
"duplexer": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz",
@ -11286,6 +11319,11 @@
"env-variable": "0.0.x"
}
},
"encode-utf8": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/encode-utf8/-/encode-utf8-1.0.3.tgz",
"integrity": "sha512-ucAnuBEhUK4boH2HjVYG5Q2mQyPorvv0u/ocS+zhdw0S8AlHYY+GOFhP1Gio5z4icpP2ivFSvhtFjQi8+T9ppw=="
},
"encodeurl": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
@ -11847,7 +11885,7 @@
"event-emitter": {
"version": "0.3.5",
"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": {
"d": "1",
"es5-ext": "~0.10.14"
@ -14061,7 +14099,7 @@
"inflection": {
"version": "1.12.0",
"resolved": "https://registry.npmjs.org/inflection/-/inflection-1.12.0.tgz",
"integrity": "sha512-lRy4DxuIFWXlJU7ed8UiTJOSTqStqYdEb4CEbtXfNbkdj3nH1L+reUWiE10VWcJS2yR7tge8Z74pJjtBjNwj0w=="
"integrity": "sha1-ogCTVlbW9fa8TcdQLhrstwMihBY="
},
"inflight": {
"version": "1.0.6",
@ -16304,6 +16342,16 @@
"integrity": "sha1-eB4YMpaqlPbU2RbcM10NF676I/g=",
"dev": true
},
"lop": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/lop/-/lop-0.4.1.tgz",
"integrity": "sha512-9xyho9why2A2tzm5aIcMWKvzqKsnxrf9B5I+8O30olh6lQU8PH978LqZoI4++37RBgS1Em5i54v1TFs/3wnmXQ==",
"requires": {
"duck": "^0.1.12",
"option": "~0.2.1",
"underscore": "^1.13.1"
}
},
"loud-rejection": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/loud-rejection/-/loud-rejection-1.6.0.tgz",
@ -16330,7 +16378,7 @@
"lru-queue": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/lru-queue/-/lru-queue-0.1.0.tgz",
"integrity": "sha512-BpdYkt9EvGl8OfWHDQPISVpcl5xZthb+XPsbELj5AQXxIC8IriDZIQYjBJPEm5rS420sjZ0TLEzRcq5KdBhYrQ==",
"integrity": "sha1-Jzi9nw089PhEkMVzbEhpmsYyzaM=",
"requires": {
"es5-ext": "~0.10.2"
}
@ -16369,6 +16417,39 @@
"integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==",
"dev": true
},
"mammoth": {
"version": "1.4.21",
"resolved": "https://registry.npmjs.org/mammoth/-/mammoth-1.4.21.tgz",
"integrity": "sha512-znix1/i7LtfVMAe6mmrxJSoN1HmTASJ48I+PofSHs4vPKCuPF1DDOCVeMgZTYpitzjWTWs9Xhxxi2LBbHpmovg==",
"requires": {
"argparse": "~1.0.3",
"bluebird": "~3.4.0",
"dingbat-to-unicode": "^1.0.1",
"jszip": "^3.7.1",
"lop": "^0.4.1",
"path-is-absolute": "^1.0.0",
"sax": "~1.1.1",
"underscore": "^1.13.1",
"xmlbuilder": "^10.0.0"
},
"dependencies": {
"bluebird": {
"version": "3.4.7",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.4.7.tgz",
"integrity": "sha512-iD3898SR7sWVRHbiQv+sHUtHnMvC1o3nW5rAcqnq3uOn07DSAppZYUkIGslDz6gXC7HfunPe7YVBgoEJASPcHA=="
},
"sax": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.1.6.tgz",
"integrity": "sha512-8zci48uUQyfqynGDSkUMD7FCJB96hwLnlZOXlgs1l3TX+LW27t3psSWKUxC0fxVgA86i8tL4NwGcY1h/6t3ESg=="
},
"xmlbuilder": {
"version": "10.1.1",
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-10.1.1.tgz",
"integrity": "sha512-OyzrcFLL/nb6fMGHbiRDuPup9ljBycsdCypwuyg5AAHvyWzGfChJpCXMG88AGTIMFhGZ9RccFN1e6lhg3hkwKg=="
}
}
},
"map-age-cleaner": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz",
@ -19656,6 +19737,11 @@
}
}
},
"option": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/option/-/option-0.2.4.tgz",
"integrity": "sha512-pkEqbDyl8ou5cpq+VsnQbe/WlEy5qS7xPzMS1U55OCG9KPvwFD46zDbxQIj3egJSFc3D+XhYOPUzz49zQAVy7A=="
},
"optionator": {
"version": "0.8.3",
"resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.3.tgz",
@ -20157,6 +20243,14 @@
"node-modules-regexp": "^1.0.0"
}
},
"pizzip": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/pizzip/-/pizzip-3.0.6.tgz",
"integrity": "sha512-CYmQJQ6ShNhScp2zrpGetRfamQ2CtUdsfcXaauqsQ0h/HVdQTTlHNUaNzMO0i+l8XTNctHJ6PrmFP+YZoF4iZw==",
"requires": {
"pako": "~1.0.2"
}
},
"pkg-conf": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/pkg-conf/-/pkg-conf-2.1.0.tgz",
@ -20352,6 +20446,11 @@
"resolved": "https://registry.npmjs.org/png-js/-/png-js-1.0.0.tgz",
"integrity": "sha512-k+YsbhpA9e+EFfKjTCH3VW6aoKlyNYI6NYdTfDL4CIvFnvsuO84ttonmZE7rc+v23SLTH8XX+5w/Ak9v0xGY4g=="
},
"pngjs": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/pngjs/-/pngjs-5.0.0.tgz",
"integrity": "sha512-40QW5YalBNfQo5yRYmiw7Yz6TKKVr3h6970B2YE+3fQpsWcrbj1PzJgxeJ19DRQjhMbKPIuMY8rFaXc8moolVw=="
},
"pop-iterate": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/pop-iterate/-/pop-iterate-1.0.1.tgz",
@ -21391,6 +21490,124 @@
"resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz",
"integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc="
},
"qrcode": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/qrcode/-/qrcode-1.5.0.tgz",
"integrity": "sha512-9MgRpgVc+/+47dFvQeD6U2s0Z92EsKzcHogtum4QB+UNd025WOJSHvn/hjk9xmzj7Stj95CyUAs31mrjxliEsQ==",
"requires": {
"dijkstrajs": "^1.0.1",
"encode-utf8": "^1.0.3",
"pngjs": "^5.0.0",
"yargs": "^15.3.1"
},
"dependencies": {
"cliui": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz",
"integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==",
"requires": {
"string-width": "^4.2.0",
"strip-ansi": "^6.0.0",
"wrap-ansi": "^6.2.0"
}
},
"find-up": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz",
"integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==",
"requires": {
"locate-path": "^5.0.0",
"path-exists": "^4.0.0"
}
},
"get-caller-file": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
"integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg=="
},
"locate-path": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz",
"integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==",
"requires": {
"p-locate": "^4.1.0"
}
},
"p-limit": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz",
"integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==",
"requires": {
"p-try": "^2.0.0"
}
},
"p-locate": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz",
"integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==",
"requires": {
"p-limit": "^2.2.0"
}
},
"p-try": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
"integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ=="
},
"path-exists": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz",
"integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w=="
},
"require-main-filename": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz",
"integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg=="
},
"wrap-ansi": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz",
"integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==",
"requires": {
"ansi-styles": "^4.0.0",
"string-width": "^4.1.0",
"strip-ansi": "^6.0.0"
}
},
"y18n": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz",
"integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ=="
},
"yargs": {
"version": "15.4.1",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz",
"integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==",
"requires": {
"cliui": "^6.0.0",
"decamelize": "^1.2.0",
"find-up": "^4.1.0",
"get-caller-file": "^2.0.1",
"require-directory": "^2.1.1",
"require-main-filename": "^2.0.0",
"set-blocking": "^2.0.0",
"string-width": "^4.2.0",
"which-module": "^2.0.0",
"y18n": "^4.0.0",
"yargs-parser": "^18.1.2"
}
},
"yargs-parser": {
"version": "18.1.3",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz",
"integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==",
"requires": {
"camelcase": "^5.0.0",
"decamelize": "^1.2.0"
}
}
}
},
"qrcode-terminal": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/qrcode-terminal/-/qrcode-terminal-0.12.0.tgz",
@ -22815,7 +23032,7 @@
"is-fullwidth-code-point": {
"version": "2.0.0",
"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": {
"version": "3.0.0",
@ -22850,7 +23067,7 @@
"path-exists": {
"version": "3.0.0",
"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": {
"version": "2.0.0",
@ -26446,7 +26663,7 @@
"y18n": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz",
"integrity": "sha512-Vd1yWKYGMtzFB6bAuTI7/POwJnwQStQXOe1PW1GmjUZgkaKYGc6/Pl3IDGFgplEklF65niuwBHeS5yve4+U01Q=="
"integrity": "sha1-bRX7qITAhnnA136I53WegR4H+kE="
},
"yaeti": {
"version": "0.0.6",

View file

@ -85,6 +85,7 @@
"core-js": "3.14.0",
"data-forge": "^1.9.5",
"date-diff": "0.2.2",
"docxtemplater": "^3.31.1",
"dotenv-extended": "2.9.0",
"exceljs": "4.2.1",
"express": "4.17.1",
@ -95,6 +96,7 @@
"ibm-watson": "6.1.1",
"js-beautify": "1.13.13",
"luxon": "2.0.2",
"mammoth": "^1.4.21",
"marked": "2.0.7",
"momentjs": "2.0.0",
"ms-rest-azure": "3.0.0",
@ -107,11 +109,13 @@
"pdf-extraction": "1.0.2",
"pdfkit": "^0.13.0",
"phone": "2.4.21",
"pizzip": "^3.0.6",
"pptxtemplater": "1.0.5",
"pragmatismo-io-framework": "1.0.20",
"prism-media": "1.3.1",
"public-ip": "4.0.4",
"puppeteer": "13.7.0",
"qrcode": "^1.5.0",
"qrcode-terminal": "0.12.0",
"readline": "1.3.0",
"reflect-metadata": "0.1.13",

View file

@ -51,6 +51,7 @@ const sgMail = require('@sendgrid/mail');
const PizZip = require("pizzip");
const Docxtemplater = require("docxtemplater");
var mammoth = require("mammoth");
const qrcode = require('qrcode');
/**
* Base services of conversation to be called by BASIC which
@ -569,12 +570,11 @@ export class DialogKeywords {
// Inline word document used as e-mail body.
if (typeof (body) === "object" )
{
const result = await mammoth.convertToHtml({buffer: body});
if (typeof (body) === "object") {
const result = await mammoth.convertToHtml({ buffer: body });
body = result.value;
}
return new Promise<any>((resolve, reject) => {
sgMail.setApiKey(emailToken);
const msg = {
@ -868,4 +868,11 @@ export class DialogKeywords {
await this.min.conversationalService.sendFile(this.min, step, mobile, url, caption);
}
}
public async getQRCode(text) {
const img = await qrcode.toDataURL(text);
const data = img.replace(/^data:image\/\w+;base64,/, "");
const buf = Buffer.from(data, "base64");
return buf;
}
}

View file

@ -349,8 +349,8 @@ export class GBMinService {
}
let provider = GBMinService.isChatAPI(req, res);
let id = provider ? req.body.messages[0].author.split('@')[0] : req.body.user.phone;
let senderName = provider ? req.body.messages[0].senderName : req.body.user.name;
let id;
let senderName;
let botId;
let text;
@ -365,10 +365,6 @@ export class GBMinService {
case "chatapi":
id = req.body.messages[0].author.split('@')[0];
senderName = req.body.messages[0].senderName;
text = req.body.messages[0].body;
if (req.body.ack) {
res.status(200);
res.end();
@ -380,6 +376,9 @@ export class GBMinService {
return; // Exit here.
}
id = req.body.messages[0].author.split('@')[0];
senderName = req.body.messages[0].senderName;
text = req.body.messages[0].body;
botId = req.params.botId;
if (botId === '[default]' || botId === undefined) {
botId = GBConfigService.get('BOT_ID');
@ -387,10 +386,6 @@ export class GBMinService {
break;
case "maytapi":
id = req.body.user.phone;
senderName = req.body.user.name;
text = req.body.message.text;
if (req.body.type !== 'message') {
res.status(200);
res.end();
@ -402,6 +397,10 @@ export class GBMinService {
return; // Exit here.
}
id = req.body.user.phone;
senderName = req.body.user.name;
text = req.body.message.text;
botId = WhatsappDirectLine.phones[req.body.phoneId];
break;
}

View file

@ -92,7 +92,7 @@ export class WhatsappDirectLine extends GBService {
this.whatsappServiceKey = whatsappServiceKey;
this.whatsappServiceNumber = whatsappServiceNumber;
this.whatsappServiceUrl = whatsappServiceUrl;
this.provider = whatsappServiceKey === "gbnative" ?
this.provider = whatsappServiceKey === "internal" ?
'GeneralBots' : whatsappServiceNumber.indexOf(';') > -1 ? 'maytapi' : 'chatapi';
}
@ -139,26 +139,34 @@ export class WhatsappDirectLine extends GBService {
await this.received(message, null);
}).bind(this));
client.on('qr', ((qr) => {
client.on('qr', (async (qr) => {
const adminNumber = this.min.core.getParam(this.min.instance, 'Bot Admin Number', null);
const adminEmail = this.min.core.getParam(this.min.instance, 'Bot Admin E-mail', null);
// Sends QR Code to boot bot admin.
const info = this.customClient.info;
const msg = `Please, scan QR Code with ${info.wid.user}(${info.pushname}) for bot ${this.botId}: ${qr}.`;
const msg = `Please, scan QR Code with for bot ${this.botId}.`;
GBLog.info(msg);
qrcode.generate(qr, { small: true, scale: 0.5 });
// While handling other bots uses boot instance of this class to send QR Codes.
if (this.botId !== GBServer.globals.minBoot.botId) {
GBServer.globals.minBoot.whatsAppDirectLine.sendMessage(msg);
GBServer.globals.minBoot.whatsAppDirectLine.sendMessage(adminNumber, qr);
const s = new DialogKeywords(null, null, null, null);
const qrBuf = await s.getQRCode(qr);
const gbaiName = `${this.min.botId}.gbai`;
const localName = Path.join('work', gbaiName, 'cache', `qr${GBAdminService.getRndReadableIdentifier()}.png`);
fs.writeFileSync(localName, qrBuf);
const url = urlJoin(
GBServer.globals.publicAddress,
this.min.botId,
'cache',
Path.basename(localName)
);
GBServer.globals.minBoot.whatsAppDirectLine.sendFileToDevice(adminNumber, url, Path.basename(localName), msg);
s.sendEmail(adminEmail, `Check your WhatsApp for bot ${this.botId}`, msg);
}
@ -263,6 +271,10 @@ export class WhatsappDirectLine extends GBService {
switch (this.provider) {
case 'GeneralBots':
message = req;
text = message.body;
from = message.from.split('@')[0];
fromName = message._data.notifyName;
break;
case 'chatapi':
@ -485,7 +497,10 @@ export class WhatsappDirectLine extends GBService {
const generatedConversationId = response.obj.conversationId;
WhatsappDirectLine.conversationIds[botId + from + group] = generatedConversationId;
WhatsappDirectLine.mobiles[generatedConversationId] = from;
if (this.provider === "GeneralBots") {
WhatsappDirectLine.chatIds[generatedConversationId] = message.from;
}
WhatsappDirectLine.mobiles[generatedConversationId] = from;
WhatsappDirectLine.usernames[from] = fromName;
WhatsappDirectLine.chatIds[generatedConversationId] = message.chatId;
@ -496,7 +511,7 @@ export class WhatsappDirectLine extends GBService {
this.inputMessage(client, conversationId, text, from, fromName, group);
}
} else {
} else {
GBLog.warn(`Inconsistencty found: Invalid agentMode on User Table: ${user.agentMode}`);
}
@ -738,7 +753,7 @@ export class WhatsappDirectLine extends GBService {
switch (this.provider) {
case 'GeneralBots':
this.customClient.sendMessage(to, msg);
this.customClient.sendMessage(to+'@c.us' , msg);
break;