Skip to content

Commit

Permalink
chore: release js after ts
Browse files Browse the repository at this point in the history
  • Loading branch information
leifermendez committed Jan 22, 2024
1 parent f47ef59 commit c9ba66e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bot-whatsapp/root",
"version": "0.1.34",
"version": "0.1.35",
"description": "Bot de wahtsapp open source para MVP o pequeños negocios",
"main": "app.js",
"private": true,
Expand Down
14 changes: 11 additions & 3 deletions packages/bot/context/idleState.class.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
class IdleState {
indexCb = new Map()

/**
*
* @param param0
*/
setIdleTime = ({ from, inRef, timeInSeconds, cb }) => {
cb = cb ?? (() => {})
const startTime = new Date().getTime()
Expand Down Expand Up @@ -33,7 +37,7 @@ class IdleState {

/**
*
* @param {*} param0
* @param param0
* @returns
*/
get = ({ from, inRef }) => {
Expand All @@ -47,15 +51,19 @@ class IdleState {
}
}

/**
*
* @param ctxInComming
*/
stop = (ctxInComming) => {
try {
const queueCb = this.indexCb.get(ctxInComming.from) ?? []
for (const iterator of queueCb) {
iterator.stop(ctxInComming)
}
this.indexCb.set(ctxInComming.from, [])
} catch (err) {
console.log(err)
return null
console.error(err)
}
}
}
Expand Down
17 changes: 13 additions & 4 deletions packages/bot/core/core.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,19 @@ class CoreClass extends EventEmitter {

const continueFlow = async (initRef = undefined) => {
const currentPrev = await this.databaseClass.getPrevByNumber(from)
let nextFlow = (await this.flowClass.find(refToContinue?.ref, true)) ?? []

let nextFlow = this.flowClass.find(refToContinue?.ref, true) || []
if (initRef && !initRef?.idleFallBack) {
nextFlow = (await this.flowClass.find(initRef?.ref, true)) ?? []
nextFlow = this.flowClass.find(initRef?.ref, true) || []
}

const filterNextFlow = nextFlow.filter((msg) => msg.refSerialize !== currentPrev?.refSerialize)
const getContinueIndex = nextFlow.findIndex((msg) => msg.refSerialize === currentPrev?.refSerialize)
const indexToContinue = getContinueIndex !== -1 ? getContinueIndex : 0
const filterNextFlow = nextFlow
.slice(indexToContinue)
.filter((i) => i.refSerialize !== currentPrev?.refSerialize)

// const filterNextFlow = nextFlow.filter((msg) => msg.refSerialize !== currentPrev?.refSerialize);
const isContinueFlow = filterNextFlow.map((i) => i.keyword).includes(currentPrev?.ref)

if (!isContinueFlow) {
Expand Down Expand Up @@ -482,7 +489,9 @@ class CoreClass extends EventEmitter {
inRef,
timeInSeconds: options.startIdleMs / 1000,
cb: async (opts) => {
await runContext(true, { idleFallBack: opts.next, ref: opts.inRef, body: opts.body })
if (opts?.next) {
await runContext(true, { idleFallBack: opts.next, ref: opts.inRef, body: opts.body })
}
},
})
return
Expand Down
2 changes: 1 addition & 1 deletion packages/bot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bot-whatsapp/bot",
"version": "0.0.223-alpha.0",
"version": "0.0.226-alpha.0",
"description": "",
"main": "./lib/bundle.bot.cjs",
"scripts": {
Expand Down

0 comments on commit c9ba66e

Please sign in to comment.