mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 09:51:24 -06:00
feat: Added encoding option in endpoint sendWhatsAppAudio
This commit is contained in:
parent
68d980795a
commit
8d91e7cb1d
@ -8,6 +8,7 @@
|
|||||||
* Added reject call and send text message when receiving a call
|
* Added reject call and send text message when receiving a call
|
||||||
* Added setting to ignore group messages
|
* Added setting to ignore group messages
|
||||||
* Added connection with pairing code in chatwoot with command /init:{NUMBER}
|
* Added connection with pairing code in chatwoot with command /init:{NUMBER}
|
||||||
|
* Added encoding option in endpoint sendWhatsAppAudio
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ export class InstanceController {
|
|||||||
if (qrcode) {
|
if (qrcode) {
|
||||||
this.logger.verbose('creating qrcode');
|
this.logger.verbose('creating qrcode');
|
||||||
await instance.connectToWhatsapp(number);
|
await instance.connectToWhatsapp(number);
|
||||||
await delay(2000);
|
await delay(3000);
|
||||||
getQrcode = instance.qrCode;
|
getQrcode = instance.qrCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ export class Options {
|
|||||||
quoted?: Quoted;
|
quoted?: Quoted;
|
||||||
mentions?: Mentions;
|
mentions?: Mentions;
|
||||||
linkPreview?: boolean;
|
linkPreview?: boolean;
|
||||||
|
encoding?: boolean;
|
||||||
}
|
}
|
||||||
class OptionsMessage {
|
class OptionsMessage {
|
||||||
options: Options;
|
options: Options;
|
||||||
|
@ -1601,8 +1601,6 @@ export class ChatwootService {
|
|||||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||||
const apiKey = this.configService.get('AUTHENTICATION').API_KEY.KEY;
|
const apiKey = this.configService.get('AUTHENTICATION').API_KEY.KEY;
|
||||||
|
|
||||||
console.log('data: ', data);
|
|
||||||
|
|
||||||
const requestData = {
|
const requestData = {
|
||||||
instanceName,
|
instanceName,
|
||||||
qrcode,
|
qrcode,
|
||||||
@ -1616,8 +1614,6 @@ export class ChatwootService {
|
|||||||
requestData['number'] = number;
|
requestData['number'] = number;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('requestData: ', requestData);
|
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
maxBodyLength: Infinity,
|
maxBodyLength: Infinity,
|
||||||
|
@ -1354,7 +1354,6 @@ export class WAStartupService {
|
|||||||
|
|
||||||
if (events.call) {
|
if (events.call) {
|
||||||
this.logger.verbose('Listening event: call');
|
this.logger.verbose('Listening event: call');
|
||||||
console.log('events.call', events.call);
|
|
||||||
const call = events.call[0];
|
const call = events.call[0];
|
||||||
|
|
||||||
if (settings?.reject_call && call.status == 'offer') {
|
if (settings?.reject_call && call.status == 'offer') {
|
||||||
@ -1662,8 +1661,6 @@ export class WAStartupService {
|
|||||||
|
|
||||||
const linkPreview = options?.linkPreview != false ? undefined : false;
|
const linkPreview = options?.linkPreview != false ? undefined : false;
|
||||||
|
|
||||||
console.log('linkPreview', linkPreview);
|
|
||||||
|
|
||||||
let quoted: WAMessage;
|
let quoted: WAMessage;
|
||||||
|
|
||||||
if (options?.quoted) {
|
if (options?.quoted) {
|
||||||
@ -2179,6 +2176,12 @@ export class WAStartupService {
|
|||||||
|
|
||||||
public async audioWhatsapp(data: SendAudioDto) {
|
public async audioWhatsapp(data: SendAudioDto) {
|
||||||
this.logger.verbose('Sending audio whatsapp');
|
this.logger.verbose('Sending audio whatsapp');
|
||||||
|
|
||||||
|
if (!data.options?.encoding && data.options?.encoding !== false) {
|
||||||
|
data.options.encoding = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.options?.encoding) {
|
||||||
const convert = await this.processAudio(data.audioMessage.audio, data.number);
|
const convert = await this.processAudio(data.audioMessage.audio, data.number);
|
||||||
if (typeof convert === 'string') {
|
if (typeof convert === 'string') {
|
||||||
const audio = fs.readFileSync(convert).toString('base64');
|
const audio = fs.readFileSync(convert).toString('base64');
|
||||||
@ -2201,6 +2204,19 @@ export class WAStartupService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return await this.sendMessageWithTyping<AnyMessageContent>(
|
||||||
|
data.number,
|
||||||
|
{
|
||||||
|
audio: isURL(data.audioMessage.audio)
|
||||||
|
? { url: data.audioMessage.audio }
|
||||||
|
: Buffer.from(data.audioMessage.audio, 'base64'),
|
||||||
|
ptt: true,
|
||||||
|
mimetype: 'audio/ogg; codecs=opus',
|
||||||
|
},
|
||||||
|
{ presence: 'recording', delay: data?.options?.delay },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public async buttonMessage(data: SendButtonDto) {
|
public async buttonMessage(data: SendButtonDto) {
|
||||||
this.logger.verbose('Sending button message');
|
this.logger.verbose('Sending button message');
|
||||||
const embeddedMedia: any = {};
|
const embeddedMedia: any = {};
|
||||||
|
Loading…
Reference in New Issue
Block a user