mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
feat: send audio as voice note
This adds the 'sendAudioAsVoice' option for messages close #160
This commit is contained in:
@@ -382,6 +382,7 @@ class Client extends EventEmitter {
|
||||
async sendMessage(chatId, content, options = {}) {
|
||||
let internalOptions = {
|
||||
linkPreview: options.linkPreview === false ? undefined : true,
|
||||
sendAudioAsVoice: options.sendAudioAsVoice,
|
||||
caption: options.caption,
|
||||
quotedMessageId: options.quotedMessageId,
|
||||
mentionedJidList: Array.isArray(options.mentions) ? options.mentions.map(contact => contact.id._serialized) : []
|
||||
|
||||
@@ -48,7 +48,7 @@ exports.LoadUtils = () => {
|
||||
window.WWebJS.sendMessage = async (chat, content, options = {}) => {
|
||||
let attOptions = {};
|
||||
if (options.attachment) {
|
||||
attOptions = await window.WWebJS.processMediaData(options.attachment);
|
||||
attOptions = await window.WWebJS.processMediaData(options.attachment, options.sendAudioAsVoice);
|
||||
delete options.attachment;
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ exports.LoadUtils = () => {
|
||||
return window.Store.Msg.get(newMsgId._serialized);
|
||||
};
|
||||
|
||||
window.WWebJS.processMediaData = async (mediaInfo) => {
|
||||
window.WWebJS.processMediaData = async (mediaInfo, forceVoice) => {
|
||||
const file = window.WWebJS.mediaInfoToFile(mediaInfo);
|
||||
const mData = await window.Store.OpaqueData.default.createFromData(file, file.type);
|
||||
const mediaPrep = window.Store.MediaPrep.prepRawMedia(mData, {});
|
||||
@@ -126,6 +126,10 @@ exports.LoadUtils = () => {
|
||||
isGif: mediaData.isGif
|
||||
});
|
||||
|
||||
if(forceVoice && mediaData.type === 'audio') {
|
||||
mediaData.type = 'ptt';
|
||||
}
|
||||
|
||||
if (!(mediaData.mediaBlob instanceof window.Store.OpaqueData.default)) {
|
||||
mediaData.mediaBlob = await window.Store.OpaqueData.default.createFromData(mediaData.mediaBlob, mediaData.mediaBlob.type);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user