mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-17 19:26:23 +00:00
chore(bot): ⚡ update fallback function
This commit is contained in:
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"conventionalCommits.scopes": ["hook", "contributing", "cli"]
|
"conventionalCommits.scopes": ["hook", "contributing", "cli", "bot"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ class CoreClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manejador de eventos
|
||||||
|
*/
|
||||||
listenerBusEvents = () => [
|
listenerBusEvents = () => [
|
||||||
{
|
{
|
||||||
event: 'require_action',
|
event: 'require_action',
|
||||||
@@ -51,13 +54,17 @@ class CoreClass {
|
|||||||
const { body, from } = messageInComming
|
const { body, from } = messageInComming
|
||||||
let msgToSend = []
|
let msgToSend = []
|
||||||
|
|
||||||
//Consultamos mensaje previo en DB
|
|
||||||
const prevMsg = await this.databaseClass.getPrevByNumber(from)
|
const prevMsg = await this.databaseClass.getPrevByNumber(from)
|
||||||
//Consultamos for refSerializada en el flow actual
|
|
||||||
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,
|
||||||
@@ -70,7 +77,9 @@ class CoreClass {
|
|||||||
// 📄 [options: callback]: Si se tiene un callback se ejecuta
|
// 📄 [options: callback]: Si se tiene un callback se ejecuta
|
||||||
if (refToContinue && prevMsg?.options?.callback) {
|
if (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,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 📄🤘(tiene return) [options: nested(array)]: Si se tiene flujos hijos los implementa
|
// 📄🤘(tiene return) [options: nested(array)]: Si se tiene flujos hijos los implementa
|
||||||
|
|||||||
Reference in New Issue
Block a user