chore(bot): fallback done

This commit is contained in:
Leifer Mendez
2022-12-05 09:59:40 +01:00
parent 371ee0a780
commit f373a3abc7
2 changed files with 12 additions and 10 deletions

View File

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

View File

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