From e331c2dcc40eeb82a93f9d29f6a82333b8465927 Mon Sep 17 00:00:00 2001 From: Leifer Mendez Date: Mon, 26 Dec 2022 20:10:42 +0100 Subject: [PATCH] feat(bot): :zap: http responses support --- README.md | 1 - packages/bot/core/core.class.js | 24 +++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a3d02b7..f9850c0 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ Video como hacer PR: https://youtu.be/Lxt8Acob6aU **Comunidad** - > Forma parte de este proyecto. diff --git a/packages/bot/core/core.class.js b/packages/bot/core/core.class.js index e545a55..91195c8 100644 --- a/packages/bot/core/core.class.js +++ b/packages/bot/core/core.class.js @@ -84,7 +84,7 @@ 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) || [] @@ -92,6 +92,27 @@ class CoreClass { 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) @@ -99,6 +120,7 @@ class CoreClass { messageCtxInComming, { fallBack, + flowDynamic, } ) }