feat: Added encoding option in endpoint sendWhatsAppAudio

This commit is contained in:
Davidson Gomes 2023-07-24 16:21:29 -03:00
parent 68d980795a
commit 8d91e7cb1d
5 changed files with 40 additions and 26 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -16,6 +16,7 @@ export class Options {
quoted?: Quoted;
mentions?: Mentions;
linkPreview?: boolean;
encoding?: boolean;
}
class OptionsMessage {
options: Options;

View File

@ -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,

View File

@ -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,6 +2176,12 @@ export class WAStartupService {
public async audioWhatsapp(data: SendAudioDto) {
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);
if (typeof convert === 'string') {
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) {
this.logger.verbose('Sending button message');
const embeddedMedia: any = {};