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:
parent
c8c2f09f20
commit
8ff5bceca0
4 changed files with 16 additions and 4 deletions
|
|
@ -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
2
index.d.ts
vendored
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue