From 3c4b1c0fc4b6d98d67c67806d918d3604bb2209b Mon Sep 17 00:00:00 2001 From: Leifer Mendez Date: Mon, 23 Jan 2023 11:52:49 +0100 Subject: [PATCH] feat(bot): :zap: flowDynamic buttons, media --- packages/bot/core/core.class.js | 13 ++++++++++--- packages/bot/io/methods/toCtx.js | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/bot/core/core.class.js b/packages/bot/core/core.class.js index ea5eff3..3f20b7b 100644 --- a/packages/bot/core/core.class.js +++ b/packages/bot/core/core.class.js @@ -117,6 +117,7 @@ class CoreClass { // 📄 [options: flowDynamic]: esta funcion se encarga de responder un array de respuesta esta limitado a 5 mensajes // para evitar bloque de whatsapp + const flowDynamic = async ( listMsg = [], optListMsg = { limit: 5, fallback: false } @@ -126,15 +127,21 @@ class CoreClass { fallBackFlag = optListMsg.fallback const parseListMsg = listMsg - .map(({ body }, index) => - toCtx({ + .map((opt, index) => { + const body = typeof opt === 'string' ? opt : opt.body + const media = opt?.media ?? null + const buttons = opt?.buttons ?? [] + + return toCtx({ body, from, keyword: null, index, + options: { media, buttons }, }) - ) + }) .slice(0, optListMsg.limit) + for (const msg of parseListMsg) { await this.sendProviderAndSave(from, msg) } diff --git a/packages/bot/io/methods/toCtx.js b/packages/bot/io/methods/toCtx.js index d29295e..980cbfb 100644 --- a/packages/bot/io/methods/toCtx.js +++ b/packages/bot/io/methods/toCtx.js @@ -5,12 +5,12 @@ const { generateRef, generateRefSerialize } = require('../../utils/hash') * @param options {media:string, buttons:[], capture:true default false} * @returns */ -const toCtx = ({ body, from, prevRef, index }) => { +const toCtx = ({ body, from, prevRef, options = {}, index }) => { return { ref: generateRef(), keyword: prevRef, answer: body, - options: {}, + options: options ?? {}, from, refSerialize: generateRefSerialize({ index, answer: body }), }