mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-20 12:39:24 +00:00
Merge pull request #526 from codigoencasa/506-concatenación-flowdynamic
506 concatenación flowdynamic
This commit is contained in:
@@ -117,6 +117,7 @@ class CoreClass {
|
|||||||
|
|
||||||
// 📄 [options: flowDynamic]: esta funcion se encarga de responder un array de respuesta esta limitado a 5 mensajes
|
// 📄 [options: flowDynamic]: esta funcion se encarga de responder un array de respuesta esta limitado a 5 mensajes
|
||||||
// para evitar bloque de whatsapp
|
// para evitar bloque de whatsapp
|
||||||
|
|
||||||
const flowDynamic = async (
|
const flowDynamic = async (
|
||||||
listMsg = [],
|
listMsg = [],
|
||||||
optListMsg = { limit: 5, fallback: false }
|
optListMsg = { limit: 5, fallback: false }
|
||||||
@@ -126,15 +127,21 @@ class CoreClass {
|
|||||||
|
|
||||||
fallBackFlag = optListMsg.fallback
|
fallBackFlag = optListMsg.fallback
|
||||||
const parseListMsg = listMsg
|
const parseListMsg = listMsg
|
||||||
.map(({ body }, index) =>
|
.map((opt, index) => {
|
||||||
toCtx({
|
const body = typeof opt === 'string' ? opt : opt.body
|
||||||
|
const media = opt?.media ?? null
|
||||||
|
const buttons = opt?.buttons ?? []
|
||||||
|
|
||||||
|
return toCtx({
|
||||||
body,
|
body,
|
||||||
from,
|
from,
|
||||||
keyword: null,
|
keyword: null,
|
||||||
index,
|
index,
|
||||||
|
options: { media, buttons },
|
||||||
})
|
})
|
||||||
)
|
})
|
||||||
.slice(0, optListMsg.limit)
|
.slice(0, optListMsg.limit)
|
||||||
|
|
||||||
for (const msg of parseListMsg) {
|
for (const msg of parseListMsg) {
|
||||||
await this.sendProviderAndSave(from, msg)
|
await this.sendProviderAndSave(from, msg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ const { generateRef, generateRefSerialize } = require('../../utils/hash')
|
|||||||
* @param options {media:string, buttons:[], capture:true default false}
|
* @param options {media:string, buttons:[], capture:true default false}
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
const toCtx = ({ body, from, prevRef, index }) => {
|
const toCtx = ({ body, from, prevRef, options = {}, index }) => {
|
||||||
return {
|
return {
|
||||||
ref: generateRef(),
|
ref: generateRef(),
|
||||||
keyword: prevRef,
|
keyword: prevRef,
|
||||||
answer: body,
|
answer: body,
|
||||||
options: {},
|
options: options ?? {},
|
||||||
from,
|
from,
|
||||||
refSerialize: generateRefSerialize({ index, answer: body }),
|
refSerialize: generateRefSerialize({ index, answer: body }),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user