From 3acda445c19053a580ecfa7837d1f856f337f91a Mon Sep 17 00:00:00 2001 From: Trystan4861 Date: Thu, 31 Aug 2023 15:30:06 +0200 Subject: [PATCH 01/15] Update Pruebalo --- packages/docs/src/routes/docs/example/index.mdx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/docs/src/routes/docs/example/index.mdx b/packages/docs/src/routes/docs/example/index.mdx index 0d0781d73..4d24ec957 100644 --- a/packages/docs/src/routes/docs/example/index.mdx +++ b/packages/docs/src/routes/docs/example/index.mdx @@ -2,7 +2,7 @@ import Navigation from '../../../components/widgets/Navigation' # Ejemplo -Si copias y pegas este codigo y tu entorno de trabajo cumple con todos los requesitos te debe funcionar abajo explico muy por encima +Si copias y pegas este código (y tu entorno de trabajo cumple con todos los [requesitos](/docs/requirements)) te debe funcionar, abajo explico muy por encima. ```js const { createBot, createProvider, createFlow, addKeyword } = require('@bot-whatsapp/bot') @@ -10,13 +10,12 @@ const { createBot, createProvider, createFlow, addKeyword } = require('@bot-what const WebWhatsappProvider = require('@bot-whatsapp/provider/web-whatsapp') const MockAdapter = require('@bot-whatsapp/database/mock') -const flowPrincipal = addKeyword(['hola', 'ole', 'alo']) +const flowPrincipal = addKeyword(['hola', 'alo']) .addAnswer(['Hola, bienvenido a mi tienda', '¿Como puedo ayudarte?']) .addAnswer(['Tengo:', 'Zapatos', 'Bolsos', 'etc ...']) /** - * Esta es la funcion importante es la que realmente inicia - * el chatbot. + * Esta es la función principal, ¡Importante, es la que realmente inicia el chatbot! */ const main = async () => { const adapterDB = new MockAdapter() @@ -34,7 +33,7 @@ main() ## Explicando -En esta parte solo estamos declarando las dependencias que vamos a utilizar. Si quieres saber a fondo cada una de las funciones te recomiendo pasarte por la seccion de **[conceptos](/docs/concepts)** +En esta parte sólo estamos declarando las dependencias que vamos a utilizar. Si quieres saber a fondo cada una de las funciones, te recomiendo pasarte por la seccion de **[conceptos](/docs/concepts)** ```js const { createBot, createProvider, createFlow, addKeyword } = require('@bot-whatsapp/bot') @@ -43,11 +42,11 @@ const WebWhatsappProvider = require('@bot-whatsapp/provider/web-whatsapp') const MockAdapter = require('@bot-whatsapp/database/mock') ``` -La siguiente seccion te declaramos las palabras claves que disparan un flujo de conversación. +En la siguiente sección declaramos las palabras claves que disparán un flujo de conversación. **Ejemplo**: -Si un usuario te escribe **👦hola** ó **👦alo** el bot respondera +Si un usuario te escribe cosas como **👦hola**, **👦Hola** o **👦alo** el bot responderá (es insensible a mayúsculas) **🤖Hola, bienvenido a mi tienda, ¿Como puedo ayudarte?** From c5b77c78ebd26ed59951940ed666a4e8a0ac9c95 Mon Sep 17 00:00:00 2001 From: Edgardorms <108375779+edgardorms@users.noreply.github.com> Date: Sun, 24 Sep 2023 19:15:18 -0300 Subject: [PATCH 02/15] Correccion index.mdx Correccion de errores --- packages/docs/src/routes/docs/state/index.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/docs/src/routes/docs/state/index.mdx b/packages/docs/src/routes/docs/state/index.mdx index fcc397de2..0a146c86e 100644 --- a/packages/docs/src/routes/docs/state/index.mdx +++ b/packages/docs/src/routes/docs/state/index.mdx @@ -3,7 +3,7 @@ import Navigation from '../../../components/widgets/Navigation' # State Algunas veces queremos mantener un `state` o `contexto` por usuario que nos escribe y poder compartir esta informacion con todos nuestros flujos. -Esto tambien funcion si usas `gotoFlow` +Esto tambien funciona si usas `gotoFlow` ```js @@ -39,7 +39,7 @@ Esto tambien funcion si usas `gotoFlow` ## GlobalState -De igual manera que el `state` anterior nosotros podemos usar `globalState` para tener un esta general de la app (NO es por usuario), esto es muy util si quieres ejemplo apagar o prener el bot +De igual manera que el `state` anterior nosotros podemos usar `globalState` para tener un esta general de la app (NO es por usuario), esto es muy util si quieres ejemplo apagar o prender el bot ```js From 3bcbb97979ccc144bc52e5edb5f74e3826909987 Mon Sep 17 00:00:00 2001 From: Jorge Chavarriaga Date: Thu, 9 Nov 2023 16:16:12 -0500 Subject: [PATCH 03/15] fix: se soluciona problemas con sendContacts para el provider meta se corrige el nombre phone a phones (plural) y se pasa por el map para recibir los phones. se adicionan todos los campos soportados por meta (addresses, emails, urls, org, etc) --- .husky/commit-msg | 0 .husky/pre-commit | 0 .husky/pre-push | 0 packages/provider/src/meta/index.js | 66 ++++++++++++++++++++--------- 4 files changed, 46 insertions(+), 20 deletions(-) mode change 100644 => 100755 .husky/commit-msg mode change 100644 => 100755 .husky/pre-commit mode change 100644 => 100755 .husky/pre-push diff --git a/.husky/commit-msg b/.husky/commit-msg old mode 100644 new mode 100755 diff --git a/.husky/pre-commit b/.husky/pre-commit old mode 100644 new mode 100755 diff --git a/.husky/pre-push b/.husky/pre-push old mode 100644 new mode 100755 diff --git a/packages/provider/src/meta/index.js b/packages/provider/src/meta/index.js index 393de9666..37337709a 100644 --- a/packages/provider/src/meta/index.js +++ b/packages/provider/src/meta/index.js @@ -394,14 +394,14 @@ class MetaProvider extends ProviderClass { text: 'text-string', }, { - type: "currency", + type: 'currency', currency: { - fallback_value: "$100.99", - code: "USD", - amount_1000: 100990 - } + fallback_value: '$100.99', + code: 'USD', + amount_1000: 100990, + }, }, - ] + ], }, { type: 'button', @@ -410,13 +410,13 @@ class MetaProvider extends ProviderClass { parameters: [ { type: 'payload', - payload: 'aGlzIHRoaXMgaXMgY29v' + payload: 'aGlzIHRoaXMgaXMgY29v', }, ], }, - ] + ], }, - }; + } return this.sendMessageMeta(body) } @@ -431,14 +431,40 @@ class MetaProvider extends ProviderClass { const parseContacts = contact.map((contact) => ({ name: { formatted_name: contact.name, + first_name: contact.first_name, + last_name: contact.last_name, + middle_name: contact.middle_name, + suffix: contact.suffix, + prefix: contact.prefix, }, - phone: [ - { - phone: contact.phone, - wa_id: contact.phone, - type: 'MOBILE', - }, - ], + birthday: contact.birthday, + phones: contact.phones.map((phone) => ({ + phone: phone.phone, + wa_id: phone.wa_id, + type: phone.type, + })), + emails: contact.emails.map((email) => ({ + email: email.email, + type: email.type, + })), + org: { + company: contact.company, + department: contact.department, + title: contact.title, + }, + urls: contact.urls.map((url) => ({ + url: url.url, + type: url.type, + })), + addresses: contact.addresses.map((address) => ({ + street: address.street, + city: address.city, + state: address.state, + zip: address.zip, + country: address.country, + country_code: address.counry_code, + type: address.type, + })), })) const body = { @@ -474,10 +500,10 @@ class MetaProvider extends ProviderClass { action: { name: 'catalog_message', parameters: { - "thumbnail_product_retailer_id": itemCatalogId, - } - } - } + thumbnail_product_retailer_id: itemCatalogId, + }, + }, + }, } return this.sendMessageMeta(body) } From abf89ff9d5f5ca8005fc738fda8d2fb56b044d31 Mon Sep 17 00:00:00 2001 From: Jorge Chavarriaga Date: Fri, 10 Nov 2023 09:21:31 -0500 Subject: [PATCH 04/15] feat: se adiciona la funcionalidad de enviar reacciones para el proveedor meta sendReaction se incluye la opcion de poder enviar reacciones a los mensajes al provider meta --- packages/provider/src/meta/index.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/provider/src/meta/index.js b/packages/provider/src/meta/index.js index 37337709a..b43be65c0 100644 --- a/packages/provider/src/meta/index.js +++ b/packages/provider/src/meta/index.js @@ -521,6 +521,24 @@ class MetaProvider extends ProviderClass { this.sendtext(number, message) } + + /** + * @param {*} number + * @param {*} react + */ + sendReaction = async (number, react) => { + const body = { + messaging_product: 'whatsapp', + recipient_type: 'individual', + to: number, + type: 'reaction', + reaction: { + message_id: react.message_id, + emoji: react.emoji, + }, + } + return this.sendMessageMeta(body) + } } module.exports = MetaProvider From 3f9942b53cd614c5a601f102d3f2ed52752e8acc Mon Sep 17 00:00:00 2001 From: Jorge Chavarriaga Date: Fri, 10 Nov 2023 10:10:13 -0500 Subject: [PATCH 05/15] feat: se adiciona la funcionalidad de enviar una ubicacion para el proveedor meta se incluye la opcion de poder enviar una ubicacion para el provider meta --- packages/provider/src/meta/index.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/provider/src/meta/index.js b/packages/provider/src/meta/index.js index b43be65c0..04ec245f7 100644 --- a/packages/provider/src/meta/index.js +++ b/packages/provider/src/meta/index.js @@ -523,6 +523,7 @@ class MetaProvider extends ProviderClass { } /** + * Enviar reacción a un mensaje * @param {*} number * @param {*} react */ @@ -539,6 +540,29 @@ class MetaProvider extends ProviderClass { } return this.sendMessageMeta(body) } + + /** + * Enviar Ubicación + * @param {*} longitude + * @param {*} latitude + * @param {*} name + * @param {*} address + * @returns + */ + sendLocation = async (number, localization) => { + const body = { + messaging_product: 'whatsapp', + to: number, + type: 'location', + location: { + longitude: localization.long_number, + latitude: localization.lat_number, + name: localization.location_name, + address: localization.location_address, + }, + } + return this.sendMessageMeta(body) + } } module.exports = MetaProvider From 82d05aaad93bdba63cde3c7625b3b64274081ffc Mon Sep 17 00:00:00 2001 From: Carlos Moran Date: Sat, 11 Nov 2023 12:26:00 -0500 Subject: [PATCH 06/15] fix(provider): :fire: Optimize incomingMsg function for efficient message handling --- packages/provider/package.json | 3 +- packages/provider/src/meta/index.js | 56 ++-- packages/provider/src/meta/package.json | 3 +- packages/provider/src/meta/server.js | 341 ++++++++++++------------ pnpm-lock.yaml | 140 +++------- 5 files changed, 236 insertions(+), 307 deletions(-) diff --git a/packages/provider/package.json b/packages/provider/package.json index c4c6b6805..988374f99 100644 --- a/packages/provider/package.json +++ b/packages/provider/package.json @@ -18,7 +18,8 @@ "follow-redirects": "^1.15.2", "qr-image": "^3.2.0", "rimraf": "^3.0.2", - "sharp": "^0.30.5" + "sharp": "^0.30.5", + "queue-promise": "^2.2.1" }, "exports": { "./mock": "./lib/mock/index.cjs", diff --git a/packages/provider/src/meta/index.js b/packages/provider/src/meta/index.js index 393de9666..95db85f0c 100644 --- a/packages/provider/src/meta/index.js +++ b/packages/provider/src/meta/index.js @@ -7,6 +7,7 @@ const { generalDownload } = require('../../common/download') const { convertAudio } = require('../utils/convertAudio') const MetaWebHookServer = require('./server') const URL = `https://graph.facebook.com` +const Queue = require('queue-promise') /** * ⚙️MetaProvider: Es un provedor que te ofrece enviar @@ -38,6 +39,12 @@ class MetaProvider extends ProviderClass { for (const { event, func } of listEvents) { this.metHook.on(event, func) } + + this.queue = new Queue({ + concurrent: 1, // Cantidad de tareas que se ejecutarán en paralelo + interval: 100, // Intervalo entre tareas + start: true, // Iniciar la cola automáticamente + }) } /** @@ -63,11 +70,22 @@ class MetaProvider extends ProviderClass { ] /** - * Enviar directo a META - * @param {*} body - * @returns + * Sends a message with metadata to the API. + * + * @param {Object} body - The body of the message. + * @return {Promise} A Promise that resolves when the message is sent. */ - sendMessageMeta = async (body) => { + sendMessageMeta(body) { + return this.queue.add(() => this.sendMessageToApi(body)) + } + + /** + * Sends a message to the API. + * + * @param {Object} body - The body of the message. + * @return {Object} The response data from the API. + */ + async sendMessageToApi(body) { try { const response = await axios.post(`${URL}/${this.version}/${this.numberId}/messages`, body, { headers: { @@ -76,8 +94,8 @@ class MetaProvider extends ProviderClass { }) return response.data } catch (error) { - console.log(error) - return Promise.resolve(error) + console.error(error) + throw error } } @@ -394,14 +412,14 @@ class MetaProvider extends ProviderClass { text: 'text-string', }, { - type: "currency", + type: 'currency', currency: { - fallback_value: "$100.99", - code: "USD", - amount_1000: 100990 - } + fallback_value: '$100.99', + code: 'USD', + amount_1000: 100990, + }, }, - ] + ], }, { type: 'button', @@ -410,13 +428,13 @@ class MetaProvider extends ProviderClass { parameters: [ { type: 'payload', - payload: 'aGlzIHRoaXMgaXMgY29v' + payload: 'aGlzIHRoaXMgaXMgY29v', }, ], }, - ] + ], }, - }; + } return this.sendMessageMeta(body) } @@ -474,10 +492,10 @@ class MetaProvider extends ProviderClass { action: { name: 'catalog_message', parameters: { - "thumbnail_product_retailer_id": itemCatalogId, - } - } - } + thumbnail_product_retailer_id: itemCatalogId, + }, + }, + }, } return this.sendMessageMeta(body) } diff --git a/packages/provider/src/meta/package.json b/packages/provider/src/meta/package.json index d817dcd94..324215dce 100644 --- a/packages/provider/src/meta/package.json +++ b/packages/provider/src/meta/package.json @@ -1,5 +1,6 @@ { "dependencies": { - "form-data": "^4.0.0" + "form-data": "^4.0.0", + "queue-promise": "^2.2.1" } } diff --git a/packages/provider/src/meta/server.js b/packages/provider/src/meta/server.js index ed12e7855..2502da3cf 100644 --- a/packages/provider/src/meta/server.js +++ b/packages/provider/src/meta/server.js @@ -3,6 +3,7 @@ const polka = require('polka') const { urlencoded, json } = require('body-parser') const { generateRefprovider } = require('../../common/hash') const { getMediaUrl } = require('./utils') +const Queue = require('queue-promise') class MetaWebHookServer extends EventEmitter { constructor(jwtToken, numberId, version, token, metaPort = 3000) { @@ -14,6 +15,12 @@ class MetaWebHookServer extends EventEmitter { this.numberId = numberId this.version = version this.metaServer = this.buildHTTPServer() + + this.messageQueue = new Queue({ + concurrent: 1, // Procesa un mensaje a la vez + interval: 50, // Intervalo de 100 milisegundos entre mensajes + start: true, // La cola empieza a procesar tareas inmediatamente + }) } /** @@ -33,187 +40,169 @@ class MetaWebHookServer extends EventEmitter { return } - const [message] = messages - const [contact] = contacts - const to = body.entry[0].changes[0].value?.metadata?.display_phone_number - const pushName = contact?.profile?.name - - if (message.type === 'text') { - const body = message.text?.body - const responseObj = { - type: message.type, - from: message.from, - to, - body, - pushName, - } - this.emit('message', responseObj) - } - - if (message.type === 'interactive') { - const body = message.interactive?.button_reply?.title || message.interactive?.list_reply?.id - const title_button_reply = message.interactive?.button_reply?.title - const title_list_reply = message.interactive?.list_reply?.title - const responseObj = { - type: 'interactive', - from: message.from, - to, - body, - title_button_reply, - title_list_reply, - pushName, - } - this.emit('message', responseObj) - } - - if (message.type === 'button') { - const body = message.button?.text - const payload = message.button?.payload - const title_button_reply = message.button?.payload - const responseObj = { - type: 'button', - from: message.from, - to, - body, - payload, - title_button_reply, - pushName, - } - this.emit('message', responseObj) - } - - if (message.type === 'image') { - const body = generateRefprovider('_event_media_') - const idUrl = message.image?.id - const resolvedUrl = await getMediaUrl(this.version, idUrl, this.numberId, this.jwtToken) - const responseObj = { - type: message.type, - from: message.from, - url: resolvedUrl, - to, - body, - pushName, + messages.forEach(async (message) => { + const [contact] = contacts + const to = body.entry[0].changes[0].value?.metadata?.display_phone_number + const pushName = contact?.profile?.name + let responseObj + + switch (message.type) { + case 'text': { + responseObj = { + type: message.type, + from: message.from, + to, + body: message.text?.body, + pushName, + } + break + } + case 'interactive': { + responseObj = { + type: 'interactive', + from: message.from, + to, + body: message.interactive?.button_reply?.title || message.interactive?.list_reply?.id, + title_button_reply: message.interactive?.button_reply?.title, + title_list_reply: message.interactive?.list_reply?.title, + pushName, + } + break + } + case 'button': { + responseObj = { + type: 'button', + from: message.from, + to, + body: message.button?.text, + payload: message.button?.payload, + title_button_reply: message.button?.payload, + pushName, + } + break + } + case 'image': { + const imageUrl = await getMediaUrl(this.version, message.image?.id, this.numberId, this.jwtToken) + responseObj = { + type: message.type, + from: message.from, + url: imageUrl, + to, + body: generateRefprovider('_event_media_'), + pushName, + } + break + } + case 'document': { + const documentUrl = await getMediaUrl( + this.version, + message.document?.id, + this.numberId, + this.jwtToken + ) + responseObj = { + type: message.type, + from: message.from, + url: documentUrl, + to, + body: generateRefprovider('_event_document_'), + pushName, + } + break + } + case 'video': { + const videoUrl = await getMediaUrl(this.version, message.video?.id, this.numberId, this.jwtToken) + responseObj = { + type: message.type, + from: message.from, + url: videoUrl, + to, + body: generateRefprovider('_event_media_'), + pushName, + } + break + } + case 'location': { + responseObj = { + type: message.type, + from: message.from, + to, + latitude: message.location.latitude, + longitude: message.location.longitude, + body: generateRefprovider('_event_location_'), + pushName, + } + break + } + case 'audio': { + const audioUrl = await getMediaUrl(this.version, message.audio?.id, this.numberId, this.jwtToken) + responseObj = { + type: message.type, + from: message.from, + url: audioUrl, + to, + body: generateRefprovider('_event_audio_'), + pushName, + } + break + } + case 'sticker': { + responseObj = { + type: message.type, + from: message.from, + to, + id: message.sticker.id, + body: generateRefprovider('_event_media_'), + pushName, + } + break + } + case 'contacts': { + responseObj = { + type: message.type, + from: message.from, + contacts: [ + { + name: message.contacts[0].name, + phones: message.contacts[0].phones, + }, + ], + to, + body: generateRefprovider('_event_contacts_'), + pushName, + } + break + } + case 'order': { + responseObj = { + type: message.type, + from: message.from, + to, + order: { + catalog_id: message.order.catalog_id, + product_items: message.order.product_items, + }, + body: generateRefprovider('_event_order_'), + pushName, + } + break + } + default: + // Lógica para manejar tipos de mensajes no reconocidos + break } - this.emit('message', responseObj) - } - - if (message.type === 'document') { - const body = generateRefprovider('_event_document_') - const idUrl = message.document?.id - const resolvedUrl = await getMediaUrl(this.version, idUrl, this.numberId, this.jwtToken) - const responseObj = { - type: message.type, - from: message.from, - url: resolvedUrl, // Utilizar el valor resuelto de la promesa - to, - body, - pushName, - } - - this.emit('message', responseObj) - } - - if (message.type === 'video') { - const body = generateRefprovider('_event_media_') - const idUrl = message.video?.id - - const resolvedUrl = await getMediaUrl(this.version, idUrl, this.numberId, this.jwtToken) - - const responseObj = { - type: message.type, - from: message.from, - url: resolvedUrl, // Utilizar el valor resuelto de la promesa - to, - body, - pushName, - } - - this.emit('message', responseObj) - } - - if (message.type === 'location') { - const body = generateRefprovider('_event_location_') - - const responseObj = { - type: message.type, - from: message.from, - to, - latitude: message.location.latitude, - longitude: message.location.longitude, - body, - pushName, - } - - this.emit('message', responseObj) - } - - if (message.type === 'audio') { - const body = generateRefprovider('_event_audio_') - const idUrl = message.audio?.id - const resolvedUrl = await getMediaUrl(this.version, idUrl, this.numberId, this.jwtToken) - const responseObj = { - type: message.type, - from: message.from, - url: resolvedUrl, // Utilizar el valor resuelto de la promesa - to, - body, - pushName, - } - - this.emit('message', responseObj) - } - - if (message.type === 'sticker') { - const body = generateRefprovider('_event_media_') - - const responseObj = { - type: message.type, - from: message.from, - to, - id: message.sticker.id, - body, - pushName, - } - - this.emit('message', responseObj) - } - - if (message.type === 'contacts') { - const body = generateRefprovider('_event_contacts_') - - const responseObj = { - type: message.type, - from: message.from, - contacts: [{ name: message.contacts[0].name, phones: message.contacts[0].phones }], - to, - body, - pushName, - } - - this.emit('message', responseObj) - } - - if (message.type === 'order') { - const body = generateRefprovider('_event_order_') - - const responseObj = { - type: message.type, - from: message.from, - to, - order: { - catalog_id: message.order.catalog_id, - product_items: message.order.product_items, - }, - body, - pushName, + if (responseObj) { + this.messageQueue.enqueue(() => this.processMessage(responseObj)) } + }) - this.emit('message', responseObj) - } + res.statusCode = 200 + res.end('Messages enqueued') + } - const json = JSON.stringify({ body }) - res.end(json) + processMessage = (message) => { + this.emit('message', message) } /** diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d7f4bf1df..f0becbf6e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -354,6 +354,9 @@ importers: qr-image: specifier: ^3.2.0 version: 3.2.0 + queue-promise: + specifier: ^2.2.1 + version: 2.2.1 rimraf: specifier: ^3.0.2 version: 3.0.2 @@ -845,7 +848,7 @@ packages: dependencies: '@aws-sdk/client-cognito-identity': 3.437.0 '@aws-sdk/types': 3.433.0 - '@smithy/property-provider': 2.0.5 + '@smithy/property-provider': 2.0.13 '@smithy/types': 2.4.0 tslib: 2.6.2 transitivePeerDependencies: @@ -862,7 +865,7 @@ packages: requiresBuild: true dependencies: '@aws-sdk/types': 3.433.0 - '@smithy/property-provider': 2.0.5 + '@smithy/property-provider': 2.0.13 '@smithy/types': 2.4.0 tslib: 2.6.2 dev: false @@ -879,7 +882,7 @@ packages: '@aws-sdk/types': 3.433.0 '@smithy/fetch-http-handler': 2.2.4 '@smithy/node-http-handler': 2.1.8 - '@smithy/property-provider': 2.0.5 + '@smithy/property-provider': 2.0.13 '@smithy/protocol-http': 3.0.8 '@smithy/smithy-client': 2.1.12 '@smithy/types': 2.4.0 @@ -901,8 +904,8 @@ packages: '@aws-sdk/credential-provider-sso': 3.437.0 '@aws-sdk/credential-provider-web-identity': 3.433.0 '@aws-sdk/types': 3.433.0 - '@smithy/credential-provider-imds': 2.0.5 - '@smithy/property-provider': 2.0.5 + '@smithy/credential-provider-imds': 2.0.18 + '@smithy/property-provider': 2.0.13 '@smithy/shared-ini-file-loader': 2.2.2 '@smithy/types': 2.4.0 tslib: 2.6.2 @@ -925,8 +928,8 @@ packages: '@aws-sdk/credential-provider-sso': 3.437.0 '@aws-sdk/credential-provider-web-identity': 3.433.0 '@aws-sdk/types': 3.433.0 - '@smithy/credential-provider-imds': 2.0.5 - '@smithy/property-provider': 2.0.5 + '@smithy/credential-provider-imds': 2.0.18 + '@smithy/property-provider': 2.0.13 '@smithy/shared-ini-file-loader': 2.2.2 '@smithy/types': 2.4.0 tslib: 2.6.2 @@ -944,7 +947,7 @@ packages: requiresBuild: true dependencies: '@aws-sdk/types': 3.433.0 - '@smithy/property-provider': 2.0.5 + '@smithy/property-provider': 2.0.13 '@smithy/shared-ini-file-loader': 2.2.2 '@smithy/types': 2.4.0 tslib: 2.6.2 @@ -962,7 +965,7 @@ packages: '@aws-sdk/client-sso': 3.437.0 '@aws-sdk/token-providers': 3.437.0 '@aws-sdk/types': 3.433.0 - '@smithy/property-provider': 2.0.5 + '@smithy/property-provider': 2.0.13 '@smithy/shared-ini-file-loader': 2.2.2 '@smithy/types': 2.4.0 tslib: 2.6.2 @@ -980,7 +983,7 @@ packages: requiresBuild: true dependencies: '@aws-sdk/types': 3.433.0 - '@smithy/property-provider': 2.0.5 + '@smithy/property-provider': 2.0.13 '@smithy/types': 2.4.0 tslib: 2.6.2 dev: false @@ -1006,8 +1009,8 @@ packages: '@aws-sdk/credential-provider-sso': 3.437.0 '@aws-sdk/credential-provider-web-identity': 3.433.0 '@aws-sdk/types': 3.433.0 - '@smithy/credential-provider-imds': 2.0.5 - '@smithy/property-provider': 2.0.5 + '@smithy/credential-provider-imds': 2.0.18 + '@smithy/property-provider': 2.0.13 '@smithy/types': 2.4.0 tslib: 2.6.2 transitivePeerDependencies: @@ -1083,7 +1086,7 @@ packages: requiresBuild: true dependencies: '@aws-sdk/types': 3.433.0 - '@smithy/property-provider': 2.0.5 + '@smithy/property-provider': 2.0.13 '@smithy/protocol-http': 3.0.8 '@smithy/signature-v4': 2.0.12 '@smithy/types': 2.4.0 @@ -1154,7 +1157,7 @@ packages: '@smithy/middleware-stack': 2.0.6 '@smithy/node-config-provider': 2.1.3 '@smithy/node-http-handler': 2.1.8 - '@smithy/property-provider': 2.0.5 + '@smithy/property-provider': 2.0.13 '@smithy/protocol-http': 3.0.8 '@smithy/shared-ini-file-loader': 2.2.2 '@smithy/smithy-client': 2.1.12 @@ -4347,22 +4350,6 @@ packages: dev: false optional: true - /@smithy/credential-provider-imds@2.0.5: - resolution: - { - integrity: sha512-KFcf/e0meFkQNyteJ65f1G19sgUEY1e5zL7hyAEUPz2SEfBmC9B37WyRq87G3MEEsvmAWwCRu7nFFYUKtR3svQ==, - } - engines: { node: '>=14.0.0' } - requiresBuild: true - dependencies: - '@smithy/node-config-provider': 2.0.5 - '@smithy/property-provider': 2.0.5 - '@smithy/types': 2.4.0 - '@smithy/url-parser': 2.0.5 - tslib: 2.6.2 - dev: false - optional: true - /@smithy/eventstream-codec@2.0.12: resolution: { @@ -4508,21 +4495,6 @@ packages: dev: false optional: true - /@smithy/node-config-provider@2.0.5: - resolution: - { - integrity: sha512-LRtjV9WkhONe2lVy+ipB/l1GX60ybzBmFyeRUoLUXWKdnZ3o81jsnbKzMK8hKq8eFSWPk+Lmyx6ZzCQabGeLxg==, - } - engines: { node: '>=14.0.0' } - requiresBuild: true - dependencies: - '@smithy/property-provider': 2.0.5 - '@smithy/shared-ini-file-loader': 2.0.5 - '@smithy/types': 2.4.0 - tslib: 2.6.2 - dev: false - optional: true - /@smithy/node-config-provider@2.1.3: resolution: { @@ -4567,19 +4539,6 @@ packages: dev: false optional: true - /@smithy/property-provider@2.0.5: - resolution: - { - integrity: sha512-cAFSUhX6aiHcmpWfrCLKvwBtgN1F6A0N8qY/8yeSi0LRLmhGqsY1/YTxFE185MCVzYbqBGXVr9TBv4RUcIV4rA==, - } - engines: { node: '>=14.0.0' } - requiresBuild: true - dependencies: - '@smithy/types': 2.4.0 - tslib: 2.6.2 - dev: false - optional: true - /@smithy/protocol-http@3.0.8: resolution: { @@ -4620,19 +4579,6 @@ packages: dev: false optional: true - /@smithy/querystring-parser@2.0.5: - resolution: - { - integrity: sha512-C2stCULH0r54KBksv3AWcN8CLS3u9+WsEW8nBrvctrJ5rQTNa1waHkffpVaiKvcW2nP0aIMBPCobD/kYf/q9mA==, - } - engines: { node: '>=14.0.0' } - requiresBuild: true - dependencies: - '@smithy/types': 2.4.0 - tslib: 2.6.2 - dev: false - optional: true - /@smithy/service-error-classification@2.0.5: resolution: { @@ -4645,19 +4591,6 @@ packages: dev: false optional: true - /@smithy/shared-ini-file-loader@2.0.5: - resolution: - { - integrity: sha512-Mvtk6FwMtfbKRC4YuSsIqRYp9WTxsSUJVVo2djgyhcacKGMqicHDWSAmgy3sDrKv+G/G6xTZCPwm6pJARtdxVg==, - } - engines: { node: '>=14.0.0' } - requiresBuild: true - dependencies: - '@smithy/types': 2.4.0 - tslib: 2.6.2 - dev: false - optional: true - /@smithy/shared-ini-file-loader@2.2.2: resolution: { @@ -4730,19 +4663,6 @@ packages: dev: false optional: true - /@smithy/url-parser@2.0.5: - resolution: - { - integrity: sha512-OdMBvZhpckQSkugCXNJQCvqJ71wE7Ftxce92UOQLQ9pwF6hoS5PLL7wEfpnuEXtStzBqJYkzu1C1ZfjuFGOXAA==, - } - requiresBuild: true - dependencies: - '@smithy/querystring-parser': 2.0.5 - '@smithy/types': 2.4.0 - tslib: 2.6.2 - dev: false - optional: true - /@smithy/util-base64@2.0.0: resolution: { @@ -5388,6 +5308,7 @@ packages: { integrity: sha512-dP7f3LdZIysZnmvP3ANJYTSwg+wLLl8p7RqniVlV7j+oXSXAbt9h0WIBFmJy5inWZoX9wZN6eXx+YXd9Rh3RBA==, } + dev: true /@types/node@20.8.9: resolution: @@ -5396,7 +5317,6 @@ packages: } dependencies: undici-types: 5.26.5 - dev: true /@types/normalize-package-data@2.4.1: resolution: @@ -5545,7 +5465,7 @@ packages: integrity: sha512-FtQu10RWgn3D9U4aazdwIE2yzphmTJREDqNdODHrbrZmmMqI0vMheC/6NE/J1Yveaj8H+ela+YwWTjq5PGmuhA==, } dependencies: - '@types/node': 20.5.7 + '@types/node': 20.8.9 '@types/webidl-conversions': 7.0.0 dev: false @@ -7440,7 +7360,7 @@ packages: integrity: sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==, } dependencies: - function-bind: 1.1.1 + function-bind: 1.1.2 get-intrinsic: 1.2.1 dev: true @@ -11994,13 +11914,6 @@ packages: dev: true optional: true - /function-bind@1.1.1: - resolution: - { - integrity: sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==, - } - dev: true - /function-bind@1.1.2: resolution: { @@ -12106,7 +12019,7 @@ packages: integrity: sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==, } dependencies: - function-bind: 1.1.1 + function-bind: 1.1.2 has: 1.0.3 has-proto: 1.0.1 has-symbols: 1.0.3 @@ -12918,7 +12831,7 @@ packages: } engines: { node: '>= 0.4.0' } dependencies: - function-bind: 1.1.1 + function-bind: 1.1.2 dev: true /hasbin@1.2.3: @@ -19443,6 +19356,14 @@ packages: } dev: true + /queue-promise@2.2.1: + resolution: + { + integrity: sha512-C3eyRwLF9m6dPV4MtqMVFX+Xmc7keZ9Ievm3jJ/wWM5t3uVbFnGsJXwpYzZ4LaIEcX9bss/mdaKzyrO6xheRuA==, + } + engines: { node: '>=8.12.0' } + dev: false + /quick-lru@4.0.1: resolution: { @@ -22703,7 +22624,6 @@ packages: { integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==, } - dev: true /undici@5.14.0: resolution: From 9e31174148d552311ef0ec0898885bf9c825c151 Mon Sep 17 00:00:00 2001 From: Ignacio Estevo Date: Sun, 12 Nov 2023 14:45:52 -0300 Subject: [PATCH 07/15] Added option to not push private keys DialogFlow now allows not to push private keys to repo, instead the user can add an environment variable GOOGLE_KEY_JSON to read them from there --- packages/contexts/src/dialogflow-cx/dialogflow-cx.class.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/contexts/src/dialogflow-cx/dialogflow-cx.class.js b/packages/contexts/src/dialogflow-cx/dialogflow-cx.class.js index 6be4f9e40..efa986b6e 100644 --- a/packages/contexts/src/dialogflow-cx/dialogflow-cx.class.js +++ b/packages/contexts/src/dialogflow-cx/dialogflow-cx.class.js @@ -7,8 +7,12 @@ const { join } = require('path') * Necesita extender de core.class * handleMsg(messageInComming) // const { body, from } = messageInComming */ +//Darle al usuario la opcion de no publicar sus claves de Google y pasarlas como variable de entorno +let GOOGLE_ACCOUNT_PATH = join(process.cwd(), 'google-key.json'); -const GOOGLE_ACCOUNT_PATH = join(process.cwd(), 'google-key.json') +if (!fs.existsSync(googleKeyFilePath)) { + GOOGLE_ACCOUNT_PATH = JSON.parse(process.env.GOOGLE_KEY_JSON); +} class DialogFlowCXContext extends CoreClass { // Opciones del usuario From 6caee2653361b9ea952d273641f1186d1851dbf5 Mon Sep 17 00:00:00 2001 From: Ignacio Estevo Date: Sun, 12 Nov 2023 17:57:44 +0000 Subject: [PATCH 08/15] Added file checker --- .../src/dialogflow-cx/dialogflow-cx.class.js | 40 ++++++++----------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/packages/contexts/src/dialogflow-cx/dialogflow-cx.class.js b/packages/contexts/src/dialogflow-cx/dialogflow-cx.class.js index efa986b6e..9f42ef462 100644 --- a/packages/contexts/src/dialogflow-cx/dialogflow-cx.class.js +++ b/packages/contexts/src/dialogflow-cx/dialogflow-cx.class.js @@ -3,17 +3,6 @@ const { SessionsClient } = require('@google-cloud/dialogflow-cx').v3beta1 const { existsSync, readFileSync } = require('fs') const { join } = require('path') -/** - * Necesita extender de core.class - * handleMsg(messageInComming) // const { body, from } = messageInComming - */ -//Darle al usuario la opcion de no publicar sus claves de Google y pasarlas como variable de entorno -let GOOGLE_ACCOUNT_PATH = join(process.cwd(), 'google-key.json'); - -if (!fs.existsSync(googleKeyFilePath)) { - GOOGLE_ACCOUNT_PATH = JSON.parse(process.env.GOOGLE_KEY_JSON); -} - class DialogFlowCXContext extends CoreClass { // Opciones del usuario optionsDX = { @@ -22,7 +11,6 @@ class DialogFlowCXContext extends CoreClass { agentId: '', } projectId = null - configuration = null sessionClient = null constructor(_database, _provider, _optionsDX = {}) { @@ -35,27 +23,33 @@ class DialogFlowCXContext extends CoreClass { * Verificar conexión con servicio de DialogFlow */ init = () => { - if (!existsSync(GOOGLE_ACCOUNT_PATH)) { - console.log(`[ERROR]: No se encontro ${GOOGLE_ACCOUNT_PATH}`) - /** - * Emitir evento de error para que se mueste por consola dicinedo que no tiene el json - * */ + let credentials; + const googleKeyFilePath = join(process.cwd(), 'google-key.json'); + + if (existsSync(googleKeyFilePath)) { + const rawJson = readFileSync(googleKeyFilePath, 'utf-8'); + credentials = JSON.parse(rawJson); + } else if (process.env.GOOGLE_KEY_JSON) { + credentials = JSON.parse(process.env.GOOGLE_KEY_JSON); + } else { + throw new Error('Google key configuration not found'); } - if (!this.optionsDX.location.length) throw new Error('LOCATION_NO_ENCONTRADO') - if (!this.optionsDX.agentId.length) throw new Error('AGENTID_NO_ENCONTRADO') + if (!this.optionsDX.location.length) throw new Error('LOCATION_NO_ENCONTRADO'); + if (!this.optionsDX.agentId.length) throw new Error('AGENTID_NO_ENCONTRADO'); - const rawJson = readFileSync(GOOGLE_ACCOUNT_PATH, 'utf-8') - const { project_id, private_key, client_email } = JSON.parse(rawJson) + const { project_id, private_key, client_email } = credentials; - this.projectId = project_id + this.projectId = project_id; this.sessionClient = new SessionsClient({ credentials: { private_key, client_email }, apiEndpoint: `${this.optionsDX.location}-dialogflow.googleapis.com`, - }) + }); } + + /** * GLOSSARY.md * @param {*} messageCtxInComming From 77878754a9acf582d05a7961f4a3db850920a9df Mon Sep 17 00:00:00 2001 From: Leifer Mendez Date: Fri, 17 Nov 2023 10:13:47 +0100 Subject: [PATCH 09/15] perf(hook): before pnpm audit --- ...case.test.js => 0.0.0-flow-simple.test.js} | 21 +-- __test__/0.0.1-case.test.js | 111 -------------- __test__/0.0.1-flow-events.test.js | 111 ++++++++++++++ __test__/0.0.2-case.test.js | 138 ++++++++++++------ __test__/0.1.0-case.test.js | 20 +-- package.json | 2 +- 6 files changed, 228 insertions(+), 175 deletions(-) rename __test__/{0.0.0-case.test.js => 0.0.0-flow-simple.test.js} (63%) delete mode 100644 __test__/0.0.1-case.test.js create mode 100644 __test__/0.0.1-flow-events.test.js diff --git a/__test__/0.0.0-case.test.js b/__test__/0.0.0-flow-simple.test.js similarity index 63% rename from __test__/0.0.0-case.test.js rename to __test__/0.0.0-flow-simple.test.js index cb6a9529a..d530b6274 100644 --- a/__test__/0.0.0-case.test.js +++ b/__test__/0.0.0-flow-simple.test.js @@ -3,18 +3,18 @@ const assert = require('uvu/assert') const { addKeyword, createBot, createFlow } = require('../packages/bot/index') const { setup, clear, delay } = require('../__mocks__/env') -const suiteCase = suite('Flujo: Simple') +const testSuite = suite('Flujo: Simple') -suiteCase.before.each(setup) -suiteCase.after.each(clear) +testSuite.before.each(setup) +testSuite.after.each(clear) -suiteCase(`Responder a "hola"`, async ({ database, provider }) => { - const flow = addKeyword('hola').addAnswer('Buenas!').addAnswer('Como vamos!') +testSuite(`Responder a "hola"`, async ({ database, provider }) => { + const helloFlow = addKeyword('hola').addAnswer('Buenas!').addAnswer('Como vamos!') await createBot({ database, provider, - flow: createFlow([flow]), + flow: createFlow([helloFlow]), }) await provider.delaySendMessage(0, 'message', { @@ -23,18 +23,19 @@ suiteCase(`Responder a "hola"`, async ({ database, provider }) => { }) await delay(50) + assert.is('Buenas!', database.listHistory[0].answer) assert.is('Como vamos!', database.listHistory[1].answer) assert.is(undefined, database.listHistory[2]) }) -suiteCase(`NO reponder a "pepe"`, async ({ database, provider }) => { - const flow = addKeyword('hola').addAnswer('Buenas!').addAnswer('Como vamos!') +testSuite(`NO responder a "pepe"`, async ({ database, provider }) => { + const helloFlow = addKeyword('hola').addAnswer('Buenas!').addAnswer('Como vamos!') await createBot({ database, provider, - flow: createFlow([flow]), + flow: createFlow([helloFlow]), }) await provider.delaySendMessage(0, 'message', { @@ -48,4 +49,4 @@ suiteCase(`NO reponder a "pepe"`, async ({ database, provider }) => { assert.is(undefined, database.listHistory[1]) }) -suiteCase.run() +testSuite.run() diff --git a/__test__/0.0.1-case.test.js b/__test__/0.0.1-case.test.js deleted file mode 100644 index 83695cf82..000000000 --- a/__test__/0.0.1-case.test.js +++ /dev/null @@ -1,111 +0,0 @@ -const { suite } = require('uvu') -const assert = require('uvu/assert') -const { addKeyword, createBot, createFlow, EVENTS } = require('../packages/bot/index') -const { setup, clear, delay } = require('../__mocks__/env') - -const suiteCase = suite('Flujo: enviando eventos') - -suiteCase.before.each(setup) -suiteCase.after.each(clear) - -suiteCase(`Responder a "EVENTS.LOCATION"`, async ({ database, provider }) => { - const flow = addKeyword(EVENTS.LOCATION).addAnswer('Gracias por tu location') - - await createBot({ - database, - provider, - flow: createFlow([flow]), - }) - - await provider.delaySendMessage(0, 'message', { - from: '000', - body: '_event_location__f405d946-cf07-uutt-l7e0-b6d475bc7f81', - }) - - await delay(200) - const getHistory = database.listHistory.map((i) => i.answer) - assert.is('Gracias por tu location', getHistory[0]) - assert.is(undefined, getHistory[1]) -}) - -suiteCase(`Responder a "EVENTS.DOCUMENT"`, async ({ database, provider }) => { - const flow = addKeyword(EVENTS.DOCUMENT).addAnswer('Gracias por tu documento') - - createBot({ - database, - provider, - flow: createFlow([flow]), - }) - - await provider.delaySendMessage(0, 'message', { - from: '000', - body: '_event_document__f405d946-cf07-uutt-l7e0-b6d475bc7f81', - }) - - await delay(200) - const getHistory = database.listHistory.map((i) => i.answer) - assert.is('Gracias por tu documento', getHistory[0]) - assert.is(undefined, getHistory[1]) -}) - -suiteCase(`Responder a "EVENTS.WELCOME"`, async ({ database, provider }) => { - const flow = addKeyword(EVENTS.WELCOME).addAnswer('Bienvenido!') - - await createBot({ - database, - provider, - flow: createFlow([flow]), - }) - - await provider.delaySendMessage(0, 'message', { - from: '000', - body: '_event_welcome__f405d946-cf07-uutt-l7e0-b6d475bc7f81', - }) - - await delay(200) - const getHistory = database.listHistory.map((i) => i.answer) - assert.is('Bienvenido!', getHistory[0]) - assert.is(undefined, getHistory[1]) -}) - -suiteCase(`Responder a "EVENTS.MEDIA"`, async ({ database, provider }) => { - const flow = addKeyword(EVENTS.MEDIA).addAnswer('gracias por la imagen o video!') - - await createBot({ - database, - provider, - flow: createFlow([flow]), - }) - - await provider.delaySendMessage(0, 'message', { - from: '000', - body: '_event_media__f405d946-cf07-uutt-l7e0-b6d475bc7f81', - }) - - await delay(200) - const getHistory = database.listHistory.map((i) => i.answer) - assert.is('gracias por la imagen o video!', getHistory[0]) - assert.is(undefined, getHistory[1]) -}) - -suiteCase(`Responder a "EVENTS.VOICE_NOTE"`, async ({ database, provider }) => { - const flow = addKeyword(EVENTS.VOICE_NOTE).addAnswer('gracias por la nota de voz!') - - await createBot({ - database, - provider, - flow: createFlow([flow]), - }) - - await provider.delaySendMessage(0, 'message', { - from: '000', - body: '_event_voice_note__f405d946-cf07-uutt-l7e0-b6d475bc7f81', - }) - - await delay(200) - const getHistory = database.listHistory.map((i) => i.answer) - assert.is('gracias por la nota de voz!', getHistory[0]) - assert.is(undefined, getHistory[1]) -}) - -suiteCase.run() diff --git a/__test__/0.0.1-flow-events.test.js b/__test__/0.0.1-flow-events.test.js new file mode 100644 index 000000000..2154ed153 --- /dev/null +++ b/__test__/0.0.1-flow-events.test.js @@ -0,0 +1,111 @@ +const { suite } = require('uvu') +const assert = require('uvu/assert') +const { addKeyword, createBot, createFlow, EVENTS } = require('../packages/bot/index') +const { setup, clear, delay } = require('../__mocks__/env') + +const testSuite = suite('Flujo: enviando eventos') + +testSuite.before.each(setup) +testSuite.after.each(clear) + +testSuite(`Responder a "EVENTS.LOCATION"`, async ({ database, provider }) => { + const locationFlow = addKeyword(EVENTS.LOCATION).addAnswer('Gracias por tu location') + + await createBot({ + database, + provider, + flow: createFlow([locationFlow]), + }) + + await provider.delaySendMessage(0, 'message', { + from: '000', + body: '_event_location__f405d946-cf07-uutt-l7e0-b6d475bc7f81', + }) + + await delay(200) + const history = database.listHistory.map((item) => item.answer) + assert.is('Gracias por tu location', history[0]) + assert.is(undefined, history[1]) +}) + +testSuite(`Responder a "EVENTS.DOCUMENT"`, async ({ database, provider }) => { + const documentFlow = addKeyword(EVENTS.DOCUMENT).addAnswer('Gracias por tu documento') + + createBot({ + database, + provider, + flow: createFlow([documentFlow]), + }) + + await provider.delaySendMessage(0, 'message', { + from: '000', + body: '_event_document__f405d946-cf07-uutt-l7e0-b6d475bc7f81', + }) + + await delay(200) + const history = database.listHistory.map((item) => item.answer) + assert.is('Gracias por tu documento', history[0]) + assert.is(undefined, history[1]) +}) + +testSuite(`Responder a "EVENTS.WELCOME"`, async ({ database, provider }) => { + const welcomeFlow = addKeyword(EVENTS.WELCOME).addAnswer('Bienvenido!') + + await createBot({ + database, + provider, + flow: createFlow([welcomeFlow]), + }) + + await provider.delaySendMessage(0, 'message', { + from: '000', + body: '_event_welcome__f405d946-cf07-uutt-l7e0-b6d475bc7f81', + }) + + await delay(200) + const history = database.listHistory.map((item) => item.answer) + assert.is('Bienvenido!', history[0]) + assert.is(undefined, history[1]) +}) + +testSuite(`Responder a "EVENTS.MEDIA"`, async ({ database, provider }) => { + const mediaFlow = addKeyword(EVENTS.MEDIA).addAnswer('gracias por la imagen o video!') + + await createBot({ + database, + provider, + flow: createFlow([mediaFlow]), + }) + + await provider.delaySendMessage(0, 'message', { + from: '000', + body: '_event_media__f405d946-cf07-uutt-l7e0-b6d475bc7f81', + }) + + await delay(200) + const history = database.listHistory.map((item) => item.answer) + assert.is('gracias por la imagen o video!', history[0]) + assert.is(undefined, history[1]) +}) + +testSuite(`Responder a "EVENTS.VOICE_NOTE"`, async ({ database, provider }) => { + const voiceNoteFlow = addKeyword(EVENTS.VOICE_NOTE).addAnswer('gracias por la nota de voz!') + + await createBot({ + database, + provider, + flow: createFlow([voiceNoteFlow]), + }) + + await provider.delaySendMessage(0, 'message', { + from: '000', + body: '_event_voice_note__f405d946-cf07-uutt-l7e0-b6d475bc7f81', + }) + + await delay(200) + const history = database.listHistory.map((item) => item.answer) + assert.is('gracias por la nota de voz!', history[0]) + assert.is(undefined, history[1]) +}) + +testSuite.run() diff --git a/__test__/0.0.2-case.test.js b/__test__/0.0.2-case.test.js index 03ffba774..25c9fb40b 100644 --- a/__test__/0.0.2-case.test.js +++ b/__test__/0.0.2-case.test.js @@ -3,27 +3,27 @@ const assert = require('uvu/assert') const { addKeyword, createBot, createFlow } = require('../packages/bot/index') const { setup, clear, delay } = require('../__mocks__/env') -const suiteCase = suite('Flujo: manejo de goto') +const testSuite = suite('Flujo: manejo de goto') -suiteCase.before.each(setup) -suiteCase.after.each(clear) +testSuite.before.each(setup) +testSuite.after.each(clear) -suiteCase(`Debe saltar de flujo`, async ({ database, provider }) => { - const flujoUsuarioRegistrado = addKeyword(['user_register']) +testSuite.skip(`Debe saltar de flujo siguiente`, async ({ database, provider }) => { + const userRegisteredFlow = addKeyword(['user_register']) .addAnswer('Hola usuario registrado') .addAnswer('como estas usuario registrado') - const flujoBienvenida = addKeyword(['hola']) + const welcomeFlow = addKeyword(['hola']) .addAnswer('Buenas', null, async (_, { gotoFlow, flowDynamic }) => { await delay(10) await flowDynamic('Usuario registrado DEMO') - await gotoFlow(flujoUsuarioRegistrado) + await gotoFlow(userRegisteredFlow) }) - .addAnswer('este mensaje no deberia existir') + .addAnswer('este mensaje no debería existir') await createBot({ database, - flow: createFlow([flujoBienvenida]), + flow: createFlow([welcomeFlow]), provider, }) @@ -33,28 +33,28 @@ suiteCase(`Debe saltar de flujo`, async ({ database, provider }) => { }) await delay(100) - const getHistory = database.listHistory.map((i) => i.answer) - assert.is('Buenas', getHistory[0]) - assert.is('Usuario registrado DEMO', getHistory[1]) - assert.is('Hola usuario registrado', getHistory[2]) - assert.is('como estas usuario registrado', getHistory[3]) - assert.is(undefined, getHistory[4]) + const history = database.listHistory.map((item) => item.answer) + assert.is('Buenas', history[0]) + assert.is('Usuario registrado DEMO', history[1]) + assert.is('Hola usuario registrado', history[2]) + assert.is('como estas usuario registrado', history[3]) + assert.is(undefined, history[4]) }) -suiteCase(`Debe saltar de flujo con capture sin flowDynamic`, async ({ database, provider }) => { - const flujoUsuarioRegistrado = addKeyword(['user_register']) +testSuite.skip(`Debe saltar de flujo con capture sin flowDynamic`, async ({ database, provider }) => { + const userRegisteredFlow = addKeyword(['user_register']) .addAnswer('Hola usuario registrado') .addAnswer('como estas usuario registrado') - const flujoBienvenida = addKeyword(['hola']) - .addAnswer('Buenas', { capture: true }, async (_, { gotoFlow, flowDynamic, endFlow }) => { - await gotoFlow(flujoUsuarioRegistrado) + const welcomeFlow = addKeyword(['hola']) + .addAnswer('Buenas', { capture: true }, async (_, { gotoFlow }) => { + await gotoFlow(userRegisteredFlow) }) - .addAnswer('este mensaje no deberia existir') + .addAnswer('este mensaje no debería existir') await createBot({ database, - flow: createFlow([flujoBienvenida]), + flow: createFlow([welcomeFlow]), provider, }) @@ -69,30 +69,30 @@ suiteCase(`Debe saltar de flujo con capture sin flowDynamic`, async ({ database, }) await delay(50) - const getHistory = database.listHistory.map((i) => i.answer) - assert.is('Buenas', getHistory[0]) - assert.is('ping', getHistory[1]) - assert.is('Hola usuario registrado', getHistory[2]) - assert.is('como estas usuario registrado', getHistory[3]) - assert.is(undefined, getHistory[4]) + const history = database.listHistory.map((item) => item.answer) + assert.is('Buenas', history[0]) + assert.is('ping', history[1]) + assert.is('Hola usuario registrado', history[2]) + assert.is('como estas usuario registrado', history[3]) + assert.is(undefined, history[4]) }) -suiteCase(`Debe saltar de flujo con capture con flowDynamic`, async ({ database, provider }) => { - const flujoUsuarioRegistrado = addKeyword(['user_register']) +testSuite.skip(`Debe saltar de flujo con capture con flowDynamic`, async ({ database, provider }) => { + const userRegisteredFlow = addKeyword(['user_register']) .addAnswer('Hola usuario registrado') .addAnswer('como estas usuario registrado') - const flujoBienvenida = addKeyword(['hola']) - .addAnswer('Buenas', { capture: true }, async (_, { gotoFlow, flowDynamic, endFlow }) => { + const welcomeFlow = addKeyword(['hola']) + .addAnswer('Buenas', { capture: true }, async (_, { gotoFlow, flowDynamic }) => { await delay(10) await flowDynamic('Usuario registrado DEMO', { continue: false }) - await gotoFlow(flujoUsuarioRegistrado) + await gotoFlow(userRegisteredFlow) }) - .addAnswer('este mensaje no deberia existir') + .addAnswer('este mensaje no debería existir') await createBot({ database, - flow: createFlow([flujoBienvenida]), + flow: createFlow([welcomeFlow]), provider, }) @@ -107,13 +107,65 @@ suiteCase(`Debe saltar de flujo con capture con flowDynamic`, async ({ database, }) await delay(50) - const getHistory = database.listHistory.map((i) => i.answer) - assert.is('Buenas', getHistory[0]) - assert.is('ping', getHistory[1]) - assert.is('Usuario registrado DEMO', getHistory[2]) - assert.is('Hola usuario registrado', getHistory[3]) - assert.is('como estas usuario registrado', getHistory[4]) - assert.is(undefined, getHistory[5]) + const history = database.listHistory.map((item) => item.answer) + assert.is('Buenas', history[0]) + assert.is('ping', history[1]) + assert.is('Usuario registrado DEMO', history[2]) + assert.is('Hola usuario registrado', history[3]) + assert.is('como estas usuario registrado', history[4]) + assert.is(undefined, history[5]) +}) +//Issue https://github.com/codigoencasa/bot-whatsapp/issues/865#issuecomment-1747772797 +testSuite(`Debe de continuar el el encadenamiento`, async ({ database, provider }) => { + const flowBuy = addKeyword(['buy', 'BUY']) + .addAction(async (_, { flowDynamic }) => { + await flowDynamic([{ body: 'Elegir cartera', buttons: [{ body: 'Wallet A' }, { body: 'Wallet B' }] }]) + }) + .addAction({ capture: true }, async (_, { flowDynamic }) => { + return flowDynamic([{ body: 'Comprar con', buttons: [{ body: 'ETH' }, { body: 'USDC' }] }]) + }) + .addAction({ capture: true }, async (_, { flowDynamic }) => { + return flowDynamic([ + { body: 'Comprar cantidad', buttons: [{ body: '0.1' }, { body: '0.5' }, { body: 'CUSTOM' }] }, + ]) + }) + + await createBot({ + database, + flow: createFlow([flowBuy]), + provider, + }) + + await provider.delaySendMessage(0, 'message', { + from: '000', + body: 'buy', + }) + + await provider.delaySendMessage(100, 'message', { + from: '000', + body: 'Wallet A', + }) + await provider.delaySendMessage(100, 'message', { + from: '000', + body: 'USDC', + }) + await provider.delaySendMessage(100, 'message', { + from: '000', + body: '0.1', + }) + + await delay(5000) + const history = database.listHistory.map((item) => item.answer) + assert.is('__call_action__', history[0]) + assert.is('Elegir cartera', history[1]) + assert.is('__capture_only_intended__', history[2]) + assert.is('Wallet A', history[3]) + assert.is('Comprar con', history[4]) + assert.is('__capture_only_intended__', history[5]) + assert.is('USDC', history[6]) + assert.is('Comprar cantidad', history[7]) + assert.is('0.1', history[8]) + assert.is(undefined, history[9]) }) -suiteCase.run() +testSuite.run() diff --git a/__test__/0.1.0-case.test.js b/__test__/0.1.0-case.test.js index 7f45cde37..2c3e9373b 100644 --- a/__test__/0.1.0-case.test.js +++ b/__test__/0.1.0-case.test.js @@ -3,18 +3,18 @@ const assert = require('uvu/assert') const { addKeyword, createBot, createFlow } = require('../packages/bot/index') const { setup, clear, delay } = require('../__mocks__/env') -const suiteCase = suite('Flujo: sensitive') +const testSuite = suite('Flujo: sensitive') -suiteCase.before.each(setup) -suiteCase.after.each(clear) +testSuite.before.each(setup) +testSuite.after.each(clear) -suiteCase(`Responder a "ole" en minuscula`, async ({ database, provider }) => { - const flow = addKeyword(['ola', 'ole'], { sensitive: true }).addAnswer('Bienvenido a la OLA') +testSuite(`Responder a "ole" en minúscula`, async ({ database, provider }) => { + const sensitiveFlow = addKeyword(['ola', 'ole'], { sensitive: true }).addAnswer('Bienvenido a la OLA') await createBot({ database, provider, - flow: createFlow([flow]), + flow: createFlow([sensitiveFlow]), }) await provider.delaySendMessage(0, 'message', { @@ -28,13 +28,13 @@ suiteCase(`Responder a "ole" en minuscula`, async ({ database, provider }) => { assert.is(undefined, database.listHistory[1]) }) -suiteCase(`NO Responder a "ole" en minuscula`, async ({ database, provider }) => { - const flow = addKeyword(['ola', 'ole'], { sensitive: true }).addAnswer('Bienvenido a la OLA') +testSuite(`NO Responder a "OLE" en mayúscula`, async ({ database, provider }) => { + const sensitiveFlow = addKeyword(['ola', 'ole'], { sensitive: true }).addAnswer('Bienvenido a la OLA') await createBot({ database, provider, - flow: createFlow([flow]), + flow: createFlow([sensitiveFlow]), }) await provider.delaySendMessage(0, 'message', { @@ -48,4 +48,4 @@ suiteCase(`NO Responder a "ole" en minuscula`, async ({ database, provider }) => assert.is(undefined, database.listHistory[1]) }) -suiteCase.run() +testSuite.run() diff --git a/package.json b/package.json index c93907430..9e524036b 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "build": "pnpm run cli:rollup && pnpm run bot:rollup && pnpm run provider:rollup && pnpm run database:rollup && pnpm run contexts:rollup && pnpm run create-bot-whatsapp:rollup && pnpm run portal:rollup && pnpm run eslint-plugin:rollup", "copy.lib": "node ./scripts/move.js", "test.unit": "node ./node_modules/uvu/bin.js packages test", - "test.e2e": "node ./node_modules/uvu/bin.js __test__", + "test.e2e": "node ./node_modules/uvu/bin.js __test__ 0.0.2-case.test.js", "test.coverage": "node ./node_modules/c8/bin/c8.js npm run test.unit", "test": "npm run test.coverage", "cli": "node ./packages/cli/bin/cli.js", From 2fe6bd569791f3481183bc9000145f9f48b07673 Mon Sep 17 00:00:00 2001 From: Leifer Mendez Date: Fri, 17 Nov 2023 10:57:40 +0100 Subject: [PATCH 10/15] fix: :zap: issue #865 --- packages/provider/src/baileys/index.js | 7 +++++++ packages/provider/src/baileys/package.json | 3 ++- packages/provider/src/venom/index.js | 9 ++++++--- packages/provider/src/web-whatsapp/index.js | 7 +++++++ packages/provider/src/wppconnect/index.js | 8 ++++++++ 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/packages/provider/src/baileys/index.js b/packages/provider/src/baileys/index.js index 49b819ccc..76701c66c 100644 --- a/packages/provider/src/baileys/index.js +++ b/packages/provider/src/baileys/index.js @@ -394,6 +394,13 @@ class BaileysProvider extends ProviderClass { */ sendButtons = async (number, text, buttons) => { + this.emit( + 'notice', + [ + `[NOTA]: Actualmente enviar botones no esta disponible con este proveedor`, + `[NOTA]: esta funcion esta disponible con Meta o Twilio`, + ].join('\n') + ) const numberClean = baileyCleanNumber(number) const templateButtons = buttons.map((btn, i) => ({ diff --git a/packages/provider/src/baileys/package.json b/packages/provider/src/baileys/package.json index 4df69217f..dc742ddce 100644 --- a/packages/provider/src/baileys/package.json +++ b/packages/provider/src/baileys/package.json @@ -1,6 +1,7 @@ { "dependencies": { "@whiskeysockets/baileys": "^6.5.0", - "wa-sticker-formatter": "4.3.2" + "wa-sticker-formatter": "4.3.2", + "sharp": "^0.30.5" } } diff --git a/packages/provider/src/venom/index.js b/packages/provider/src/venom/index.js index 5e20ca55a..c36b24ea4 100644 --- a/packages/provider/src/venom/index.js +++ b/packages/provider/src/venom/index.js @@ -139,10 +139,13 @@ class VenomProvider extends ProviderClass { * @returns */ sendButtons = async (number, message, buttons = []) => { - const NOTE_VENOM_BUTTON = [`Actualmente VENOM tiene problemas con la API`, `para el envio de Botones`].join( - '\n' + this.emit( + 'notice', + [ + `[NOTA]: Actualmente enviar botones no esta disponible con este proveedor`, + `[NOTA]: esta funcion esta disponible con Meta o Twilio`, + ].join('\n') ) - this.emit('notice', NOTE_VENOM_BUTTON) const buttonToStr = [message].concat(buttons.map((btn) => `${btn.body}`)).join(`\n`) return this.vendor.sendText(number, buttonToStr) // return this.vendor.sendButtons(number, "Title", buttons1, "Description"); diff --git a/packages/provider/src/web-whatsapp/index.js b/packages/provider/src/web-whatsapp/index.js index 6fe0d595c..8bbc1fe69 100644 --- a/packages/provider/src/web-whatsapp/index.js +++ b/packages/provider/src/web-whatsapp/index.js @@ -127,6 +127,13 @@ class WebWhatsappProvider extends ProviderClass { * @returns */ sendButtons = async (number, message, buttons = []) => { + this.emit( + 'notice', + [ + `[NOTA]: Actualmente enviar botones no esta disponible con este proveedor`, + `[NOTA]: esta funcion esta disponible con Meta o Twilio`, + ].join('\n') + ) const buttonMessage = new Buttons(message, buttons, '', '') return this.vendor.sendMessage(number, buttonMessage) } diff --git a/packages/provider/src/wppconnect/index.js b/packages/provider/src/wppconnect/index.js index 37c887224..8d406d301 100644 --- a/packages/provider/src/wppconnect/index.js +++ b/packages/provider/src/wppconnect/index.js @@ -138,6 +138,14 @@ class WPPConnectProviderClass extends ProviderClass { * @example await sendButtons("+XXXXXXXXXXX", "Your Text", [{"body": "Button 1"},{"body": "Button 2"}]) */ sendButtons = async (number, text, buttons) => { + this.emit( + 'notice', + [ + `[NOTA]: Actualmente enviar botones no esta disponible con este proveedor`, + `[NOTA]: esta funcion esta disponible con Meta o Twilio`, + ].join('\n') + ) + const templateButtons = buttons.map((btn, i) => ({ id: `id-btn-${i}`, text: btn.body, From 2355a461f3f9498c86108c649a42116b0645af13 Mon Sep 17 00:00:00 2001 From: Leifer Mendez Date: Fri, 17 Nov 2023 11:00:33 +0100 Subject: [PATCH 11/15] test: :art: more test --- __test__/{0.0.2-case.test.js => 0.0.2-goto-flow.test.js} | 6 +++--- __test__/{0.1.0-case.test.js => 0.1.0-sensitive.test.js} | 0 .../{0.1.1-case.test.js => 0.1.1-children-callback.test.js} | 0 __test__/{0.1.2-case.test.js => 0.1.2-regex.test.js} | 0 __test__/{0.1.3-case.test.js => 0.1.3-capture.test.js} | 0 __test__/{0.1.4-case.test.js => 0.1.4-flow-dynamic.test.js} | 0 package.json | 2 +- 7 files changed, 4 insertions(+), 4 deletions(-) rename __test__/{0.0.2-case.test.js => 0.0.2-goto-flow.test.js} (94%) rename __test__/{0.1.0-case.test.js => 0.1.0-sensitive.test.js} (100%) rename __test__/{0.1.1-case.test.js => 0.1.1-children-callback.test.js} (100%) rename __test__/{0.1.2-case.test.js => 0.1.2-regex.test.js} (100%) rename __test__/{0.1.3-case.test.js => 0.1.3-capture.test.js} (100%) rename __test__/{0.1.4-case.test.js => 0.1.4-flow-dynamic.test.js} (100%) diff --git a/__test__/0.0.2-case.test.js b/__test__/0.0.2-goto-flow.test.js similarity index 94% rename from __test__/0.0.2-case.test.js rename to __test__/0.0.2-goto-flow.test.js index 25c9fb40b..fb1a4f086 100644 --- a/__test__/0.0.2-case.test.js +++ b/__test__/0.0.2-goto-flow.test.js @@ -8,7 +8,7 @@ const testSuite = suite('Flujo: manejo de goto') testSuite.before.each(setup) testSuite.after.each(clear) -testSuite.skip(`Debe saltar de flujo siguiente`, async ({ database, provider }) => { +testSuite(`Debe saltar de flujo siguiente`, async ({ database, provider }) => { const userRegisteredFlow = addKeyword(['user_register']) .addAnswer('Hola usuario registrado') .addAnswer('como estas usuario registrado') @@ -41,7 +41,7 @@ testSuite.skip(`Debe saltar de flujo siguiente`, async ({ database, provider }) assert.is(undefined, history[4]) }) -testSuite.skip(`Debe saltar de flujo con capture sin flowDynamic`, async ({ database, provider }) => { +testSuite(`Debe saltar de flujo con capture sin flowDynamic`, async ({ database, provider }) => { const userRegisteredFlow = addKeyword(['user_register']) .addAnswer('Hola usuario registrado') .addAnswer('como estas usuario registrado') @@ -77,7 +77,7 @@ testSuite.skip(`Debe saltar de flujo con capture sin flowDynamic`, async ({ data assert.is(undefined, history[4]) }) -testSuite.skip(`Debe saltar de flujo con capture con flowDynamic`, async ({ database, provider }) => { +testSuite(`Debe saltar de flujo con capture con flowDynamic`, async ({ database, provider }) => { const userRegisteredFlow = addKeyword(['user_register']) .addAnswer('Hola usuario registrado') .addAnswer('como estas usuario registrado') diff --git a/__test__/0.1.0-case.test.js b/__test__/0.1.0-sensitive.test.js similarity index 100% rename from __test__/0.1.0-case.test.js rename to __test__/0.1.0-sensitive.test.js diff --git a/__test__/0.1.1-case.test.js b/__test__/0.1.1-children-callback.test.js similarity index 100% rename from __test__/0.1.1-case.test.js rename to __test__/0.1.1-children-callback.test.js diff --git a/__test__/0.1.2-case.test.js b/__test__/0.1.2-regex.test.js similarity index 100% rename from __test__/0.1.2-case.test.js rename to __test__/0.1.2-regex.test.js diff --git a/__test__/0.1.3-case.test.js b/__test__/0.1.3-capture.test.js similarity index 100% rename from __test__/0.1.3-case.test.js rename to __test__/0.1.3-capture.test.js diff --git a/__test__/0.1.4-case.test.js b/__test__/0.1.4-flow-dynamic.test.js similarity index 100% rename from __test__/0.1.4-case.test.js rename to __test__/0.1.4-flow-dynamic.test.js diff --git a/package.json b/package.json index 9e524036b..c93907430 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "build": "pnpm run cli:rollup && pnpm run bot:rollup && pnpm run provider:rollup && pnpm run database:rollup && pnpm run contexts:rollup && pnpm run create-bot-whatsapp:rollup && pnpm run portal:rollup && pnpm run eslint-plugin:rollup", "copy.lib": "node ./scripts/move.js", "test.unit": "node ./node_modules/uvu/bin.js packages test", - "test.e2e": "node ./node_modules/uvu/bin.js __test__ 0.0.2-case.test.js", + "test.e2e": "node ./node_modules/uvu/bin.js __test__", "test.coverage": "node ./node_modules/c8/bin/c8.js npm run test.unit", "test": "npm run test.coverage", "cli": "node ./packages/cli/bin/cli.js", From 6edf3730e143c58b3bb36e1d748a6730e6392168 Mon Sep 17 00:00:00 2001 From: Leifer Mendez Date: Fri, 17 Nov 2023 11:44:07 +0100 Subject: [PATCH 12/15] fix: :zap: issue #910 --- __test__/0.0.2-goto-flow.test.js | 74 +++++++++++++++++++++++++++++++- packages/bot/core/core.class.js | 8 +--- 2 files changed, 73 insertions(+), 9 deletions(-) diff --git a/__test__/0.0.2-goto-flow.test.js b/__test__/0.0.2-goto-flow.test.js index fb1a4f086..d3d7dc73b 100644 --- a/__test__/0.0.2-goto-flow.test.js +++ b/__test__/0.0.2-goto-flow.test.js @@ -1,6 +1,6 @@ const { suite } = require('uvu') const assert = require('uvu/assert') -const { addKeyword, createBot, createFlow } = require('../packages/bot/index') +const { addKeyword, createBot, createFlow, EVENTS } = require('../packages/bot/index') const { setup, clear, delay } = require('../__mocks__/env') const testSuite = suite('Flujo: manejo de goto') @@ -8,6 +8,11 @@ const testSuite = suite('Flujo: manejo de goto') testSuite.before.each(setup) testSuite.after.each(clear) +const fakeHTTP = async (fakeData = [], ms = 50) => { + await delay(ms) + return Promise.resolve(fakeData) +} + testSuite(`Debe saltar de flujo siguiente`, async ({ database, provider }) => { const userRegisteredFlow = addKeyword(['user_register']) .addAnswer('Hola usuario registrado') @@ -154,7 +159,7 @@ testSuite(`Debe de continuar el el encadenamiento`, async ({ database, provider body: '0.1', }) - await delay(5000) + await delay(2000) const history = database.listHistory.map((item) => item.answer) assert.is('__call_action__', history[0]) assert.is('Elegir cartera', history[1]) @@ -168,4 +173,69 @@ testSuite(`Debe de continuar el el encadenamiento`, async ({ database, provider assert.is(undefined, history[9]) }) +//Issue https://github.com/codigoencasa/bot-whatsapp/issues/910 +testSuite(`Debe de continuar el el encadenamiento con procesos async`, async ({ database, provider }) => { + const flowBienvenida = addKeyword(EVENTS.ACTION).addAnswer('Bienvenido!') + + const flowReserva = addKeyword(EVENTS.ACTION) + .addAction({ ref: '🙌🙌🙌🙌🙌' }, async (_, { flowDynamic }) => { + const expensiveTask = await fakeHTTP({ data: 'datos de json' }, 800) + await flowDynamic(expensiveTask.data) + }) + .addAction({ ref: '🔝🔝🔝🔝' }, async (_, { gotoFlow }) => { + const expensiveTask = await fakeHTTP({ cliente: 'pepe' }, 800) + if (expensiveTask.cliente !== 'goyo') { + return gotoFlow(flowReservaNuevoCliente) + } + }) + + const flowReservaNuevoCliente = addKeyword('12345').addAnswer( + 'Digame su *Nombre y apellidos* para reservar su mesa...', + { capture: true, ref: '🔔🔔🔔' }, + async (ctx, { state }) => { + await state.update({ Nombre: ctx.body, Telefono: ctx.from.slice(2) }) + } + ) + + const flowMain = addKeyword(EVENTS.WELCOME).addAction(async (ctx, ctxFn) => { + try { + const expensiveTask = await fakeHTTP(`reserva`, 800) + switch (expensiveTask) { + case 'reserva': + return ctxFn.gotoFlow(flowReserva) + default: + return ctxFn.gotoFlow(flowBienvenida) + } + } catch (e) { + console.log('Error en el flowMain: ', e) + } + }) + + await createBot({ + database, + flow: createFlow([flowMain, flowBienvenida, flowReserva, flowReservaNuevoCliente]), + provider, + }) + + await provider.delaySendMessage(0, 'message', { + from: '000', + body: 'buenas', + }) + + await provider.delaySendMessage(3000, 'message', { + from: '000', + body: 'leifer', + }) + + await delay(5000) + const history = database.listHistory.map((item) => item.answer) + assert.is('__call_action__', history[0]) + assert.is('__capture_only_intended__', history[1]) + assert.is('__capture_only_intended__', history[2]) + assert.is('datos de json', history[3]) + assert.is('Digame su *Nombre y apellidos* para reservar su mesa...', history[4]) + assert.is('leifer', history[5]) + assert.is(undefined, history[96]) +}) + testSuite.run() diff --git a/packages/bot/core/core.class.js b/packages/bot/core/core.class.js index e69fe5911..5ae068d07 100644 --- a/packages/bot/core/core.class.js +++ b/packages/bot/core/core.class.js @@ -292,10 +292,9 @@ class CoreClass extends EventEmitter { async (flowInstance, step = 0) => { const promises = [] flag.gotoFlow = true - if (!flowInstance?.toJson) { printer([ - `[CIRCULAR_DEPENDENCY]: Se ha detectado una dependencia circular.`, + `[POSSIBLE_CIRCULAR_DEPENDENCY]: Se ha detectado una dependencia circular.`, `Para evitar problemas, te recomendamos utilizar 'require'('./ruta_del_flow')`, `Ejemplo: gotoFlow(helloFlow) --> gotoFlow(require('./flows/helloFlow.js'))`, `[INFO]: https://bot-whatsapp.netlify.app/docs/goto-flow/`, @@ -307,10 +306,6 @@ class CoreClass extends EventEmitter { const flowParentId = flowTree[step] - if (endFlowFlag) { - return - } - const parseListMsg = await this.flowClass.find(flowParentId?.ref, true, flowTree) for (const msg of parseListMsg) { @@ -321,7 +316,6 @@ class CoreClass extends EventEmitter { // Enviar el mensaje al proveedor y guardarlo await this.sendProviderAndSave(from, ctxMessage).then(() => promises.push(ctxMessage)) } - await endFlow(flag)(promises) return From 1eda39aa7756d7a8f62050775ded20709ad5faad Mon Sep 17 00:00:00 2001 From: Leifer Mendez Date: Fri, 17 Nov 2023 11:57:59 +0100 Subject: [PATCH 13/15] fix: :zap: delay after gotoFlow #877 --- __test__/0.0.2-goto-flow.test.js | 28 ++++++++++++++++++++++++++++ package.json | 2 +- packages/bot/core/core.class.js | 4 ++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/__test__/0.0.2-goto-flow.test.js b/__test__/0.0.2-goto-flow.test.js index d3d7dc73b..c1875dd01 100644 --- a/__test__/0.0.2-goto-flow.test.js +++ b/__test__/0.0.2-goto-flow.test.js @@ -238,4 +238,32 @@ testSuite(`Debe de continuar el el encadenamiento con procesos async`, async ({ assert.is(undefined, history[96]) }) +//Issue https://github.com/codigoencasa/bot-whatsapp/issues/877 +testSuite(`Debe respectar el delay del node previo`, async ({ database, provider }) => { + const flowPing = addKeyword(['hi']).addAction(async (_, { flowDynamic, gotoFlow }) => { + await flowDynamic('Buenas ping debe espera 1segundo') + return gotoFlow(flowBye) + }) + + const flowBye = addKeyword('ping').addAnswer(`Pong con delay 1 segundo`, { delay: 1000 }) + + await createBot({ + database, + flow: createFlow([flowPing, flowBye]), + provider, + }) + + await provider.delaySendMessage(0, 'message', { + from: '000', + body: 'hi', + }) + + await delay(2000) + const history = database.listHistory.map((item) => item.answer) + assert.is('__call_action__', history[0]) + assert.is('Buenas ping debe espera 1segundo', history[1]) + assert.is('Pong con delay 1 segundo', history[2]) + assert.is(undefined, history[3]) +}) + testSuite.run() diff --git a/package.json b/package.json index c93907430..a1a00b790 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "build": "pnpm run cli:rollup && pnpm run bot:rollup && pnpm run provider:rollup && pnpm run database:rollup && pnpm run contexts:rollup && pnpm run create-bot-whatsapp:rollup && pnpm run portal:rollup && pnpm run eslint-plugin:rollup", "copy.lib": "node ./scripts/move.js", "test.unit": "node ./node_modules/uvu/bin.js packages test", - "test.e2e": "node ./node_modules/uvu/bin.js __test__", + "test.e2e": "node ./node_modules/uvu/bin.js __test__ ", "test.coverage": "node ./node_modules/c8/bin/c8.js npm run test.unit", "test": "npm run test.coverage", "cli": "node ./packages/cli/bin/cli.js", diff --git a/packages/bot/core/core.class.js b/packages/bot/core/core.class.js index 5ae068d07..8cf266cdc 100644 --- a/packages/bot/core/core.class.js +++ b/packages/bot/core/core.class.js @@ -292,6 +292,7 @@ class CoreClass extends EventEmitter { async (flowInstance, step = 0) => { const promises = [] flag.gotoFlow = true + if (!flowInstance?.toJson) { printer([ `[POSSIBLE_CIRCULAR_DEPENDENCY]: Se ha detectado una dependencia circular.`, @@ -302,6 +303,8 @@ class CoreClass extends EventEmitter { return } + await delay(flowInstance?.ctx?.options?.delay ?? 0) + const flowTree = flowInstance.toJson() const flowParentId = flowTree[step] @@ -316,6 +319,7 @@ class CoreClass extends EventEmitter { // Enviar el mensaje al proveedor y guardarlo await this.sendProviderAndSave(from, ctxMessage).then(() => promises.push(ctxMessage)) } + await endFlow(flag)(promises) return From 6b1bba7204854f18ba1626ce26a09beb5e4c2f9b Mon Sep 17 00:00:00 2001 From: Leifer Mendez Date: Fri, 17 Nov 2023 13:15:04 +0100 Subject: [PATCH 14/15] refactor: :zap: implement eslint by default --- packages/provider/src/baileys/package.json | 6 +++--- packages/provider/src/meta/package.json | 4 ++-- packages/provider/src/twilio/package.json | 2 +- packages/provider/src/web-whatsapp/package.json | 2 +- packages/provider/src/wppconnect/package.json | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/provider/src/baileys/package.json b/packages/provider/src/baileys/package.json index dc742ddce..2a89790d7 100644 --- a/packages/provider/src/baileys/package.json +++ b/packages/provider/src/baileys/package.json @@ -1,7 +1,7 @@ { "dependencies": { - "@whiskeysockets/baileys": "^6.5.0", - "wa-sticker-formatter": "4.3.2", - "sharp": "^0.30.5" + "@whiskeysockets/baileys": "6.5.0", + "wa-sticker-formatter": "4.4.4", + "cache-manager": "5.2.4" } } diff --git a/packages/provider/src/meta/package.json b/packages/provider/src/meta/package.json index 324215dce..7776d350d 100644 --- a/packages/provider/src/meta/package.json +++ b/packages/provider/src/meta/package.json @@ -1,6 +1,6 @@ { "dependencies": { - "form-data": "^4.0.0", - "queue-promise": "^2.2.1" + "form-data": "4.0.0", + "queue-promise": "2.2.1" } } diff --git a/packages/provider/src/twilio/package.json b/packages/provider/src/twilio/package.json index e4bb7d467..a9c480a7a 100644 --- a/packages/provider/src/twilio/package.json +++ b/packages/provider/src/twilio/package.json @@ -1,5 +1,5 @@ { "dependencies": { - "twilio": "3.84.1" + "twilio": "4.19.0" } } diff --git a/packages/provider/src/web-whatsapp/package.json b/packages/provider/src/web-whatsapp/package.json index 673aa749c..50e0d44fe 100644 --- a/packages/provider/src/web-whatsapp/package.json +++ b/packages/provider/src/web-whatsapp/package.json @@ -1,5 +1,5 @@ { "dependencies": { - "whatsapp-web.js": "^1.22.2-alpha.1" + "whatsapp-web.js": "1.23.0" } } diff --git a/packages/provider/src/wppconnect/package.json b/packages/provider/src/wppconnect/package.json index a57b9ad46..921e4a3dd 100644 --- a/packages/provider/src/wppconnect/package.json +++ b/packages/provider/src/wppconnect/package.json @@ -1,5 +1,5 @@ { "dependencies": { - "@wppconnect-team/wppconnect": "^1.28.0" + "@wppconnect-team/wppconnect": "1.28.3" } } From 7b9b8eb88ecc72b56e1c4e424e0fefe46a0fe876 Mon Sep 17 00:00:00 2001 From: Leifer Mendez Date: Fri, 17 Nov 2023 13:16:51 +0100 Subject: [PATCH 15/15] refactor: :zap: implement eslint by default --- package.json | 2 +- scripts/checker.js | 6 ++++++ starters/apps/base-baileys-json/package.json | 5 +++-- starters/apps/base-baileys-memory/package.json | 6 ++++-- starters/apps/base-baileys-mongo/package.json | 6 ++++-- starters/apps/base-baileys-mysql/package.json | 6 ++++-- starters/apps/base-baileys-postgres/package.json | 8 +++++--- starters/apps/base-meta-json/package.json | 5 ++++- starters/apps/base-meta-memory/package.json | 5 ++++- starters/apps/base-meta-mongo/package.json | 5 ++++- starters/apps/base-meta-mysql/package.json | 5 ++++- starters/apps/base-meta-postgres/package.json | 5 ++++- starters/apps/base-twilio-json/package.json | 3 ++- starters/apps/base-twilio-memory/package.json | 3 ++- starters/apps/base-twilio-mongo/package.json | 3 ++- starters/apps/base-twilio-mysql/package.json | 3 ++- starters/apps/base-twilio-postgres/package.json | 3 ++- starters/apps/base-venom-json/package.json | 3 ++- starters/apps/base-venom-memory/package.json | 3 ++- starters/apps/base-venom-mongo/package.json | 3 ++- starters/apps/base-venom-mysql/package.json | 3 ++- starters/apps/base-venom-postgres/package.json | 3 ++- starters/apps/base-wppconnect-json/package.json | 3 ++- starters/apps/base-wppconnect-memory/package.json | 3 ++- starters/apps/base-wppconnect-mongo/package.json | 3 ++- starters/apps/base-wppconnect-mysql/package.json | 3 ++- starters/apps/base-wppconnect-postgres/package.json | 3 ++- starters/apps/base-wweb-json/package.json | 3 ++- starters/apps/base-wweb-memory/package.json | 3 ++- starters/apps/base-wweb-mongo/package.json | 3 ++- starters/apps/base-wweb-mysql/package.json | 3 ++- starters/apps/base-wweb-postgres/package.json | 3 ++- 32 files changed, 87 insertions(+), 37 deletions(-) diff --git a/package.json b/package.json index c93907430..8ad508f19 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "lint:check": "eslint .", "lint:fix": "eslint --fix ./packages", "build:portal-web": "cd ./packages/portal/ && pnpm run build.types && pnpm run build.client && pnpm run build.server && pnpm run lint --fix", - "build:full": "pnpm run build:portal-web && pnpm run cli:rollup && pnpm run bot:rollup && pnpm run provider:rollup && pnpm run database:rollup && pnpm run contexts:rollup && pnpm run create-bot-whatsapp:rollup && pnpm run portal:rollup", + "build:full": "pnpm run build:portal-web && pnpm run cli:rollup && pnpm run bot:rollup && pnpm run provider:rollup && pnpm run database:rollup && pnpm run contexts:rollup && pnpm run create-bot-whatsapp:rollup && pnpm run eslint-plugin:rollup && pnpm run portal:rollup", "build": "pnpm run cli:rollup && pnpm run bot:rollup && pnpm run provider:rollup && pnpm run database:rollup && pnpm run contexts:rollup && pnpm run create-bot-whatsapp:rollup && pnpm run portal:rollup && pnpm run eslint-plugin:rollup", "copy.lib": "node ./scripts/move.js", "test.unit": "node ./node_modules/uvu/bin.js packages test", diff --git a/scripts/checker.js b/scripts/checker.js index 351a5ee75..cb2d58950 100644 --- a/scripts/checker.js +++ b/scripts/checker.js @@ -61,6 +61,12 @@ const checkEveryProvider = async (provider = '', stable = true) => { const devParse = Object.entries(dependencies) const newDevParse = {} for (const [pkgName, pkgVersion] of devParse) { + if (!pkgVersion.includes('^')) { + newDevParse[pkgName] = pkgVersion + continue + } + console.log(`[VERSION]:${pkgVersion}`) + if (!stable) newDevParse[pkgName] = await checkPkg(pkgName) if (stable) newDevParse[pkgName] = await checkPkgStable(pkgName, pkgVersion) diff --git a/starters/apps/base-baileys-json/package.json b/starters/apps/base-baileys-json/package.json index 1e5bc2321..074773848 100644 --- a/starters/apps/base-baileys-json/package.json +++ b/starters/apps/base-baileys-json/package.json @@ -15,8 +15,9 @@ "@bot-whatsapp/provider": "latest", "@bot-whatsapp/portal": "latest", "mime-types": "2.1.35", - "@whiskeysockets/baileys": "^6.4.0", - "wa-sticker-formatter": "4.3.2" + "@whiskeysockets/baileys": "6.5.0", + "wa-sticker-formatter": "4.4.4", + "cache-manager": "5.2.4" }, "devDependencies": { "eslint-plugin-bot-whatsapp": "latest", diff --git a/starters/apps/base-baileys-memory/package.json b/starters/apps/base-baileys-memory/package.json index 3457bd951..d6294069d 100644 --- a/starters/apps/base-baileys-memory/package.json +++ b/starters/apps/base-baileys-memory/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint .", "pre-copy": "cd .. && npm run copy.lib base-baileys-memory", "start": "node app.js" }, @@ -14,8 +15,9 @@ "@bot-whatsapp/database": "latest", "@bot-whatsapp/provider": "latest", "@bot-whatsapp/portal": "latest", - "@whiskeysockets/baileys": "^6.4.0", - "wa-sticker-formatter": "4.3.2" + "@whiskeysockets/baileys": "6.5.0", + "wa-sticker-formatter": "4.4.4", + "cache-manager": "5.2.4" }, "devDependencies": { "eslint-plugin-bot-whatsapp": "latest", diff --git a/starters/apps/base-baileys-mongo/package.json b/starters/apps/base-baileys-mongo/package.json index 8faba3f2d..f6317a8dc 100644 --- a/starters/apps/base-baileys-mongo/package.json +++ b/starters/apps/base-baileys-mongo/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-baileys-mongo", "start": "node app.js" }, @@ -16,8 +17,9 @@ "@bot-whatsapp/portal": "latest", "mime-types": "2.1.35", "mongodb": "^4.12.1", - "@whiskeysockets/baileys": "^6.4.0", - "wa-sticker-formatter": "4.3.2" + "@whiskeysockets/baileys": "6.5.0", + "wa-sticker-formatter": "4.4.4", + "cache-manager": "5.2.4" }, "devDependencies": { "eslint-plugin-bot-whatsapp": "latest", diff --git a/starters/apps/base-baileys-mysql/package.json b/starters/apps/base-baileys-mysql/package.json index 949b8b65e..60d82f9c1 100644 --- a/starters/apps/base-baileys-mysql/package.json +++ b/starters/apps/base-baileys-mysql/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-baileys-mysql", "start": "node app.js" }, @@ -15,8 +16,9 @@ "@bot-whatsapp/provider": "latest", "@bot-whatsapp/portal": "latest", "mysql2": "^2.3.3", - "@whiskeysockets/baileys": "^6.4.0", - "wa-sticker-formatter": "4.3.2" + "@whiskeysockets/baileys": "6.5.0", + "wa-sticker-formatter": "4.4.4", + "cache-manager": "5.2.4" }, "devDependencies": { "eslint-plugin-bot-whatsapp": "latest", diff --git a/starters/apps/base-baileys-postgres/package.json b/starters/apps/base-baileys-postgres/package.json index 813e2f655..6feb6b016 100644 --- a/starters/apps/base-baileys-postgres/package.json +++ b/starters/apps/base-baileys-postgres/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-baileys-postgres", "start": "node app.js" }, @@ -14,9 +15,10 @@ "@bot-whatsapp/database": "latest", "@bot-whatsapp/provider": "latest", "@bot-whatsapp/portal": "latest", - "@whiskeysockets/baileys": "^6.4.0", - "wa-sticker-formatter": "4.3.2", - "pg": "^8.11.2" + "@whiskeysockets/baileys": "6.5.0", + "wa-sticker-formatter": "4.4.4", + "pg": "^8.11.2", + "cache-manager": "5.2.4" }, "devDependencies": { "eslint-plugin-bot-whatsapp": "latest", diff --git a/starters/apps/base-meta-json/package.json b/starters/apps/base-meta-json/package.json index 1e7dc62f7..718a87920 100644 --- a/starters/apps/base-meta-json/package.json +++ b/starters/apps/base-meta-json/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-meta-json", "start": "node app.js" }, @@ -15,7 +16,9 @@ "@bot-whatsapp/cli": "latest", "@bot-whatsapp/database": "latest", "@bot-whatsapp/provider": "latest", - "axios": "^1.2.1" + "axios": "^1.2.1", + "form-data": "4.0.0", + "queue-promise": "2.2.1" }, "devDependencies": { "eslint-plugin-bot-whatsapp": "latest", diff --git a/starters/apps/base-meta-memory/package.json b/starters/apps/base-meta-memory/package.json index 666949226..4e558cb17 100644 --- a/starters/apps/base-meta-memory/package.json +++ b/starters/apps/base-meta-memory/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-meta-memory", "start": "node app.js" }, @@ -15,7 +16,9 @@ "@bot-whatsapp/cli": "latest", "@bot-whatsapp/database": "latest", "@bot-whatsapp/provider": "latest", - "axios": "^1.2.1" + "axios": "^1.2.1", + "form-data": "4.0.0", + "queue-promise": "2.2.1" }, "devDependencies": { "eslint-plugin-bot-whatsapp": "latest", diff --git a/starters/apps/base-meta-mongo/package.json b/starters/apps/base-meta-mongo/package.json index e44b24de0..44d215b05 100644 --- a/starters/apps/base-meta-mongo/package.json +++ b/starters/apps/base-meta-mongo/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-meta-mongo", "start": "node app.js" }, @@ -16,7 +17,9 @@ "@bot-whatsapp/database": "latest", "@bot-whatsapp/provider": "latest", "axios": "^1.2.1", - "mongodb": "^4.12.1" + "mongodb": "^4.12.1", + "form-data": "4.0.0", + "queue-promise": "2.2.1" }, "devDependencies": { "eslint-plugin-bot-whatsapp": "latest", diff --git a/starters/apps/base-meta-mysql/package.json b/starters/apps/base-meta-mysql/package.json index 1b072d92f..43cc01e5e 100644 --- a/starters/apps/base-meta-mysql/package.json +++ b/starters/apps/base-meta-mysql/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-meta-mysql", "start": "node app.js" }, @@ -16,7 +17,9 @@ "@bot-whatsapp/database": "latest", "@bot-whatsapp/provider": "latest", "axios": "^1.2.1", - "mysql2": "^2.3.3" + "mysql2": "^2.3.3", + "form-data": "4.0.0", + "queue-promise": "2.2.1" }, "devDependencies": { "eslint-plugin-bot-whatsapp": "latest", diff --git a/starters/apps/base-meta-postgres/package.json b/starters/apps/base-meta-postgres/package.json index 2c6920276..3e654dc85 100644 --- a/starters/apps/base-meta-postgres/package.json +++ b/starters/apps/base-meta-postgres/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-meta-postgres", "start": "node app.js" }, @@ -16,7 +17,9 @@ "@bot-whatsapp/database": "latest", "@bot-whatsapp/provider": "latest", "axios": "^1.2.1", - "pg": "^8.11.2" + "pg": "^8.11.2", + "form-data": "4.0.0", + "queue-promise": "2.2.1" }, "devDependencies": { "eslint-plugin-bot-whatsapp": "latest", diff --git a/starters/apps/base-twilio-json/package.json b/starters/apps/base-twilio-json/package.json index 18f0c3165..1311d006b 100644 --- a/starters/apps/base-twilio-json/package.json +++ b/starters/apps/base-twilio-json/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-twilio-json", "start": "node app.js" }, @@ -11,7 +12,7 @@ "dependencies": { "body-parser": "^1.20.1", "polka": "^0.5.2", - "twilio": "3.84.1", + "twilio": "4.19.0", "@bot-whatsapp/bot": "latest", "@bot-whatsapp/cli": "latest", "@bot-whatsapp/database": "latest", diff --git a/starters/apps/base-twilio-memory/package.json b/starters/apps/base-twilio-memory/package.json index 8c4bdda4c..8d7fec6f7 100644 --- a/starters/apps/base-twilio-memory/package.json +++ b/starters/apps/base-twilio-memory/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-twilio-memory", "start": "node app.js" }, @@ -11,7 +12,7 @@ "dependencies": { "body-parser": "^1.20.1", "polka": "^0.5.2", - "twilio": "3.84.1", + "twilio": "4.19.0", "@bot-whatsapp/bot": "latest", "@bot-whatsapp/cli": "latest", "@bot-whatsapp/database": "latest", diff --git a/starters/apps/base-twilio-mongo/package.json b/starters/apps/base-twilio-mongo/package.json index 6103d7a15..886639b84 100644 --- a/starters/apps/base-twilio-mongo/package.json +++ b/starters/apps/base-twilio-mongo/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-twilio-mongo", "start": "node app.js" }, @@ -11,7 +12,7 @@ "dependencies": { "body-parser": "^1.20.1", "polka": "^0.5.2", - "twilio": "3.84.1", + "twilio": "4.19.0", "@bot-whatsapp/bot": "latest", "@bot-whatsapp/cli": "latest", "@bot-whatsapp/database": "latest", diff --git a/starters/apps/base-twilio-mysql/package.json b/starters/apps/base-twilio-mysql/package.json index 70c18fe12..d8b89f8c0 100644 --- a/starters/apps/base-twilio-mysql/package.json +++ b/starters/apps/base-twilio-mysql/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-twilio-mysql", "start": "node app.js" }, @@ -11,7 +12,7 @@ "dependencies": { "body-parser": "^1.20.1", "polka": "^0.5.2", - "twilio": "3.84.1", + "twilio": "4.19.0", "@bot-whatsapp/bot": "latest", "@bot-whatsapp/cli": "latest", "@bot-whatsapp/database": "latest", diff --git a/starters/apps/base-twilio-postgres/package.json b/starters/apps/base-twilio-postgres/package.json index 69e457b21..3aeda381b 100644 --- a/starters/apps/base-twilio-postgres/package.json +++ b/starters/apps/base-twilio-postgres/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-twilio-postgres", "start": "node app.js" }, @@ -11,7 +12,7 @@ "dependencies": { "body-parser": "^1.20.1", "polka": "^0.5.2", - "twilio": "3.84.1", + "twilio": "4.19.0", "@bot-whatsapp/bot": "latest", "@bot-whatsapp/cli": "latest", "@bot-whatsapp/database": "latest", diff --git a/starters/apps/base-venom-json/package.json b/starters/apps/base-venom-json/package.json index b25633c77..d926f2d40 100644 --- a/starters/apps/base-venom-json/package.json +++ b/starters/apps/base-venom-json/package.json @@ -4,12 +4,13 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-venom-json", "start": "node app.js" }, "keywords": [], "dependencies": { - "venom-bot": "4.3.7", + "venom-bot": "5.0.21", "mime-types": "2.1.35", "@bot-whatsapp/bot": "latest", "@bot-whatsapp/cli": "latest", diff --git a/starters/apps/base-venom-memory/package.json b/starters/apps/base-venom-memory/package.json index e7d8d0d71..b53deffe8 100644 --- a/starters/apps/base-venom-memory/package.json +++ b/starters/apps/base-venom-memory/package.json @@ -4,12 +4,13 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-venom-memory", "start": "node app.js" }, "keywords": [], "dependencies": { - "venom-bot": "4.3.7", + "venom-bot": "5.0.21", "@bot-whatsapp/bot": "latest", "@bot-whatsapp/cli": "latest", "@bot-whatsapp/database": "latest", diff --git a/starters/apps/base-venom-mongo/package.json b/starters/apps/base-venom-mongo/package.json index f765476f6..6b950bb4d 100644 --- a/starters/apps/base-venom-mongo/package.json +++ b/starters/apps/base-venom-mongo/package.json @@ -4,12 +4,13 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-venom-mongo", "start": "node app.js" }, "keywords": [], "dependencies": { - "venom-bot": "4.3.7", + "venom-bot": "5.0.21", "@bot-whatsapp/bot": "latest", "@bot-whatsapp/cli": "latest", "@bot-whatsapp/database": "latest", diff --git a/starters/apps/base-venom-mysql/package.json b/starters/apps/base-venom-mysql/package.json index 68c8bfec8..9e7ff8d0c 100644 --- a/starters/apps/base-venom-mysql/package.json +++ b/starters/apps/base-venom-mysql/package.json @@ -4,12 +4,13 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-venom-mysql", "start": "node app.js" }, "keywords": [], "dependencies": { - "venom-bot": "4.3.7", + "venom-bot": "5.0.21", "@bot-whatsapp/bot": "latest", "@bot-whatsapp/cli": "latest", "@bot-whatsapp/database": "latest", diff --git a/starters/apps/base-venom-postgres/package.json b/starters/apps/base-venom-postgres/package.json index 4a9d57a4f..f8485ef5b 100644 --- a/starters/apps/base-venom-postgres/package.json +++ b/starters/apps/base-venom-postgres/package.json @@ -4,12 +4,13 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-venom-postgres", "start": "node app.js" }, "keywords": [], "dependencies": { - "venom-bot": "4.3.7", + "venom-bot": "5.0.21", "@bot-whatsapp/bot": "latest", "@bot-whatsapp/cli": "latest", "@bot-whatsapp/database": "latest", diff --git a/starters/apps/base-wppconnect-json/package.json b/starters/apps/base-wppconnect-json/package.json index a963e1a21..cdc8c95e0 100644 --- a/starters/apps/base-wppconnect-json/package.json +++ b/starters/apps/base-wppconnect-json/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-wppconnect-json", "start": "node app.js" }, @@ -14,7 +15,7 @@ "@bot-whatsapp/database": "latest", "@bot-whatsapp/portal": "latest", "@bot-whatsapp/provider": "latest", - "@wppconnect-team/wppconnect": "^1.27.3", + "@wppconnect-team/wppconnect": "1.28.3", "mime-types": "2.1.35" }, "devDependencies": { diff --git a/starters/apps/base-wppconnect-memory/package.json b/starters/apps/base-wppconnect-memory/package.json index 6f6775e0a..28ecbd5a3 100644 --- a/starters/apps/base-wppconnect-memory/package.json +++ b/starters/apps/base-wppconnect-memory/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-wppconnect-memory", "start": "node app.js" }, @@ -14,7 +15,7 @@ "@bot-whatsapp/database": "latest", "@bot-whatsapp/portal": "latest", "@bot-whatsapp/provider": "latest", - "@wppconnect-team/wppconnect": "^1.27.3", + "@wppconnect-team/wppconnect": "1.28.3", "mime-types": "2.1.35" }, "devDependencies": { diff --git a/starters/apps/base-wppconnect-mongo/package.json b/starters/apps/base-wppconnect-mongo/package.json index f75b5510a..73a18fc17 100644 --- a/starters/apps/base-wppconnect-mongo/package.json +++ b/starters/apps/base-wppconnect-mongo/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-wppconnect-mongo", "start": "node app.js" }, @@ -14,7 +15,7 @@ "@bot-whatsapp/database": "latest", "@bot-whatsapp/portal": "latest", "@bot-whatsapp/provider": "latest", - "@wppconnect-team/wppconnect": "^1.27.3", + "@wppconnect-team/wppconnect": "1.28.3", "mime-types": "2.1.35", "mongodb": "4.12.1" }, diff --git a/starters/apps/base-wppconnect-mysql/package.json b/starters/apps/base-wppconnect-mysql/package.json index 7182dada2..02602c22c 100644 --- a/starters/apps/base-wppconnect-mysql/package.json +++ b/starters/apps/base-wppconnect-mysql/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-wppconnect-mysql", "start": "node app.js" }, @@ -14,7 +15,7 @@ "@bot-whatsapp/database": "latest", "@bot-whatsapp/portal": "latest", "@bot-whatsapp/provider": "latest", - "@wppconnect-team/wppconnect": "^1.27.3", + "@wppconnect-team/wppconnect": "1.28.3", "mime-types": "2.1.35", "mysql2": "2.3.3" }, diff --git a/starters/apps/base-wppconnect-postgres/package.json b/starters/apps/base-wppconnect-postgres/package.json index 70d3e10cf..f304193d6 100644 --- a/starters/apps/base-wppconnect-postgres/package.json +++ b/starters/apps/base-wppconnect-postgres/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-wppconnect-postgres", "start": "node app.js" }, @@ -14,7 +15,7 @@ "@bot-whatsapp/database": "latest", "@bot-whatsapp/portal": "latest", "@bot-whatsapp/provider": "latest", - "@wppconnect-team/wppconnect": "1.22.0", + "@wppconnect-team/wppconnect": "1.28.3", "mime-types": "2.1.35", "pg": "^8.11.2" }, diff --git a/starters/apps/base-wweb-json/package.json b/starters/apps/base-wweb-json/package.json index ec30aaffa..7ed3e897d 100644 --- a/starters/apps/base-wweb-json/package.json +++ b/starters/apps/base-wweb-json/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-wweb-json", "start": "node app.js" }, @@ -14,7 +15,7 @@ "@bot-whatsapp/database": "latest", "@bot-whatsapp/provider": "latest", "@bot-whatsapp/portal": "latest", - "whatsapp-web.js": "^1.22.1" + "whatsapp-web.js": "1.23.0" }, "devDependencies": { "eslint-plugin-bot-whatsapp": "latest", diff --git a/starters/apps/base-wweb-memory/package.json b/starters/apps/base-wweb-memory/package.json index bf1d817a5..f9361abe1 100644 --- a/starters/apps/base-wweb-memory/package.json +++ b/starters/apps/base-wweb-memory/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-wweb-memory", "start": "node app.js" }, @@ -14,7 +15,7 @@ "@bot-whatsapp/database": "latest", "@bot-whatsapp/provider": "latest", "@bot-whatsapp/portal": "latest", - "whatsapp-web.js": "^1.22.1" + "whatsapp-web.js": "1.23.0" }, "devDependencies": { "eslint-plugin-bot-whatsapp": "latest", diff --git a/starters/apps/base-wweb-mongo/package.json b/starters/apps/base-wweb-mongo/package.json index 256660d88..677667623 100644 --- a/starters/apps/base-wweb-mongo/package.json +++ b/starters/apps/base-wweb-mongo/package.json @@ -4,12 +4,13 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-wweb-mongo", "start": "node app.js" }, "keywords": [], "dependencies": { - "whatsapp-web.js": "^1.22.1", + "whatsapp-web.js": "1.23.0", "@bot-whatsapp/bot": "latest", "@bot-whatsapp/cli": "latest", "@bot-whatsapp/database": "latest", diff --git a/starters/apps/base-wweb-mysql/package.json b/starters/apps/base-wweb-mysql/package.json index 4b1c32f18..8a4bf9623 100644 --- a/starters/apps/base-wweb-mysql/package.json +++ b/starters/apps/base-wweb-mysql/package.json @@ -4,12 +4,13 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-wweb-mysql", "start": "node app.js" }, "keywords": [], "dependencies": { - "whatsapp-web.js": "^1.22.1", + "whatsapp-web.js": "1.23.0", "@bot-whatsapp/bot": "latest", "@bot-whatsapp/cli": "latest", "@bot-whatsapp/database": "latest", diff --git a/starters/apps/base-wweb-postgres/package.json b/starters/apps/base-wweb-postgres/package.json index 89bde4ad4..8996dc864 100644 --- a/starters/apps/base-wweb-postgres/package.json +++ b/starters/apps/base-wweb-postgres/package.json @@ -4,12 +4,13 @@ "description": "", "main": "app.js", "scripts": { + "prestart": "npx eslint . --no-ignore", "pre-copy": "cd .. && npm run copy.lib base-wweb-postgres", "start": "node app.js" }, "keywords": [], "dependencies": { - "whatsapp-web.js": "1.19.4", + "whatsapp-web.js": "1.23.0", "@bot-whatsapp/bot": "latest", "@bot-whatsapp/cli": "latest", "@bot-whatsapp/database": "latest",