mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-20 20:49:15 +00:00
test: 🔥 a lot test e2e
This commit is contained in:
@@ -142,8 +142,19 @@ class CoreClass {
|
||||
const nextFlow = (await this.flowClass.find(refToContinue?.ref, true)) ?? []
|
||||
const filterNextFlow = nextFlow.filter((msg) => msg.refSerialize !== currentPrev?.refSerialize)
|
||||
const isContinueFlow = filterNextFlow.map((i) => i.keyword).includes(currentPrev?.ref)
|
||||
if (!isContinueFlow) await sendFlow(filterNextFlow, from, { prev: undefined })
|
||||
return
|
||||
|
||||
if (!isContinueFlow) {
|
||||
const refToContinueChild = this.flowClass.getRefToContinueChild(currentPrev?.keyword)
|
||||
const flowStandaloneChild = this.flowClass.getFlowsChild()
|
||||
const nextChildMessages =
|
||||
(await this.flowClass.find(refToContinueChild?.ref, true, flowStandaloneChild)) || []
|
||||
if (nextChildMessages?.length) return await sendFlow(nextChildMessages, from, { prev: undefined })
|
||||
}
|
||||
|
||||
if (!isContinueFlow) {
|
||||
await sendFlow(filterNextFlow, from, { prev: undefined })
|
||||
return
|
||||
}
|
||||
}
|
||||
// 📄 [options: fallBack]: esta funcion se encarga de repetir el ultimo mensaje
|
||||
const fallBack =
|
||||
|
||||
@@ -59,6 +59,37 @@ class FlowClass {
|
||||
findBySerialize = (refSerialize) => this.flowSerialize.find((r) => r.refSerialize === refSerialize)
|
||||
|
||||
findIndexByRef = (ref) => this.flowSerialize.findIndex((r) => r.ref === ref)
|
||||
|
||||
getRefToContinueChild = (keyword) => {
|
||||
try {
|
||||
const flowChilds = this.flowSerialize
|
||||
.reduce((acc, cur) => {
|
||||
const merge = [...acc, cur?.options?.nested].flat(2)
|
||||
return merge
|
||||
}, [])
|
||||
.filter((i) => !!i && i?.refSerialize === keyword)
|
||||
.shift()
|
||||
|
||||
return flowChilds
|
||||
} catch (e) {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
getFlowsChild = () => {
|
||||
try {
|
||||
const flowChilds = this.flowSerialize
|
||||
.reduce((acc, cur) => {
|
||||
const merge = [...acc, cur?.options?.nested].flat(2)
|
||||
return merge
|
||||
}, [])
|
||||
.filter((i) => !!i)
|
||||
|
||||
return flowChilds
|
||||
} catch (e) {
|
||||
return []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FlowClass
|
||||
|
||||
@@ -23,6 +23,8 @@ class ProviderClass extends EventEmitter {
|
||||
if (NODE_ENV !== 'production') console.log('[sendMessage]', { userId, message })
|
||||
return message
|
||||
}
|
||||
|
||||
getInstance = () => this.vendor
|
||||
}
|
||||
|
||||
module.exports = ProviderClass
|
||||
|
||||
Reference in New Issue
Block a user