@@ -33,6 +33,7 @@ import makeWASocket, {
3333 WAMessageUpdate ,
3434 WASocket ,
3535} from '@whiskeysockets/baileys' ;
36+ import MAIN_LOGGER from '@whiskeysockets/baileys/lib/Utils/logger' ;
3637import axios from 'axios' ;
3738import { exec , execSync } from 'child_process' ;
3839import { arrayUnique , isBase64 , isURL } from 'class-validator' ;
@@ -131,6 +132,8 @@ import { ChatwootService } from './chatwoot.service';
131132//import { SocksProxyAgent } from './socks-proxy-agent';
132133import { TypebotService } from './typebot.service' ;
133134
135+ const logger = MAIN_LOGGER . child ( { } ) ;
136+
134137export class WAStartupService {
135138 constructor (
136139 private readonly configService : ConfigService ,
@@ -1542,7 +1545,7 @@ export class WAStartupService {
15421545 'buffer' ,
15431546 { } ,
15441547 {
1545- logger : P ( { level : 'error' } ) ,
1548+ logger : logger ,
15461549 reuploadRequest : this . client . updateMediaMessage ,
15471550 } ,
15481551 ) ;
@@ -2061,7 +2064,12 @@ export class WAStartupService {
20612064 }
20622065 }
20632066
2064- private async sendMessageWithTyping < T = proto . IMessage > ( number : string , message : T , options ?: Options ) {
2067+ private async sendMessageWithTyping < T = proto . IMessage > (
2068+ number : string ,
2069+ message : T ,
2070+ options ?: Options ,
2071+ isChatwoot = false ,
2072+ ) {
20652073 this . logger . verbose ( 'Sending message with typing' ) ;
20662074
20672075 this . logger . verbose ( `Check if number "${ number } " is WhatsApp` ) ;
@@ -2219,7 +2227,7 @@ export class WAStartupService {
22192227 this . logger . verbose ( 'Sending data to webhook in event SEND_MESSAGE' ) ;
22202228 await this . sendDataWebhook ( Events . SEND_MESSAGE , messageRaw ) ;
22212229
2222- if ( this . localChatwoot . enabled ) {
2230+ if ( this . localChatwoot . enabled && ! isChatwoot ) {
22232231 this . chatwootService . eventWhatsapp ( Events . SEND_MESSAGE , { instanceName : this . instance . name } , messageRaw ) ;
22242232 }
22252233
@@ -2244,14 +2252,15 @@ export class WAStartupService {
22442252 }
22452253
22462254 // Send Message Controller
2247- public async textMessage ( data : SendTextDto ) {
2255+ public async textMessage ( data : SendTextDto , isChatwoot = false ) {
22482256 this . logger . verbose ( 'Sending text message' ) ;
22492257 return await this . sendMessageWithTyping (
22502258 data . number ,
22512259 {
22522260 conversation : data . textMessage . text ,
22532261 } ,
22542262 data ?. options ,
2263+ isChatwoot ,
22552264 ) ;
22562265 }
22572266
@@ -2528,11 +2537,11 @@ export class WAStartupService {
25282537 return result ;
25292538 }
25302539
2531- public async mediaMessage ( data : SendMediaDto ) {
2540+ public async mediaMessage ( data : SendMediaDto , isChatwoot = false ) {
25322541 this . logger . verbose ( 'Sending media message' ) ;
25332542 const generate = await this . prepareMediaMessage ( data . mediaMessage ) ;
25342543
2535- return await this . sendMessageWithTyping ( data . number , { ...generate . message } , data ?. options ) ;
2544+ return await this . sendMessageWithTyping ( data . number , { ...generate . message } , data ?. options , isChatwoot ) ;
25362545 }
25372546
25382547 public async processAudio ( audio : string , number : string ) {
@@ -2589,7 +2598,7 @@ export class WAStartupService {
25892598 } ) ;
25902599 }
25912600
2592- public async audioWhatsapp ( data : SendAudioDto ) {
2601+ public async audioWhatsapp ( data : SendAudioDto , isChatwoot = false ) {
25932602 this . logger . verbose ( 'Sending audio whatsapp' ) ;
25942603
25952604 if ( ! data . options ?. encoding && data . options ?. encoding !== false ) {
@@ -2608,6 +2617,7 @@ export class WAStartupService {
26082617 mimetype : 'audio/mp4' ,
26092618 } ,
26102619 { presence : 'recording' , delay : data ?. options ?. delay } ,
2620+ isChatwoot ,
26112621 ) ;
26122622
26132623 fs . unlinkSync ( convert ) ;
@@ -2629,6 +2639,7 @@ export class WAStartupService {
26292639 mimetype : 'audio/ogg; codecs=opus' ,
26302640 } ,
26312641 { presence : 'recording' , delay : data ?. options ?. delay } ,
2642+ isChatwoot ,
26322643 ) ;
26332644 }
26342645
0 commit comments