Skip to content

Commit

Permalink
feat(bot): ⚡ flowDynamic buttons, media
Browse files Browse the repository at this point in the history
  • Loading branch information
leifermendez committed Jan 23, 2023
1 parent 79cc31a commit 3c4b1c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions packages/bot/core/core.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/bot/io/methods/toCtx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
}
Expand Down

0 comments on commit 3c4b1c0

Please # to comment.