diff --git a/README.md b/README.md index 26b46a7..108d086 100644 --- a/README.md +++ b/README.md @@ -264,7 +264,7 @@ const buttons = [ const buttonMessage = { text: "Hi it's button message", - footerText: 'Hello World', + footer: 'Hello World', buttons: buttons, headerType: 1 } @@ -273,18 +273,46 @@ const sendMsg = await sock.sendMessage(id, buttonMessage) //send a template message! const templateButtons = [ - {index: 1, urlButton: {displayText: '⭐ Star Baileys on GitHub!', url: 'https://github.com/adiwajshing/Baileys'}}, - {index: 2, callButton: {displayText: 'Call me!', phoneNumber: '+1 (234) 5678-901'}}, - {index: 3, quickReplyButton: {displayText: 'This is a reply, just like normal buttons!', id: 'id-like-buttons-message'}}, + {index: 1, urlButton: {displayText: '⭐ Star Baileys on GitHub!', url: 'https://github.com/adiwajshing/Baileys'}}, + {index: 2, callButton: {displayText: 'Call me!', phoneNumber: '+1 (234) 5678-901'}}, + {index: 3, quickReplyButton: {displayText: 'This is a reply, just like normal buttons!', id: 'id-like-buttons-message'}}, ] -const buttonMessage = { +const templateMessage = { text: "Hi it's a template message", footer: 'Hello World', templateButtons: templateButttons } const sendMsg = await sock.sendMessage(id, templateMessage) + +// send a list message! +const sections = [ + { + title: "Section 1", + rows: [ + {title: "Option 1", rowId: "option1"}, + {title: "Option 2", rowId: "option2", description: "This is a description"} + ] + }, + { + title: "Section 2", + rows: [ + {title: "Option 3", rowId: "option3"}, + {title: "Option 4", rowId: "option4", description: "This is a description V2"} + ] + }, +] + +const listMessage = { + text: "This is a list", + footer: "nice footer, link: https://google.com", + title: "Amazing boldfaced list title", + buttonText: "Required, text on the button to vie the list", + sections +} + +const sendMsg = await sock.sendMessage(id, listMessage) ``` ### Media Messages diff --git a/src/Types/Message.ts b/src/Types/Message.ts index c06d029..6d63a77 100644 --- a/src/Types/Message.ts +++ b/src/Types/Message.ts @@ -58,6 +58,16 @@ type Templatable = { footer?: string } +type Listable = { + /** Sections of the List */ + sections?: proto.ISection[] + + /** Title of a List Message only */ + title?: string + + /** Text of the bnutton on the list (required) */ + buttonText: string +} type WithDimensions = { width?: number height?: number @@ -93,7 +103,7 @@ export type AnyRegularMessageContent = ( ({ text: string } - & Mentionable & Buttonable & Templatable) | + & Mentionable & Buttonable & Templatable & Listable) | AnyMediaMessageContent | { contacts: { diff --git a/src/Utils/auth-utils.ts b/src/Utils/auth-utils.ts index 3a5dc5f..85c002f 100644 --- a/src/Utils/auth-utils.ts +++ b/src/Utils/auth-utils.ts @@ -112,7 +112,7 @@ export const initAuthCreds = (): AuthenticationCreds => { } /** stores the full authentication state in a single JSON file */ -export const useSingleFileAuthState = (filename: string): { state: AuthenticationState, saveState: () => void } => { +export const useSingleFileAuthState = (filename: string, logger?: Logger): { state: AuthenticationState, saveState: () => void } => { // require fs here so that in case "fs" is not available -- the app does not crash const { readFileSync, writeFileSync, existsSync } = require('fs') let creds: AuthenticationCreds @@ -120,7 +120,7 @@ export const useSingleFileAuthState = (filename: string): { state: Authenticatio // save the authentication state to a file const saveState = () => { - console.log('saving auth state') + logger && logger.trace('saving auth state') writeFileSync( filename, // BufferJSON replacer utility saves buffers nicely diff --git a/src/Utils/messages.ts b/src/Utils/messages.ts index 456edb5..71dcce0 100644 --- a/src/Utils/messages.ts +++ b/src/Utils/messages.ts @@ -314,6 +314,18 @@ export const generateWAMessageContent = async( m = { templateMessage } } + + if ('sections' in message && !!message.sections) { + const listMessage: proto.IListMessage = { + sections: message.sections, + buttonText: message.buttonText, + title: message.title, + footerText: message.footer, + description: message.text + } + + m = { listMessage } + } if('viewOnce' in message && !!message.viewOnce) { m = { viewOnceMessage: { message: m } }