mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-18 03:29:15 +00:00
@@ -18,6 +18,7 @@ class CoreClass {
|
||||
flowClass
|
||||
databaseClass
|
||||
providerClass
|
||||
listCallbacks = []
|
||||
constructor(_flow, _database, _provider) {
|
||||
this.flowClass = _flow
|
||||
this.databaseClass = _database
|
||||
@@ -105,6 +106,7 @@ class CoreClass {
|
||||
from,
|
||||
keyword: null,
|
||||
index,
|
||||
options: prevMsg?.options ?? {},
|
||||
})
|
||||
)
|
||||
.slice(0, optListMsg.limit)
|
||||
@@ -114,18 +116,24 @@ class CoreClass {
|
||||
}
|
||||
|
||||
// 📄 Se encarga de revisar si el contexto del mensaje tiene callback y ejecutarlo
|
||||
const cbEveryCtx = (inRef) => {
|
||||
this.flowClass.allCallbacks[inRef](messageCtxInComming, {
|
||||
fallBack,
|
||||
flowDynamic,
|
||||
})
|
||||
}
|
||||
const cbEveryCtx =
|
||||
(inRef, _injectMessageCtx, _injectfallBack, _injectflowDynamic) =>
|
||||
() => {
|
||||
this.flowClass.allCallbacks[inRef](_injectMessageCtx, {
|
||||
fallBack: _injectfallBack,
|
||||
flowDynamic: _injectflowDynamic,
|
||||
})
|
||||
}
|
||||
|
||||
// 📄 [options: callback]: Si se tiene un callback se ejecuta
|
||||
if (!fallBackFlag) {
|
||||
if (refToContinue?.options?.capture) cbEveryCtx(refToContinue?.ref)
|
||||
for (const ite of this.flowClass.find(body)) {
|
||||
if (!ite?.options?.capture) cbEveryCtx(ite?.ref)
|
||||
const callAllCb = (_msgToList = []) => {
|
||||
for (const ite of _msgToList) {
|
||||
this.listCallbacks[ite?.ref] = cbEveryCtx(
|
||||
ite?.ref,
|
||||
messageCtxInComming,
|
||||
fallBack,
|
||||
flowDynamic
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,10 +146,7 @@ class CoreClass {
|
||||
|
||||
msgToSend = this.flowClass.find(body, false, flowStandalone) || []
|
||||
|
||||
for (const ite of msgToSend) {
|
||||
cbEveryCtx(ite?.ref)
|
||||
}
|
||||
|
||||
callAllCb(msgToSend)
|
||||
this.sendFlow(msgToSend, from)
|
||||
return
|
||||
}
|
||||
@@ -153,12 +158,14 @@ class CoreClass {
|
||||
|
||||
if (['string', 'boolean'].includes(typeCapture) && valueCapture) {
|
||||
msgToSend = this.flowClass.find(refToContinue?.ref, true) || []
|
||||
callAllCb(msgToSend)
|
||||
this.sendFlow(msgToSend, from)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
msgToSend = this.flowClass.find(body) || []
|
||||
callAllCb(msgToSend)
|
||||
this.sendFlow(msgToSend, from)
|
||||
}
|
||||
|
||||
@@ -169,10 +176,19 @@ class CoreClass {
|
||||
* @returns
|
||||
*/
|
||||
sendProviderAndSave = (numberOrId, ctxMessage) => {
|
||||
const executeCb = (ref) => {
|
||||
try {
|
||||
return this.listCallbacks[ref]()
|
||||
} catch (e) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
const { answer } = ctxMessage
|
||||
return Promise.all([
|
||||
this.providerClass.sendMessage(numberOrId, answer, ctxMessage),
|
||||
this.databaseClass.save({ ...ctxMessage, from: numberOrId }),
|
||||
executeCb(ctxMessage?.ref),
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bot-whatsapp/bot",
|
||||
"version": "0.0.41-alpha.0",
|
||||
"version": "0.0.42-alpha.0",
|
||||
"description": "",
|
||||
"main": "./lib/bundle.bot.cjs",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bot-whatsapp/cli",
|
||||
"version": "0.0.48-alpha.0",
|
||||
"version": "0.0.49-alpha.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "create-bot-whatsapp",
|
||||
"version": "0.0.59-alpha.0",
|
||||
"version": "0.0.60-alpha.0",
|
||||
"description": "",
|
||||
"main": "./lib/bundle.create-bot-whatsapp.cjs",
|
||||
"files": [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bot-whatsapp/database",
|
||||
"version": "0.0.40-alpha.0",
|
||||
"version": "0.0.41-alpha.0",
|
||||
"description": "Esto es el conector a mysql, pg, mongo",
|
||||
"main": "./lib/mock/index.cjs",
|
||||
"keywords": [],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bot-whatsapp/provider",
|
||||
"version": "0.0.46-alpha.0",
|
||||
"version": "0.0.47-alpha.0",
|
||||
"description": "Esto es el conector a Twilio, Meta, etc...",
|
||||
"main": "./lib/mock/index.cjs",
|
||||
"keywords": [],
|
||||
|
||||
Reference in New Issue
Block a user