D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
etb1lp46s9ed
/
washeet.softurecs.com
/
server
/
dto
/
Filename :
list.js
back
Copy
import { ulid } from "ulid"; import { prepareMediaMessage } from "../lib/helper.js"; class Row { constructor(props) { Object.assign(this, props); if (!this.id) { this.id = ulid(Date.now()); } if (!this.header) { this.header = ""; } } } class ListSection { constructor(props) { Object.assign(this, props); this.rows = props.rows.map((row) => new Row(row)); } } class Section { constructor(props) { Object.assign(this, props); this.list = props.list.map((item) => new ListSection(item)); } toSectionsString() { return JSON.stringify({ title: this.buttonText, sections: this.list, }); } } const formatListMsg = async (sections, footer, message, sock, image) => { const generate = await (async () => { if (image) { return await prepareMediaMessage(sock, { mediatype: "image", media: image, }); } })(); return { // viewOnceMessage: { // message: { // messageContextInfo: { // deviceListMetadata: {}, // deviceListMetadataVersion: 2, // }, interactiveMessage: { carouselMessage: { cards: [ { body: { text: (function () { return message; })(), }, footer: { text: footer ?? "..", }, header: (function () { if (generate?.message?.imageMessage) { return { hasMediaAttachment: !!generate.message.imageMessage, imageMessage: generate.message.imageMessage, }; } })(), nativeFlowMessage: { buttons: sections.map(function (value) { return { name: "single_select", buttonParamsJson: value.toSectionsString(), }; }), messageParamsJson: JSON.stringify({ from: "api", templateId: ulid(Date.now()), }), }, messageVersion: 1, }, ], }, }, // }, // }, }; }; export { formatListMsg, Section };