restore flow working!

This commit is contained in:
Leifer Mendez
2022-11-18 19:55:57 +01:00
parent e3664cc973
commit 6953c954a8
10 changed files with 101 additions and 27 deletions

View File

@@ -1,4 +1,4 @@
const { validateCtx } = require('../io/methods')
const { toCtx } = require('../io/methods')
const { printer } = require('../utils/interactive')
/**
@@ -51,8 +51,20 @@ class CoreClass {
let msgToSend = []
const prevMsg = await this.databaseClass.getPrevByNumber(from)
if (prevMsg?.ref && prevMsg?.options?.capture) {
msgToSend = this.flowClass.find(prevMsg.ref, true) || []
if (prevMsg?.ref) {
const ctxByNumber = toCtx({
body,
from,
prevRef: prevMsg.refSerialize,
})
this.databaseClass.save(ctxByNumber)
}
if (prevMsg?.refSerialize && prevMsg?.options?.capture) {
const refToContinue = this.flowClass.findBySerialize(
prevMsg.refSerialize
)
msgToSend = this.flowClass.find(refToContinue?.ref, true) || []
} else {
msgToSend = this.flowClass.find(body) || []
}