mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
[MD] Added template support and footers for buttons & templates (#942)
* Added template support and footers for buttons & templates * Template message readme
This commit is contained in:
31
README.md
31
README.md
@@ -265,6 +265,21 @@ const buttonMessage = {
|
||||
}
|
||||
|
||||
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'}},
|
||||
]
|
||||
|
||||
const buttonMessage = {
|
||||
text: "Hi it's a template message",
|
||||
footer: 'Hello World',
|
||||
templateButtons: templateButttons
|
||||
}
|
||||
|
||||
const sendMsg = await sock.sendMessage(id, templateMessage)
|
||||
```
|
||||
|
||||
### Media Messages
|
||||
@@ -325,6 +340,22 @@ const buttonMessage = {
|
||||
}
|
||||
|
||||
const sendMsg = await sock.sendMessage(id, buttonMessage)
|
||||
|
||||
//send a template message with an image **attached**!
|
||||
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'}},
|
||||
]
|
||||
|
||||
const buttonMessage = {
|
||||
text: "Hi it's a template message",
|
||||
footer: 'Hello World',
|
||||
templateButtons: templateButttons,
|
||||
image: {url: 'https://example.com/image.jpeg'}
|
||||
}
|
||||
|
||||
const sendMsg = await sock.sendMessage(id, templateMessage)
|
||||
```
|
||||
|
||||
### Notes
|
||||
|
||||
@@ -50,6 +50,12 @@ type Buttonable = {
|
||||
/** add buttons to the message */
|
||||
buttons?: proto.IButton[]
|
||||
}
|
||||
type Templatable = {
|
||||
/** add buttons to the message (conflicts with normal buttons)*/
|
||||
templateButtons?: proto.IHydratedTemplateButton[]
|
||||
|
||||
footer?: string
|
||||
}
|
||||
type WithDimensions = {
|
||||
width?: number
|
||||
height?: number
|
||||
@@ -60,13 +66,13 @@ export type AnyMediaMessageContent = (
|
||||
image: WAMediaUpload
|
||||
caption?: string
|
||||
jpegThumbnail?: string
|
||||
} & Mentionable & Buttonable & WithDimensions) |
|
||||
} & Mentionable & Buttonable & Templatable & WithDimensions) |
|
||||
({
|
||||
video: WAMediaUpload
|
||||
caption?: string
|
||||
gifPlayback?: boolean
|
||||
jpegThumbnail?: string
|
||||
} & Mentionable & Buttonable & WithDimensions) | {
|
||||
} & Mentionable & Buttonable & Templatable & WithDimensions) | {
|
||||
audio: WAMediaUpload
|
||||
/** if set to true, will send as a `voice note` */
|
||||
pttAudio?: boolean
|
||||
@@ -78,14 +84,14 @@ export type AnyMediaMessageContent = (
|
||||
document: WAMediaUpload
|
||||
mimetype: string
|
||||
fileName?: string
|
||||
} & Buttonable)) &
|
||||
} & Buttonable & Templatable)) &
|
||||
{ mimetype?: string }
|
||||
|
||||
export type AnyRegularMessageContent = (
|
||||
({
|
||||
text: string
|
||||
}
|
||||
& Mentionable & Buttonable) |
|
||||
& Mentionable & Buttonable & Templatable) |
|
||||
AnyMediaMessageContent |
|
||||
{
|
||||
contacts: {
|
||||
|
||||
@@ -262,8 +262,37 @@ export const generateWAMessageContent = async(
|
||||
|
||||
Object.assign(buttonsMessage, m)
|
||||
}
|
||||
|
||||
if ('footer' in message && !!message.footer) {
|
||||
buttonsMessage.footerText = message.footer
|
||||
}
|
||||
|
||||
m = { buttonsMessage }
|
||||
} else if ('templateButtons' in message && !!message.templateButtons) {
|
||||
const templateMessage: proto.ITemplateMessage = {
|
||||
hydratedTemplate: {
|
||||
hydratedButtons: message.templateButtons
|
||||
}
|
||||
}
|
||||
|
||||
if ('text' in message) {
|
||||
templateMessage.hydratedTemplate.hydratedContentText = message.text
|
||||
} else {
|
||||
|
||||
if('caption' in message) {
|
||||
templateMessage.hydratedTemplate.hydratedContentText = message.caption
|
||||
}
|
||||
|
||||
Object.assign(templateMessage.hydratedTemplate, m)
|
||||
}
|
||||
|
||||
if ('footer' in message && !!message.footer) {
|
||||
templateMessage.hydratedTemplate.hydratedFooterText = message.footer
|
||||
}
|
||||
|
||||
m = { templateMessage }
|
||||
}
|
||||
|
||||
if('viewOnce' in message && !!message.viewOnce) {
|
||||
m = { viewOnceMessage: { message: m } }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user