feat: send photo/video as a view once message (#2317)

* added isViewOnce property

* docs updated

* added usage example

* fix: ESLint
This commit is contained in:
alechkos 2023-07-31 12:53:35 +03:00 • committed by GitHub
commit 8ff5bceca0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 4 deletions

View file

@ -140,6 +140,12 @@ client.on('message', async msg => {
const attachmentData = await quotedMsg.downloadMedia();
client.sendMessage(msg.from, attachmentData, { caption: 'Here\'s your requested media.' });
}
} else if (msg.body === '!isviewonce' && msg.hasQuotedMsg) {
const quotedMsg = await msg.getQuotedMessage();
if (quotedMsg.hasMedia) {
const media = await quotedMsg.downloadMedia();
await client.sendMessage(msg.from, media, { isViewOnce: true });
}
} else if (msg.body === '!location') {
msg.reply(new Location(37.422, -122.084, 'Googleplex\nGoogle Headquarters'));
} else if (msg.location) {

2
index.d.ts vendored
View file

@ -909,6 +909,8 @@ declare namespace WAWebJS {
sendMediaAsSticker?: boolean
/** Send media as document */
sendMediaAsDocument?: boolean
/** Send photo/video as a view once message */
isViewOnce?: boolean
/** Automatically parse vCards and send them as contacts */
parseVCards?: boolean
/** Image or videos caption */

View file

@ -238,9 +238,9 @@ class Client extends EventEmitter {
// Listens to qr token change
if (mut.type === 'attributes' && mut.attributeName === 'data-ref') {
window.qrChanged(mut.target.dataset.ref);
} else
}
// Listens to retry button, when found, click it
if (mut.type === 'childList') {
else if (mut.type === 'childList') {
const retry_button = document.querySelector(selectors.QR_RETRY_BUTTON);
if (retry_button) retry_button.click();
}
@ -738,6 +738,7 @@ class Client extends EventEmitter {
* @property {boolean} [sendVideoAsGif=false] - Send video as gif
* @property {boolean} [sendMediaAsSticker=false] - Send media as a sticker
* @property {boolean} [sendMediaAsDocument=false] - Send media as a document
* @property {boolean} [isViewOnce=false] - Send photo/video as a view once message
* @property {boolean} [parseVCards=true] - Automatically parse vCards and send them as contacts
* @property {string} [caption] - Image or video caption
* @property {string} [quotedMessageId] - Id of the message that is being quoted (or replied to)
@ -779,10 +780,12 @@ class Client extends EventEmitter {
if (content instanceof MessageMedia) {
internalOptions.attachment = content;
internalOptions.isViewOnce = options.isViewOnce,
content = '';
} else if (options.media instanceof MessageMedia) {
internalOptions.attachment = options.media;
internalOptions.caption = content;
internalOptions.isViewOnce = options.isViewOnce,
content = '';
} else if (content instanceof Location) {
internalOptions.location = content;

View file

@ -127,6 +127,7 @@ exports.LoadUtils = () => {
attOptions.caption = options.caption;
}
content = options.sendMediaAsSticker ? undefined : attOptions.preview;
attOptions.isViewOnce = options.isViewOnce;
delete options.attachment;
delete options.sendMediaAsSticker;