@bot-whatsapp/bot
Advanced tools
Comparing version 0.0.194-alpha.0 to 0.0.195-alpha.0
@@ -174,9 +174,16 @@ const { EventEmitter } = require('node:events') | ||
(flag) => | ||
async (message = null) => { | ||
flag.endFlow = true | ||
endFlowFlag = true | ||
if (message) this.sendProviderAndSave(from, createCtxMessage(message)) | ||
clearQueue() | ||
return | ||
} | ||
async (messages = null) => { | ||
flag.endFlow = true | ||
endFlowFlag = true | ||
if (typeof messages === 'string') { | ||
await this.sendProviderAndSave(from, createCtxMessage(messages)) | ||
} | ||
if (Array.isArray(messages)) { | ||
for (const iterator of messages) { | ||
await resolveCbEveryCtx(iterator, {continue:true}) | ||
} | ||
} | ||
clearQueue() | ||
return | ||
} | ||
@@ -197,5 +204,3 @@ // 📄 Esta funcion se encarga de enviar un array de mensajes dentro de este ctx | ||
const delayMs = ctxMessage?.options?.delay ?? this.generalArgs.delay ?? 0 | ||
if (delayMs) { | ||
await delay(delayMs) // Esperar según el retraso configurado | ||
} | ||
await delay(delayMs) | ||
@@ -261,43 +266,35 @@ //TODO el proceso de forzar cola de procsos | ||
(flag) => | ||
async (message = null) => { | ||
this.queuePrincipal.clearQueue(from) | ||
flag.fallBack = true | ||
await this.sendProviderAndSave(from, { | ||
...prevMsg, | ||
answer: typeof message === 'string' ? message : message?.body ?? prevMsg.answer, | ||
options: { | ||
...prevMsg.options, | ||
buttons: prevMsg.options?.buttons, | ||
}, | ||
}) | ||
return | ||
} | ||
async (message = null) => { | ||
this.queuePrincipal.clearQueue(from) | ||
flag.fallBack = true | ||
await this.sendProviderAndSave(from, { | ||
...prevMsg, | ||
answer: typeof message === 'string' ? message : message?.body ?? prevMsg.answer, | ||
options: { | ||
...prevMsg.options, | ||
buttons: prevMsg.options?.buttons, | ||
}, | ||
}) | ||
return | ||
} | ||
const gotoFlow = | ||
(flag) => | ||
async (flowInstance, step = 0) => { | ||
const promises = [] | ||
flag.gotoFlow = true | ||
const flowTree = flowInstance.toJson() | ||
const flowParentId = flowTree[step] | ||
const parseListMsg = await this.flowClass.find(flowParentId?.ref, true, flowTree) | ||
if (endFlowFlag) return | ||
// await this.sendProviderAndSave(from, createCtxMessage({answer:'__goto_flow__',keyword:flowParentId?.ref})) | ||
for (const msg of parseListMsg) { | ||
const msgParse = this.flowClass.findSerializeByRef(msg?.ref) | ||
const ctxMessage = { ...msgParse, ...msg } | ||
await this.sendProviderAndSave(from, ctxMessage).then(() => { | ||
// this.queuePrincipal.enqueue( | ||
// from, | ||
// () => resolveCbEveryCtx(ctxMessage), | ||
// `cb_${ctxMessage.ref}` | ||
// ) | ||
resolveCbEveryCtx(ctxMessage) | ||
return | ||
}) | ||
async (flowInstance, step = 0) => { | ||
const promises = [] | ||
flag.gotoFlow = true | ||
const flowTree = flowInstance.toJson() | ||
const flowParentId = flowTree[step] | ||
const parseListMsg = await this.flowClass.find(flowParentId?.ref, true, flowTree) | ||
if (endFlowFlag) return | ||
await this.sendProviderAndSave(from, createCtxMessage({ answer: '__goto_flow__', keyword: flowParentId?.ref })) | ||
for (const msg of parseListMsg) { | ||
const msgParse = this.flowClass.findSerializeByRef(msg?.ref) | ||
const ctxMessage = { ...msgParse, ...msg } | ||
await this.sendProviderAndSave(from, ctxMessage).then(() => promises.push(ctxMessage)) | ||
} | ||
await endFlow(flag)(promises) | ||
return | ||
} | ||
// await Promise.all(promises) | ||
await endFlow(flag)() | ||
return | ||
} | ||
@@ -308,24 +305,24 @@ // 📄 [options: flowDynamic]: esta funcion se encarga de responder un array de respuesta esta limitado a 5 mensajes | ||
const flowDynamic = | ||
(flag, inRef) => | ||
async (listMsg = [], options = { continue: true }) => { | ||
if (!options.hasOwnProperty('continue')) options = { ...options, continue: true } | ||
(flag, inRef, privateOptions) => | ||
async (listMsg = [], options = { continue: true }) => { | ||
if (!options.hasOwnProperty('continue')) options = { ...options, continue: true } | ||
flag.flowDynamic = true | ||
if (!Array.isArray(listMsg)) listMsg = [{ body: listMsg, ...options }] | ||
const parseListMsg = listMsg.map((opt, index) => createCtxMessage(opt, index)) | ||
flag.flowDynamic = true | ||
if (!Array.isArray(listMsg)) listMsg = [{ body: listMsg, ...options }] | ||
const parseListMsg = listMsg.map((opt, index) => createCtxMessage(opt, index)) | ||
console.log({ parseListMsg, endFlowFlag }) | ||
if (!privateOptions.continue && endFlowFlag) return | ||
this.queuePrincipal.setFingerTime(from, inRef) //aqui debeo decirle al sistema como que finalizo el flujo | ||
for (const msg of parseListMsg) { | ||
const delayMs = msg?.options?.delay ?? this.generalArgs.delay ?? 0 | ||
await delay(delayMs) | ||
await this.sendProviderAndSave(from, msg) | ||
} | ||
if (endFlowFlag) return | ||
this.queuePrincipal.setFingerTime(from, inRef) //aqui debeo decirle al sistema como que finalizo el flujo | ||
for (const msg of parseListMsg) { | ||
const delayMs = msg?.options?.delay ?? this.generalArgs.delay ?? 0 | ||
if (delayMs) await delay(delayMs) | ||
await this.sendProviderAndSave(from, msg) | ||
if (options?.continue) await continueFlow() | ||
return | ||
} | ||
if (options?.continue) await continueFlow() | ||
return | ||
} | ||
// 📄 Se encarga de revisar si el contexto del mensaje tiene callback o idle | ||
const resolveCbEveryCtx = async (ctxMessage) => { | ||
const resolveCbEveryCtx = async (ctxMessage, options = { continue: false }) => { | ||
if (!!ctxMessage?.options?.idle && !ctxMessage?.options?.capture) { | ||
@@ -336,8 +333,14 @@ printer( | ||
} | ||
if (ctxMessage?.options?.idle) return await cbEveryCtx(ctxMessage?.ref, ctxMessage?.options?.idle) | ||
if (!ctxMessage?.options?.capture) return await cbEveryCtx(ctxMessage?.ref) | ||
if (ctxMessage?.options?.idle) { | ||
await cbEveryCtx(ctxMessage?.ref, { ...options, startIdleMs: ctxMessage?.options?.idle }) | ||
return | ||
} | ||
if (!ctxMessage?.options?.capture) { | ||
await cbEveryCtx(ctxMessage?.ref, options) | ||
return | ||
} | ||
} | ||
// 📄 Se encarga de revisar si el contexto del mensaje tiene callback y ejecutarlo | ||
const cbEveryCtx = async (inRef, startIdleMs = 0) => { | ||
const cbEveryCtx = async (inRef, options = { startIdleMs: 0, continue: false }) => { | ||
const flags = { | ||
@@ -363,3 +366,3 @@ endFlow: false, | ||
fallBack: fallBack(flags), | ||
flowDynamic: flowDynamic(flags, inRef), | ||
flowDynamic: flowDynamic(flags, inRef, options), | ||
endFlow: endFlow(flags), | ||
@@ -380,7 +383,7 @@ gotoFlow: gotoFlow(flags), | ||
if (startIdleMs > 0) { | ||
if (options.startIdleMs > 0) { | ||
idleForCallback.setIdleTime({ | ||
from, | ||
inRef, | ||
timeInSeconds: startIdleMs / 1000, | ||
timeInSeconds: options.startIdleMs / 1000, | ||
cb: async (opts) => { | ||
@@ -521,3 +524,3 @@ endFlowFlag = false | ||
const delayMs = ctxMessage?.options?.delay ?? this.generalArgs.delay ?? 0 | ||
if (delayMs) await delay(delayMs) | ||
await delay(delayMs) | ||
await this.queuePrincipal.enqueue( | ||
@@ -524,0 +527,0 @@ numberOrId, |
{ | ||
"name": "@bot-whatsapp/bot", | ||
"version": "0.0.194-alpha.0", | ||
"version": "0.0.195-alpha.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./lib/bundle.bot.cjs", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
139255
3538