added support for sending viewOnceMessage and updated README (#596)

* add support to send viewOnceMessage

* Update README.md

* add support send viewOnceMessage and update README

* remove something irrelevant from PR

Co-authored-by: LoL-Human <>
This commit is contained in:
ファイズ
2021-07-14 23:51:59 +07:00
committed by GitHub
parent 3ce4f6cc6e
commit 46fdab76ee
3 changed files with 10 additions and 2 deletions

View File

@@ -242,7 +242,8 @@ const sections = [{title: "Section 1", rows: rows}]
const button = {
buttonText: 'Click Me!',
description: "Hello it's list message",
sections: sections
sections: sections,
listType: 1
}
const sendMsg = await conn.sendMessage(id, button, MessageType.listMessage)

View File

@@ -178,6 +178,9 @@ export class WAConnection extends Base {
if (mediaType === MessageType.sticker && options.caption) {
throw new Error('cannot send a caption with a sticker')
}
if (!(mediaType === MessageType.image || mediaType === MessageType.video) && options.viewOnce) {
throw new Error(`cannot send a ${mediaType} as a viewOnceMessage`)
}
if (!options.mimetype) {
options.mimetype = MimetypeMap[mediaType]
}
@@ -267,7 +270,8 @@ export class WAConnection extends Base {
fileName: options.filename || 'file',
gifPlayback: isGIF || undefined,
caption: options.caption,
ptt: options.ptt
ptt: options.ptt,
viewOnce: options.viewOnce
}
)
}
@@ -277,6 +281,7 @@ export class WAConnection extends Base {
prepareMessageFromContent(id: string, message: WAMessageContent, options: MessageOptions) {
if (!options.timestamp) options.timestamp = new Date() // set timestamp to now
if (typeof options.sendEphemeral === 'undefined') options.sendEphemeral = 'chat'
if (options.viewOnce) message = { viewOnceMessage: { message } }
// prevent an annoying bug (WA doesn't accept sending messages with '@c.us')
id = whatsappID (id)

View File

@@ -402,6 +402,8 @@ export interface MessageOptions {
filename?: string
/** For audio messages, if set to true, will send as a `voice note` */
ptt?: boolean
/** For image or video messages, if set to true, will send as a `viewOnceMessage` */
viewOnce?: boolean
/** Optional agent for media uploads */
uploadAgent?: Agent
/** If set to true (default), automatically detects if you're sending a link & attaches the preview*/