mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-20 04:29:16 +00:00
move io into bot
This commit is contained in:
30
packages/bot/io/flow.class.js
Normal file
30
packages/bot/io/flow.class.js
Normal file
@@ -0,0 +1,30 @@
|
||||
class FlowClass {
|
||||
flow
|
||||
constructor(_flow) {
|
||||
this.flow = _flow
|
||||
}
|
||||
|
||||
find = (keyOrWord, symbol = false) => {
|
||||
let messages = []
|
||||
const findIn = (keyOrWord, symbol = false, flow = this.flow) => {
|
||||
if (symbol) {
|
||||
const refSymbol = flow.find((c) => c.keyword === keyOrWord)
|
||||
if (refSymbol && refSymbol.answer)
|
||||
messages.push(refSymbol.answer)
|
||||
if (refSymbol && refSymbol.ref) findIn(refSymbol.ref, true)
|
||||
} else {
|
||||
const refSymbolByKeyworkd = flow.find((c) =>
|
||||
c.keyword.includes(keyOrWord)
|
||||
)
|
||||
if (refSymbolByKeyworkd && refSymbolByKeyworkd.ref)
|
||||
findIn(refSymbolByKeyworkd.ref, true)
|
||||
|
||||
return messages
|
||||
}
|
||||
}
|
||||
findIn(keyOrWord, symbol)
|
||||
return messages
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FlowClass
|
||||
Reference in New Issue
Block a user