almost work it

This commit is contained in:
Leifer Mendez
2022-11-22 21:45:00 +01:00
parent c40c0c54bd
commit 368bf29e63
4 changed files with 52 additions and 27 deletions

View File

@@ -50,7 +50,13 @@ class CoreClass {
handleMsg = async (messageInComming) => {
const { body, from } = messageInComming
let msgToSend = []
//Consultamos mensaje previo en DB
const prevMsg = await this.databaseClass.getPrevByNumber(from)
//Consultamos for refSerializada en el flow actual
const refToContinue = this.flowClass.findBySerialize(
prevMsg?.refSerialize
)
if (prevMsg?.ref) {
const ctxByNumber = toCtx({
@@ -61,26 +67,32 @@ class CoreClass {
this.databaseClass.save(ctxByNumber)
}
if (prevMsg?.refSerialize && prevMsg?.options?.capture) {
const refToContinue = this.flowClass.findBySerialize(
prevMsg.refSerialize
)
//Si se tiene un callback se ejecuta
if (refToContinue && prevMsg?.options?.callback) {
const indexFlow = this.flowClass.findIndexByRef(refToContinue?.ref)
this.flowClass.allCallbacks[indexFlow].callback(messageInComming)
}
if (refToContinue && prevMsg?.options?.callback) {
const indexFlow = this.flowClass.findIndexByRef(
refToContinue?.ref
)
//Si se tiene anidaciones de flows, si tienes anidados obligatoriamente capture:true
if (prevMsg?.options?.nested?.length) {
const nestedRef = prevMsg.options.nested
const flowStandalone = nestedRef.map((f) => ({
...this.flowClass.findBySerialize(f),
}))
this.flowClass.allCallbacks[indexFlow].callback(
messageInComming
)
}
msgToSend = this.flowClass.find(body, false, flowStandalone) || []
this.sendFlow(msgToSend, from)
return
}
//Consultamos si se espera respuesta por parte de cliente "Ejemplo: Dime tu nombre"
if (!prevMsg?.options?.nested?.length && prevMsg?.options?.capture) {
msgToSend = this.flowClass.find(refToContinue?.ref, true) || []
} else {
msgToSend = this.flowClass.find(body) || []
}
if (Array.isArray(msgToSend)) this.sendFlow(msgToSend, from)
this.sendFlow(msgToSend, from)
}
sendProviderAndSave = (numberOrId, ctxMessage) => {