feat: send Media HD (#3535)
* Changing the quality of media downloads * return function result * add option sendImageAsHd * change example * fix quotes * chore: remove unused code --------- Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
This commit is contained in:
parent
c142c3bf93
commit
0ffb66fdb1
4 changed files with 25 additions and 9 deletions
|
|
@ -470,6 +470,12 @@ client.on('message', async msg => {
|
||||||
console.log(statuses);
|
console.log(statuses);
|
||||||
const chat = await statuses[0]?.getChat(); // Get user chat of a first status
|
const chat = await statuses[0]?.getChat(); // Get user chat of a first status
|
||||||
console.log(chat);
|
console.log(chat);
|
||||||
|
} else if (msg.body === '!sendMediaHD' && msg.hasQuotedMsg) {
|
||||||
|
const quotedMsg = await msg.getQuotedMessage();
|
||||||
|
if (quotedMsg.hasMedia) {
|
||||||
|
const media = await quotedMsg.downloadMedia();
|
||||||
|
await client.sendMessage(msg.from, media, { sendMediaAsHd: true });
|
||||||
|
}
|
||||||
} else if (msg.body === '!parseVCard') {
|
} else if (msg.body === '!parseVCard') {
|
||||||
const vCard =
|
const vCard =
|
||||||
'BEGIN:VCARD\n' +
|
'BEGIN:VCARD\n' +
|
||||||
|
|
|
||||||
2
index.d.ts
vendored
2
index.d.ts
vendored
|
|
@ -1225,6 +1225,8 @@ declare namespace WAWebJS {
|
||||||
sendMediaAsSticker?: boolean
|
sendMediaAsSticker?: boolean
|
||||||
/** Send media as document */
|
/** Send media as document */
|
||||||
sendMediaAsDocument?: boolean
|
sendMediaAsDocument?: boolean
|
||||||
|
/** Send media as quality HD */
|
||||||
|
sendMediaAsHd?: boolean
|
||||||
/** Send photo/video as a view once message */
|
/** Send photo/video as a view once message */
|
||||||
isViewOnce?: boolean
|
isViewOnce?: boolean
|
||||||
/** Automatically parse vCards and send them as contacts */
|
/** Automatically parse vCards and send them as contacts */
|
||||||
|
|
|
||||||
|
|
@ -840,6 +840,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} [sendMediaAsHd=false] - Send image as quality HD
|
||||||
* @property {boolean} [isViewOnce=false] - Send photo/video as a view once message
|
* @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
|
||||||
|
|
@ -894,6 +895,7 @@ class Client extends EventEmitter {
|
||||||
sendVideoAsGif: options.sendVideoAsGif,
|
sendVideoAsGif: options.sendVideoAsGif,
|
||||||
sendMediaAsSticker: options.sendMediaAsSticker,
|
sendMediaAsSticker: options.sendMediaAsSticker,
|
||||||
sendMediaAsDocument: options.sendMediaAsDocument,
|
sendMediaAsDocument: options.sendMediaAsDocument,
|
||||||
|
sendMediaAsHd: options.sendMediaAsHd,
|
||||||
caption: options.caption,
|
caption: options.caption,
|
||||||
quotedMessageId: options.quotedMessageId,
|
quotedMessageId: options.quotedMessageId,
|
||||||
parseVCards: options.parseVCards !== false,
|
parseVCards: options.parseVCards !== false,
|
||||||
|
|
@ -2145,7 +2147,7 @@ class Client extends EventEmitter {
|
||||||
return false;
|
return false;
|
||||||
}, chatId);
|
}, chatId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save new contact to user's addressbook or edit the existing one
|
* Save new contact to user's addressbook or edit the existing one
|
||||||
* @param {string} phoneNumber The contact's phone number in a format "17182222222", where "1" is a country code
|
* @param {string} phoneNumber The contact's phone number in a format "17182222222", where "1" is a country code
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ exports.LoadUtils = () => {
|
||||||
forceGif: options.sendVideoAsGif,
|
forceGif: options.sendVideoAsGif,
|
||||||
forceVoice: options.sendAudioAsVoice,
|
forceVoice: options.sendAudioAsVoice,
|
||||||
forceDocument: options.sendMediaAsDocument,
|
forceDocument: options.sendMediaAsDocument,
|
||||||
|
forceMediaHd: options.sendMediaAsHd,
|
||||||
sendToChannel: isChannel
|
sendToChannel: isChannel
|
||||||
});
|
});
|
||||||
mediaOptions.caption = options.caption;
|
mediaOptions.caption = options.caption;
|
||||||
|
|
@ -363,16 +364,21 @@ exports.LoadUtils = () => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
window.WWebJS.processMediaData = async (mediaInfo, { forceSticker, forceGif, forceVoice, forceDocument, sendToChannel }) => {
|
window.WWebJS.processMediaData = async (mediaInfo, { forceSticker, forceGif, forceVoice, forceDocument, forceMediaHd, sendToChannel }) => {
|
||||||
const file = window.WWebJS.mediaInfoToFile(mediaInfo);
|
const file = window.WWebJS.mediaInfoToFile(mediaInfo);
|
||||||
const opaqueData = await window.Store.OpaqueData.createFromData(file, file.type);
|
const opaqueData = await window.Store.OpaqueData.createFromData(file, file.type);
|
||||||
const mediaPrep = window.Store.MediaPrep.prepRawMedia(
|
const mediaParams = {
|
||||||
opaqueData, {
|
asSticker: forceSticker,
|
||||||
asSticker: forceSticker,
|
asGif: forceGif,
|
||||||
asGif: forceGif,
|
isPtt: forceVoice,
|
||||||
isPtt: forceVoice,
|
asDocument: forceDocument
|
||||||
asDocument: forceDocument
|
};
|
||||||
});
|
|
||||||
|
if (forceMediaHd && file.type.indexOf('image/') === 0) {
|
||||||
|
mediaParams.maxDimension = 2560;
|
||||||
|
}
|
||||||
|
|
||||||
|
const mediaPrep = window.Store.MediaPrep.prepRawMedia(opaqueData, mediaParams);
|
||||||
const mediaData = await mediaPrep.waitForPrep();
|
const mediaData = await mediaPrep.waitForPrep();
|
||||||
const mediaObject = window.Store.MediaObject.getOrCreateMediaObject(mediaData.filehash);
|
const mediaObject = window.Store.MediaObject.getOrCreateMediaObject(mediaData.filehash);
|
||||||
const mediaType = window.Store.MediaTypes.msgToMediaType({
|
const mediaType = window.Store.MediaTypes.msgToMediaType({
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue