From f373a3abc794768cb5113e76af30c24941ef7afb Mon Sep 17 00:00:00 2001 From: Leifer Mendez Date: Mon, 5 Dec 2022 09:59:40 +0100 Subject: [PATCH] chore(bot): :zap: fallback done --- TODO.md | 2 ++ packages/bot/core/core.class.js | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/TODO.md b/TODO.md index 8b41430..dd2ea72 100644 --- a/TODO.md +++ b/TODO.md @@ -9,6 +9,8 @@ - [X] .addKeyword('1') no funciona con 1 caracter - [X] sensitivy viene activado por defecto - [ ] fallback respuesta en hijo: Se puede colocar en option el ref de la answer fallback +- [ ] envia imagen +- [ ] envia nota de voz - [ ] colocar mensaje esperando conectando whatsapp (provider) - [ ] Cuando Envian Sticket devuelve mensaje raro - [ ] createDatabase validar implementacion de funciones diff --git a/packages/bot/core/core.class.js b/packages/bot/core/core.class.js index 549ac45..1c2f149 100644 --- a/packages/bot/core/core.class.js +++ b/packages/bot/core/core.class.js @@ -53,18 +53,12 @@ class CoreClass { handleMsg = async (messageInComming) => { const { body, from } = messageInComming let msgToSend = [] - + let fallBackFlag = false const prevMsg = await this.databaseClass.getPrevByNumber(from) const refToContinue = this.flowClass.findBySerialize( prevMsg?.refSerialize ) - const fallBack = () => { - msgToSend = this.flowClass.find(refToContinue?.keyword, true) || [] - this.sendFlow(msgToSend, from) - return refToContinue - } - if (prevMsg?.ref) { const ctxByNumber = toCtx({ body, @@ -73,9 +67,15 @@ class CoreClass { }) this.databaseClass.save(ctxByNumber) } + const fallBack = () => { + fallBackFlag = true + msgToSend = this.flowClass.find(refToContinue?.keyword, true) || [] + this.sendFlow(msgToSend, from) + return refToContinue + } // 📄 [options: callback]: Si se tiene un callback se ejecuta - if (refToContinue && prevMsg?.options?.callback) { + if (!fallBackFlag && refToContinue && prevMsg?.options?.callback) { const indexFlow = this.flowClass.findIndexByRef(refToContinue?.ref) this.flowClass.allCallbacks[indexFlow].callback(messageInComming, { fallBack, @@ -83,7 +83,7 @@ class CoreClass { } // 📄🤘(tiene return) [options: nested(array)]: Si se tiene flujos hijos los implementa - if (prevMsg?.options?.nested?.length) { + if (!fallBackFlag && prevMsg?.options?.nested?.length) { const nestedRef = prevMsg.options.nested const flowStandalone = nestedRef.map((f) => ({ ...nestedRef.find((r) => r.refSerialize === f.refSerialize), @@ -95,7 +95,7 @@ class CoreClass { } // 📄🤘(tiene return) [options: capture (boolean)]: Si se tiene option boolean - if (!prevMsg?.options?.nested?.length) { + if (!fallBackFlag && !prevMsg?.options?.nested?.length) { const typeCapture = typeof prevMsg?.options?.capture const valueCapture = prevMsg?.options?.capture