chore(bot): update fallback function

This commit is contained in:
Leifer Mendez
2022-12-04 16:01:52 +01:00
parent aa2417af12
commit 371ee0a780
2 changed files with 13 additions and 4 deletions

View File

@@ -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