Skip to content

Commit

Permalink
feat(bot): ⚡ http responses support
Browse files Browse the repository at this point in the history
feat(bot): ⚡ http responses support
  • Loading branch information
leifermendez authored Dec 26, 2022
2 parents 9dc1ac5 + e331c2d commit 2d2bb08
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Video como hacer PR: https://youtu.be/Lxt8Acob6aU

**Comunidad**
<!-- readme: collaborators,contributors -start -->

<!-- readme: collaborators,contributors -end -->

> Forma parte de este proyecto.
Expand Down
24 changes: 23 additions & 1 deletion packages/bot/core/core.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,43 @@ class CoreClass {
this.databaseClass.save(ctxByNumber)
}

// 📄 [options: fallback]: esta funcion se encarga de repetir el ultimo mensaje
// 📄 [options: fallBack]: esta funcion se encarga de repetir el ultimo mensaje
const fallBack = () => {
fallBackFlag = true
msgToSend = this.flowClass.find(refToContinue?.keyword, true) || []
this.sendFlow(msgToSend, from)
return refToContinue
}

// 📄 [options: flowDynamic]: esta funcion se encarga de responder un array de respuesta esta limitado a 5 mensajes
// para evitar bloque de whatsapp
const flowDynamic = (listMsg = [], optListMsg = { limit: 3 }) => {
if (!Array.isArray(listMsg))
throw new Error('Esto debe ser un ARRAY')

const parseListMsg = listMsg
.map(({ body }, index) =>
toCtx({
body,
from,
keyword: null,
index,
})
)
.slice(0, optListMsg.limit)
msgToSend = parseListMsg
this.sendFlow(msgToSend, from)
return
}

// 📄 Se encarga de revisar si el contexto del mensaje tiene callback y ejecutarlo
const cbEveryCtx = (inRef) => {
const indexFlow = this.flowClass.findIndexByRef(inRef)
this.flowClass.allCallbacks[indexFlow].callback(
messageCtxInComming,
{
fallBack,
flowDynamic,
}
)
}
Expand Down

0 comments on commit 2d2bb08

Please sign in to comment.