mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-18 03:29:15 +00:00
build: ⚡ fix
build: ⚡ fix
This commit is contained in:
@@ -18,7 +18,6 @@ class CoreClass {
|
||||
flowClass
|
||||
databaseClass
|
||||
providerClass
|
||||
listCallbacks = []
|
||||
constructor(_flow, _database, _provider) {
|
||||
this.flowClass = _flow
|
||||
this.databaseClass = _database
|
||||
@@ -106,7 +105,6 @@ class CoreClass {
|
||||
from,
|
||||
keyword: null,
|
||||
index,
|
||||
options: prevMsg?.options ?? {},
|
||||
})
|
||||
)
|
||||
.slice(0, optListMsg.limit)
|
||||
@@ -116,24 +114,18 @@ class CoreClass {
|
||||
}
|
||||
|
||||
// 📄 Se encarga de revisar si el contexto del mensaje tiene callback y ejecutarlo
|
||||
const cbEveryCtx =
|
||||
(inRef, _injectMessageCtx, _injectfallBack, _injectflowDynamic) =>
|
||||
() => {
|
||||
this.flowClass.allCallbacks[inRef](_injectMessageCtx, {
|
||||
fallBack: _injectfallBack,
|
||||
flowDynamic: _injectflowDynamic,
|
||||
})
|
||||
}
|
||||
const cbEveryCtx = (inRef) => {
|
||||
this.flowClass.allCallbacks[inRef](messageCtxInComming, {
|
||||
fallBack,
|
||||
flowDynamic,
|
||||
})
|
||||
}
|
||||
|
||||
// 📄 [options: callback]: Si se tiene un callback se ejecuta
|
||||
const callAllCb = (_msgToList = []) => {
|
||||
for (const ite of _msgToList) {
|
||||
this.listCallbacks[ite?.ref] = cbEveryCtx(
|
||||
ite?.ref,
|
||||
messageCtxInComming,
|
||||
fallBack,
|
||||
flowDynamic
|
||||
)
|
||||
if (!fallBackFlag) {
|
||||
if (prevMsg?.options?.capture) cbEveryCtx(prevMsg?.ref)
|
||||
for (const ite of this.flowClass.find(body)) {
|
||||
if (!ite?.options?.capture) cbEveryCtx(ite?.ref)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +138,10 @@ class CoreClass {
|
||||
|
||||
msgToSend = this.flowClass.find(body, false, flowStandalone) || []
|
||||
|
||||
callAllCb(msgToSend)
|
||||
for (const ite of msgToSend) {
|
||||
cbEveryCtx(ite?.ref)
|
||||
}
|
||||
|
||||
this.sendFlow(msgToSend, from)
|
||||
return
|
||||
}
|
||||
@@ -158,14 +153,12 @@ 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)
|
||||
}
|
||||
|
||||
@@ -176,19 +169,10 @@ 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.43-alpha.0",
|
||||
"version": "0.0.44-alpha.0",
|
||||
"description": "",
|
||||
"main": "./lib/bundle.bot.cjs",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bot-whatsapp/cli",
|
||||
"version": "0.0.50-alpha.0",
|
||||
"version": "0.0.51-alpha.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"devDependencies": {
|
||||
|
||||
@@ -97,13 +97,21 @@ class DialogFlowContext extends CoreClass {
|
||||
})
|
||||
|
||||
customPayload = {
|
||||
media: fields?.media?.stringValue,
|
||||
buttons: mapButtons,
|
||||
options: {
|
||||
media: fields?.media?.stringValue,
|
||||
buttons: mapButtons,
|
||||
},
|
||||
}
|
||||
|
||||
const ctxFromDX = {
|
||||
...customPayload,
|
||||
answer: fields?.answer?.stringValue,
|
||||
}
|
||||
this.sendFlow([ctxFromDX], from)
|
||||
return
|
||||
}
|
||||
|
||||
const ctxFromDX = {
|
||||
...customPayload,
|
||||
answer: queryResult?.fulfillmentText,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "create-bot-whatsapp",
|
||||
"version": "0.0.61-alpha.0",
|
||||
"version": "0.0.62-alpha.0",
|
||||
"description": "",
|
||||
"main": "./lib/bundle.create-bot-whatsapp.cjs",
|
||||
"files": [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bot-whatsapp/database",
|
||||
"version": "0.0.42-alpha.0",
|
||||
"version": "0.0.43-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.48-alpha.0",
|
||||
"version": "0.0.49-alpha.0",
|
||||
"description": "Esto es el conector a Twilio, Meta, etc...",
|
||||
"main": "./lib/mock/index.cjs",
|
||||
"keywords": [],
|
||||
|
||||
@@ -4,7 +4,7 @@ const pino = require('pino')
|
||||
const rimraf = require('rimraf')
|
||||
const mime = require('mime-types')
|
||||
const { join } = require('path')
|
||||
const { existsSync, createWriteStream } = require('fs')
|
||||
const { existsSync, createWriteStream, readFileSync } = require('fs')
|
||||
const { Console } = require('console')
|
||||
|
||||
const {
|
||||
@@ -137,7 +137,7 @@ class BaileysProvider extends ProviderClass {
|
||||
}
|
||||
|
||||
const btnCtx =
|
||||
payload?.message?.templateButtonReplyMessage
|
||||
payload?.message?.buttonsResponseMessage
|
||||
?.selectedDisplayText
|
||||
|
||||
if (btnCtx) payload.body = btnCtx
|
||||
@@ -167,8 +167,8 @@ class BaileysProvider extends ProviderClass {
|
||||
sendMedia = async (number, imageUrl, text) => {
|
||||
const fileDownloaded = await baileyDownloadMedia(imageUrl)
|
||||
return this.vendor.sendMessage(number, {
|
||||
image: { url: fileDownloaded },
|
||||
text,
|
||||
image: readFileSync(fileDownloaded),
|
||||
caption: text,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -229,20 +229,22 @@ class BaileysProvider extends ProviderClass {
|
||||
*/
|
||||
|
||||
sendButtons = async (number, text, buttons) => {
|
||||
const numberClean = number.replace('+', '')
|
||||
const numberClean = baileyCleanNumber(number)
|
||||
|
||||
const templateButtons = buttons.map((btn, i) => ({
|
||||
index: `${i}`,
|
||||
quickReplyButton: {
|
||||
displayText: btn.body,
|
||||
id: `id-btn-${i}`,
|
||||
},
|
||||
buttonId: `id-btn-${i}`,
|
||||
buttonText: { displayText: btn.body },
|
||||
type: 1,
|
||||
}))
|
||||
|
||||
return this.vendor.sendMessage(`${numberClean}@c.us`, {
|
||||
const buttonMessage = {
|
||||
text,
|
||||
footer: '',
|
||||
templateButtons: templateButtons,
|
||||
})
|
||||
buttons: templateButtons,
|
||||
headerType: 1,
|
||||
}
|
||||
|
||||
return this.vendor.sendMessage(numberClean, buttonMessage)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user