mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 01:41: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 setting to ignore group messages
|
||||
* Added connection with pairing code in chatwoot with command /init:{NUMBER}
|
||||
* Added encoding option in endpoint sendWhatsAppAudio
|
||||
|
||||
### Fixed
|
||||
|
||||
|
@ -107,7 +107,7 @@ export class InstanceController {
|
||||
if (qrcode) {
|
||||
this.logger.verbose('creating qrcode');
|
||||
await instance.connectToWhatsapp(number);
|
||||
await delay(2000);
|
||||
await delay(3000);
|
||||
getQrcode = instance.qrCode;
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ export class Options {
|
||||
quoted?: Quoted;
|
||||
mentions?: Mentions;
|
||||
linkPreview?: boolean;
|
||||
encoding?: boolean;
|
||||
}
|
||||
class OptionsMessage {
|
||||
options: Options;
|
||||
|
@ -1601,8 +1601,6 @@ export class ChatwootService {
|
||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||
const apiKey = this.configService.get('AUTHENTICATION').API_KEY.KEY;
|
||||
|
||||
console.log('data: ', data);
|
||||
|
||||
const requestData = {
|
||||
instanceName,
|
||||
qrcode,
|
||||
@ -1616,8 +1614,6 @@ export class ChatwootService {
|
||||
requestData['number'] = number;
|
||||
}
|
||||
|
||||
console.log('requestData: ', requestData);
|
||||
|
||||
const config = {
|
||||
method: 'post',
|
||||
maxBodyLength: Infinity,
|
||||
|
@ -1354,7 +1354,6 @@ export class WAStartupService {
|
||||
|
||||
if (events.call) {
|
||||
this.logger.verbose('Listening event: call');
|
||||
console.log('events.call', events.call);
|
||||
const call = events.call[0];
|
||||
|
||||
if (settings?.reject_call && call.status == 'offer') {
|
||||
@ -1662,8 +1661,6 @@ export class WAStartupService {
|
||||
|
||||
const linkPreview = options?.linkPreview != false ? undefined : false;
|
||||
|
||||
console.log('linkPreview', linkPreview);
|
||||
|
||||
let quoted: WAMessage;
|
||||
|
||||
if (options?.quoted) {
|
||||
@ -2179,26 +2176,45 @@ export class WAStartupService {
|
||||
|
||||
public async audioWhatsapp(data: SendAudioDto) {
|
||||
this.logger.verbose('Sending audio whatsapp');
|
||||
const convert = await this.processAudio(data.audioMessage.audio, data.number);
|
||||
if (typeof convert === 'string') {
|
||||
const audio = fs.readFileSync(convert).toString('base64');
|
||||
const result = this.sendMessageWithTyping<AnyMessageContent>(
|
||||
data.number,
|
||||
{
|
||||
audio: Buffer.from(audio, 'base64'),
|
||||
ptt: true,
|
||||
mimetype: 'audio/mp4',
|
||||
},
|
||||
{ presence: 'recording', delay: data?.options?.delay },
|
||||
);
|
||||
|
||||
fs.unlinkSync(convert);
|
||||
this.logger.verbose('Converted audio deleted');
|
||||
|
||||
return result;
|
||||
} else {
|
||||
throw new InternalServerErrorException(convert);
|
||||
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);
|
||||
if (typeof convert === 'string') {
|
||||
const audio = fs.readFileSync(convert).toString('base64');
|
||||
const result = this.sendMessageWithTyping<AnyMessageContent>(
|
||||
data.number,
|
||||
{
|
||||
audio: Buffer.from(audio, 'base64'),
|
||||
ptt: true,
|
||||
mimetype: 'audio/mp4',
|
||||
},
|
||||
{ presence: 'recording', delay: data?.options?.delay },
|
||||
);
|
||||
|
||||
fs.unlinkSync(convert);
|
||||
this.logger.verbose('Converted audio deleted');
|
||||
|
||||
return result;
|
||||
} else {
|
||||
throw new InternalServerErrorException(convert);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user