mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-20 20:49:15 +00:00
chore(bot): ⚡ fallback done
This commit is contained in:
2
TODO.md
2
TODO.md
@@ -9,6 +9,8 @@
|
|||||||
- [X] .addKeyword('1') no funciona con 1 caracter
|
- [X] .addKeyword('1') no funciona con 1 caracter
|
||||||
- [X] sensitivy viene activado por defecto
|
- [X] sensitivy viene activado por defecto
|
||||||
- [ ] fallback respuesta en hijo: Se puede colocar en option el ref de la answer fallback
|
- [ ] 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)
|
- [ ] colocar mensaje esperando conectando whatsapp (provider)
|
||||||
- [ ] Cuando Envian Sticket devuelve mensaje raro
|
- [ ] Cuando Envian Sticket devuelve mensaje raro
|
||||||
- [ ] createDatabase validar implementacion de funciones
|
- [ ] createDatabase validar implementacion de funciones
|
||||||
|
|||||||
@@ -53,18 +53,12 @@ class CoreClass {
|
|||||||
handleMsg = async (messageInComming) => {
|
handleMsg = async (messageInComming) => {
|
||||||
const { body, from } = messageInComming
|
const { body, from } = messageInComming
|
||||||
let msgToSend = []
|
let msgToSend = []
|
||||||
|
let fallBackFlag = false
|
||||||
const prevMsg = await this.databaseClass.getPrevByNumber(from)
|
const prevMsg = await this.databaseClass.getPrevByNumber(from)
|
||||||
const refToContinue = this.flowClass.findBySerialize(
|
const refToContinue = this.flowClass.findBySerialize(
|
||||||
prevMsg?.refSerialize
|
prevMsg?.refSerialize
|
||||||
)
|
)
|
||||||
|
|
||||||
const fallBack = () => {
|
|
||||||
msgToSend = this.flowClass.find(refToContinue?.keyword, true) || []
|
|
||||||
this.sendFlow(msgToSend, from)
|
|
||||||
return refToContinue
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prevMsg?.ref) {
|
if (prevMsg?.ref) {
|
||||||
const ctxByNumber = toCtx({
|
const ctxByNumber = toCtx({
|
||||||
body,
|
body,
|
||||||
@@ -73,9 +67,15 @@ class CoreClass {
|
|||||||
})
|
})
|
||||||
this.databaseClass.save(ctxByNumber)
|
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
|
// 📄 [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)
|
const indexFlow = this.flowClass.findIndexByRef(refToContinue?.ref)
|
||||||
this.flowClass.allCallbacks[indexFlow].callback(messageInComming, {
|
this.flowClass.allCallbacks[indexFlow].callback(messageInComming, {
|
||||||
fallBack,
|
fallBack,
|
||||||
@@ -83,7 +83,7 @@ class CoreClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 📄🤘(tiene return) [options: nested(array)]: Si se tiene flujos hijos los implementa
|
// 📄🤘(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 nestedRef = prevMsg.options.nested
|
||||||
const flowStandalone = nestedRef.map((f) => ({
|
const flowStandalone = nestedRef.map((f) => ({
|
||||||
...nestedRef.find((r) => r.refSerialize === f.refSerialize),
|
...nestedRef.find((r) => r.refSerialize === f.refSerialize),
|
||||||
@@ -95,7 +95,7 @@ class CoreClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 📄🤘(tiene return) [options: capture (boolean)]: Si se tiene option boolean
|
// 📄🤘(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 typeCapture = typeof prevMsg?.options?.capture
|
||||||
const valueCapture = prevMsg?.options?.capture
|
const valueCapture = prevMsg?.options?.capture
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user