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();
|
const attachmentData = await quotedMsg.downloadMedia();
|
||||||
client.sendMessage(msg.from, attachmentData, { caption: 'Here\'s your requested media.' });
|
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') {
|
} else if (msg.body === '!location') {
|
||||||
msg.reply(new Location(37.422, -122.084, 'Googleplex\nGoogle Headquarters'));
|
msg.reply(new Location(37.422, -122.084, 'Googleplex\nGoogle Headquarters'));
|
||||||
} else if (msg.location) {
|
} else if (msg.location) {
|
||||||
|
|
|
||||||
2
index.d.ts
vendored
2
index.d.ts
vendored
|
|
@ -909,6 +909,8 @@ declare namespace WAWebJS {
|
||||||
sendMediaAsSticker?: boolean
|
sendMediaAsSticker?: boolean
|
||||||
/** Send media as document */
|
/** Send media as document */
|
||||||
sendMediaAsDocument?: boolean
|
sendMediaAsDocument?: boolean
|
||||||
|
/** Send photo/video as a view once message */
|
||||||
|
isViewOnce?: boolean
|
||||||
/** Automatically parse vCards and send them as contacts */
|
/** Automatically parse vCards and send them as contacts */
|
||||||
parseVCards?: boolean
|
parseVCards?: boolean
|
||||||
/** Image or videos caption */
|
/** Image or videos caption */
|
||||||
|
|
|
||||||
|
|
@ -238,9 +238,9 @@ class Client extends EventEmitter {
|
||||||
// Listens to qr token change
|
// Listens to qr token change
|
||||||
if (mut.type === 'attributes' && mut.attributeName === 'data-ref') {
|
if (mut.type === 'attributes' && mut.attributeName === 'data-ref') {
|
||||||
window.qrChanged(mut.target.dataset.ref);
|
window.qrChanged(mut.target.dataset.ref);
|
||||||
} else
|
}
|
||||||
// Listens to retry button, when found, click it
|
// 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);
|
const retry_button = document.querySelector(selectors.QR_RETRY_BUTTON);
|
||||||
if (retry_button) retry_button.click();
|
if (retry_button) retry_button.click();
|
||||||
}
|
}
|
||||||
|
|
@ -738,6 +738,7 @@ class Client extends EventEmitter {
|
||||||
* @property {boolean} [sendVideoAsGif=false] - Send video as gif
|
* @property {boolean} [sendVideoAsGif=false] - Send video as gif
|
||||||
* @property {boolean} [sendMediaAsSticker=false] - Send media as a sticker
|
* @property {boolean} [sendMediaAsSticker=false] - Send media as a sticker
|
||||||
* @property {boolean} [sendMediaAsDocument=false] - Send media as a document
|
* @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 {boolean} [parseVCards=true] - Automatically parse vCards and send them as contacts
|
||||||
* @property {string} [caption] - Image or video caption
|
* @property {string} [caption] - Image or video caption
|
||||||
* @property {string} [quotedMessageId] - Id of the message that is being quoted (or replied to)
|
* @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) {
|
if (content instanceof MessageMedia) {
|
||||||
internalOptions.attachment = content;
|
internalOptions.attachment = content;
|
||||||
|
internalOptions.isViewOnce = options.isViewOnce,
|
||||||
content = '';
|
content = '';
|
||||||
} else if (options.media instanceof MessageMedia) {
|
} else if (options.media instanceof MessageMedia) {
|
||||||
internalOptions.attachment = options.media;
|
internalOptions.attachment = options.media;
|
||||||
internalOptions.caption = content;
|
internalOptions.caption = content;
|
||||||
|
internalOptions.isViewOnce = options.isViewOnce,
|
||||||
content = '';
|
content = '';
|
||||||
} else if (content instanceof Location) {
|
} else if (content instanceof Location) {
|
||||||
internalOptions.location = content;
|
internalOptions.location = content;
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,7 @@ exports.LoadUtils = () => {
|
||||||
attOptions.caption = options.caption;
|
attOptions.caption = options.caption;
|
||||||
}
|
}
|
||||||
content = options.sendMediaAsSticker ? undefined : attOptions.preview;
|
content = options.sendMediaAsSticker ? undefined : attOptions.preview;
|
||||||
|
attOptions.isViewOnce = options.isViewOnce;
|
||||||
|
|
||||||
delete options.attachment;
|
delete options.attachment;
|
||||||
delete options.sendMediaAsSticker;
|
delete options.sendMediaAsSticker;
|
||||||
|
|
@ -232,8 +233,8 @@ exports.LoadUtils = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
let listOptions = {};
|
let listOptions = {};
|
||||||
if(options.list){
|
if (options.list) {
|
||||||
if(window.Store.Conn.platform === 'smba' || window.Store.Conn.platform === 'smbi'){
|
if (window.Store.Conn.platform === 'smba' || window.Store.Conn.platform === 'smbi') {
|
||||||
throw '[LT01] Whatsapp business can\'t send this yet';
|
throw '[LT01] Whatsapp business can\'t send this yet';
|
||||||
}
|
}
|
||||||
listOptions = {
|
listOptions = {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue