mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-20 04:29:15 +00:00
Add sendVideoAsGif option (#578)
* Add sendVideoAsGif option * fix typo Co-authored-by: Pedro S. Lopez <pslamoros@hotmail.com>
This commit is contained in:
2
index.d.ts
vendored
2
index.d.ts
vendored
@@ -584,6 +584,8 @@ declare namespace WAWebJS {
|
|||||||
linkPreview?: boolean
|
linkPreview?: boolean
|
||||||
/** Send audio as voice message */
|
/** Send audio as voice message */
|
||||||
sendAudioAsVoice?: boolean
|
sendAudioAsVoice?: boolean
|
||||||
|
/** Send video as gif */
|
||||||
|
sendVideoAsGif?: boolean
|
||||||
/** Send media as sticker */
|
/** Send media as sticker */
|
||||||
sendMediaAsSticker?: boolean
|
sendMediaAsSticker?: boolean
|
||||||
/** Send media as document */
|
/** Send media as document */
|
||||||
|
|||||||
@@ -430,6 +430,7 @@ class Client extends EventEmitter {
|
|||||||
* @typedef {Object} MessageSendOptions
|
* @typedef {Object} MessageSendOptions
|
||||||
* @property {boolean} [linkPreview=true] - Show links preview
|
* @property {boolean} [linkPreview=true] - Show links preview
|
||||||
* @property {boolean} [sendAudioAsVoice=false] - Send audio as voice message
|
* @property {boolean} [sendAudioAsVoice=false] - Send audio as voice message
|
||||||
|
* @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} [parseVCards=true] - Automatically parse vCards and send them as contacts
|
* @property {boolean} [parseVCards=true] - Automatically parse vCards and send them as contacts
|
||||||
@@ -455,6 +456,7 @@ class Client extends EventEmitter {
|
|||||||
let internalOptions = {
|
let internalOptions = {
|
||||||
linkPreview: options.linkPreview === false ? undefined : true,
|
linkPreview: options.linkPreview === false ? undefined : true,
|
||||||
sendAudioAsVoice: options.sendAudioAsVoice,
|
sendAudioAsVoice: options.sendAudioAsVoice,
|
||||||
|
sendVideoAsGif: options.sendVideoAsGif,
|
||||||
sendMediaAsSticker: options.sendMediaAsSticker,
|
sendMediaAsSticker: options.sendMediaAsSticker,
|
||||||
sendMediaAsDocument: options.sendMediaAsDocument,
|
sendMediaAsDocument: options.sendMediaAsDocument,
|
||||||
caption: options.caption,
|
caption: options.caption,
|
||||||
|
|||||||
@@ -62,7 +62,8 @@ exports.LoadUtils = () => {
|
|||||||
? await window.WWebJS.processStickerData(options.attachment)
|
? await window.WWebJS.processStickerData(options.attachment)
|
||||||
: await window.WWebJS.processMediaData(options.attachment, {
|
: await window.WWebJS.processMediaData(options.attachment, {
|
||||||
forceVoice: options.sendAudioAsVoice,
|
forceVoice: options.sendAudioAsVoice,
|
||||||
forceDocument: options.sendMediaAsDocument
|
forceDocument: options.sendMediaAsDocument,
|
||||||
|
forceGif: options.sendVideoAsGif
|
||||||
});
|
});
|
||||||
|
|
||||||
content = options.sendMediaAsSticker ? undefined : attOptions.preview;
|
content = options.sendMediaAsSticker ? undefined : attOptions.preview;
|
||||||
@@ -195,7 +196,7 @@ exports.LoadUtils = () => {
|
|||||||
return stickerInfo;
|
return stickerInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
window.WWebJS.processMediaData = async (mediaInfo, { forceVoice, forceDocument }) => {
|
window.WWebJS.processMediaData = async (mediaInfo, { forceVoice, forceDocument, forceGif }) => {
|
||||||
const file = window.WWebJS.mediaInfoToFile(mediaInfo);
|
const file = window.WWebJS.mediaInfoToFile(mediaInfo);
|
||||||
const mData = await window.Store.OpaqueData.createFromData(file, file.type);
|
const mData = await window.Store.OpaqueData.createFromData(file, file.type);
|
||||||
const mediaPrep = window.Store.MediaPrep.prepRawMedia(mData, { asDocument: forceDocument });
|
const mediaPrep = window.Store.MediaPrep.prepRawMedia(mData, { asDocument: forceDocument });
|
||||||
@@ -211,6 +212,10 @@ exports.LoadUtils = () => {
|
|||||||
mediaData.type = 'ptt';
|
mediaData.type = 'ptt';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (forceGif && mediaData.type === 'video') {
|
||||||
|
mediaData.isGif = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (forceDocument) {
|
if (forceDocument) {
|
||||||
mediaData.type = 'document';
|
mediaData.type = 'document';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user