From 371ee0a7803de42e57da8e2b829d17e452a5f2ed Mon Sep 17 00:00:00 2001 From: Leifer Mendez Date: Sun, 4 Dec 2022 16:01:52 +0100 Subject: [PATCH] chore(bot): :zap: update fallback function --- .vscode/settings.json | 2 +- packages/bot/core/core.class.js | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 6fd7fb6..e286082 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { - "conventionalCommits.scopes": ["hook", "contributing", "cli"] + "conventionalCommits.scopes": ["hook", "contributing", "cli", "bot"] } diff --git a/packages/bot/core/core.class.js b/packages/bot/core/core.class.js index 9481532..549ac45 100644 --- a/packages/bot/core/core.class.js +++ b/packages/bot/core/core.class.js @@ -21,6 +21,9 @@ class CoreClass { } } + /** + * Manejador de eventos + */ listenerBusEvents = () => [ { event: 'require_action', @@ -51,13 +54,17 @@ class CoreClass { const { body, from } = messageInComming let msgToSend = [] - //Consultamos mensaje previo en DB const prevMsg = await this.databaseClass.getPrevByNumber(from) - //Consultamos for refSerializada en el flow actual 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, @@ -70,7 +77,9 @@ class CoreClass { // 📄 [options: callback]: Si se tiene un callback se ejecuta if (refToContinue && prevMsg?.options?.callback) { const indexFlow = this.flowClass.findIndexByRef(refToContinue?.ref) - this.flowClass.allCallbacks[indexFlow].callback(messageInComming) + this.flowClass.allCallbacks[indexFlow].callback(messageInComming, { + fallBack, + }) } // 📄🤘(tiene return) [options: nested(array)]: Si se tiene flujos hijos los implementa