@bot-whatsapp/bot
Advanced tools
Comparing version 0.0.165-alpha.0 to 0.0.166-alpha.0
@@ -175,3 +175,3 @@ const { toCtx } = require('../io/methods') | ||
// 📄 Esta funcion se encarga de enviar un array de mensajes dentro de este ctx | ||
const sendFlow = async (messageToSend, numberOrId, options = { prev: prevMsg }) => { | ||
const sendFlow = async (messageToSend, numberOrId, options = { prev: prevMsg, forceQueue: false }) => { | ||
if (options.prev?.options?.capture) { | ||
@@ -190,12 +190,29 @@ await cbEveryCtx(options.prev?.ref) | ||
} | ||
this.queuePrincipal.setFingerTime(from, generateTime()) | ||
logger.log(`[sendQueue_A]: `, ctxMessage) | ||
//TODO el proceso de forzar cola de procsos | ||
if (options?.forceQueue) { | ||
const listIdsRefCallbacks = messageToSend.map((i) => i.ref) | ||
const listProcessWait = this.queuePrincipal.getIdsCallbacs(from) | ||
if (!listProcessWait.length) { | ||
this.queuePrincipal.setIdsCallbacks(from, listIdsRefCallbacks) | ||
} else { | ||
this.queuePrincipal.clearQueue(from) | ||
const lastMessage = messageToSend[messageToSend.length - 1] | ||
await this.databaseClass.save({ ...lastMessage, from: numberOrId }) | ||
if (listProcessWait.includes(lastMessage.ref)) return | ||
} | ||
} | ||
try { | ||
await this.queuePrincipal.enqueue(from, async () => { | ||
// Usar async en la función pasada a enqueue | ||
await this.sendProviderAndSave(numberOrId, ctxMessage) | ||
logger.log(`[QUEUE_SE_ENVIO]: `, ctxMessage) | ||
await resolveCbEveryCtx(ctxMessage) | ||
}, generateTime()) | ||
await this.queuePrincipal.enqueue( | ||
from, | ||
async () => { | ||
// Usar async en la función pasada a enqueue | ||
await this.sendProviderAndSave(numberOrId, ctxMessage) | ||
logger.log(`[QUEUE_SE_ENVIO]: `, ctxMessage) | ||
await resolveCbEveryCtx(ctxMessage) | ||
}, | ||
ctxMessage.ref | ||
) | ||
} catch (error) { | ||
@@ -210,3 +227,3 @@ logger.error(`Error al encolar: ${error.message}`) | ||
const continueFlow = async () => { | ||
const continueFlow = async (_) => { | ||
const currentPrev = await this.databaseClass.getPrevByNumber(from) | ||
@@ -223,6 +240,4 @@ const nextFlow = (await this.flowClass.find(refToContinue?.ref, true)) ?? [] | ||
if (nextChildMessages?.length) return await sendFlow(nextChildMessages, from, { prev: undefined }) | ||
} | ||
if (!isContinueFlow) { | ||
await sendFlow(filterNextFlow, from, { prev: undefined }) | ||
await sendFlow(filterNextFlow, from, { prev: undefined, forceQueue: true }) | ||
return | ||
@@ -277,3 +292,3 @@ } | ||
if (endFlowFlag) return | ||
this.queuePrincipal.setFingerTime(from, generateTime()) | ||
this.queuePrincipal.setFingerTime(from, generateTime()) //aqui debeo decirle al sistema como que finalizo el flujo | ||
for (const msg of parseListMsg) { | ||
@@ -285,3 +300,3 @@ const delayMs = msg?.options?.delay ?? this.generalArgs.delay ?? 0 | ||
if (options?.continue) await continueFlow() | ||
if (options?.continue) await continueFlow(generateTime()) | ||
return | ||
@@ -324,3 +339,3 @@ } | ||
const ifContinue = !flags.endFlow && !flags.fallBack && !flags.flowDynamic | ||
if (ifContinue) await continueFlow() | ||
if (ifContinue) await continueFlow(prevMsg?.options?.nested?.length) | ||
@@ -431,3 +446,7 @@ return | ||
if (delayMs) await delay(delayMs) | ||
await this.queuePrincipal.enqueue(numberOrId, () => this.sendProviderAndSave(numberOrId, ctxMessage), generateTime()) | ||
await this.queuePrincipal.enqueue( | ||
numberOrId, | ||
() => this.sendProviderAndSave(numberOrId, ctxMessage), | ||
generateTime() | ||
) | ||
// await queuePromises.dequeue() | ||
@@ -434,0 +453,0 @@ } |
{ | ||
"name": "@bot-whatsapp/bot", | ||
"version": "0.0.165-alpha.0", | ||
"version": "0.0.166-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
117579
3081