mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-20 20:49:15 +00:00
build: ⚡ working fallback, flowDynamic
This commit is contained in:
@@ -18,7 +18,6 @@ class CoreClass {
|
|||||||
flowClass
|
flowClass
|
||||||
databaseClass
|
databaseClass
|
||||||
providerClass
|
providerClass
|
||||||
listCallbacks = []
|
|
||||||
constructor(_flow, _database, _provider) {
|
constructor(_flow, _database, _provider) {
|
||||||
this.flowClass = _flow
|
this.flowClass = _flow
|
||||||
this.databaseClass = _database
|
this.databaseClass = _database
|
||||||
@@ -106,7 +105,6 @@ class CoreClass {
|
|||||||
from,
|
from,
|
||||||
keyword: null,
|
keyword: null,
|
||||||
index,
|
index,
|
||||||
options: prevMsg?.options ?? {},
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.slice(0, optListMsg.limit)
|
.slice(0, optListMsg.limit)
|
||||||
@@ -116,24 +114,18 @@ class CoreClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 📄 Se encarga de revisar si el contexto del mensaje tiene callback y ejecutarlo
|
// 📄 Se encarga de revisar si el contexto del mensaje tiene callback y ejecutarlo
|
||||||
const cbEveryCtx =
|
const cbEveryCtx = (inRef) => {
|
||||||
(inRef, _injectMessageCtx, _injectfallBack, _injectflowDynamic) =>
|
this.flowClass.allCallbacks[inRef](messageCtxInComming, {
|
||||||
() => {
|
fallBack,
|
||||||
this.flowClass.allCallbacks[inRef](_injectMessageCtx, {
|
flowDynamic,
|
||||||
fallBack: _injectfallBack,
|
})
|
||||||
flowDynamic: _injectflowDynamic,
|
}
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 📄 [options: callback]: Si se tiene un callback se ejecuta
|
// 📄 [options: callback]: Si se tiene un callback se ejecuta
|
||||||
const callAllCb = (_msgToList = []) => {
|
if (!fallBackFlag) {
|
||||||
for (const ite of _msgToList) {
|
if (prevMsg?.options?.capture) cbEveryCtx(prevMsg?.ref)
|
||||||
this.listCallbacks[ite?.ref] = cbEveryCtx(
|
for (const ite of this.flowClass.find(body)) {
|
||||||
ite?.ref,
|
if (!ite?.options?.capture) cbEveryCtx(ite?.ref)
|
||||||
messageCtxInComming,
|
|
||||||
fallBack,
|
|
||||||
flowDynamic
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +138,10 @@ class CoreClass {
|
|||||||
|
|
||||||
msgToSend = this.flowClass.find(body, false, flowStandalone) || []
|
msgToSend = this.flowClass.find(body, false, flowStandalone) || []
|
||||||
|
|
||||||
callAllCb(msgToSend)
|
for (const ite of msgToSend) {
|
||||||
|
cbEveryCtx(ite?.ref)
|
||||||
|
}
|
||||||
|
|
||||||
this.sendFlow(msgToSend, from)
|
this.sendFlow(msgToSend, from)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -158,14 +153,12 @@ class CoreClass {
|
|||||||
|
|
||||||
if (['string', 'boolean'].includes(typeCapture) && valueCapture) {
|
if (['string', 'boolean'].includes(typeCapture) && valueCapture) {
|
||||||
msgToSend = this.flowClass.find(refToContinue?.ref, true) || []
|
msgToSend = this.flowClass.find(refToContinue?.ref, true) || []
|
||||||
callAllCb(msgToSend)
|
|
||||||
this.sendFlow(msgToSend, from)
|
this.sendFlow(msgToSend, from)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
msgToSend = this.flowClass.find(body) || []
|
msgToSend = this.flowClass.find(body) || []
|
||||||
callAllCb(msgToSend)
|
|
||||||
this.sendFlow(msgToSend, from)
|
this.sendFlow(msgToSend, from)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,19 +169,10 @@ class CoreClass {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
sendProviderAndSave = (numberOrId, ctxMessage) => {
|
sendProviderAndSave = (numberOrId, ctxMessage) => {
|
||||||
const executeCb = (ref) => {
|
|
||||||
try {
|
|
||||||
return this.listCallbacks[ref]()
|
|
||||||
} catch (e) {
|
|
||||||
return Promise.resolve()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const { answer } = ctxMessage
|
const { answer } = ctxMessage
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
this.providerClass.sendMessage(numberOrId, answer, ctxMessage),
|
this.providerClass.sendMessage(numberOrId, answer, ctxMessage),
|
||||||
this.databaseClass.save({ ...ctxMessage, from: numberOrId }),
|
this.databaseClass.save({ ...ctxMessage, from: numberOrId }),
|
||||||
executeCb(ctxMessage?.ref),
|
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user