@@ -1137,19 +1137,35 @@ export class ChatwootService {
11371137 }
11381138 }
11391139
1140- public async onSendMessageError ( instance : InstanceDto , conversation : number , error ?: string ) {
1140+ public async onSendMessageError ( instance : InstanceDto , conversation : number , error ?: any ) {
1141+ this . logger . verbose ( `onSendMessageError ${ JSON . stringify ( error ) } ` ) ;
1142+
11411143 const client = await this . clientCw ( instance ) ;
11421144
11431145 if ( ! client ) {
11441146 return ;
11451147 }
11461148
1149+ if ( error && error ?. status === 400 && error ?. message [ 0 ] ?. exists === false ) {
1150+ client . messages . create ( {
1151+ accountId : this . provider . accountId ,
1152+ conversationId : conversation ,
1153+ data : {
1154+ content : `${ i18next . t ( 'cw.message.numbernotinwhatsapp' ) } ` ,
1155+ message_type : 'outgoing' ,
1156+ private : true ,
1157+ } ,
1158+ } ) ;
1159+
1160+ return ;
1161+ }
1162+
11471163 client . messages . create ( {
11481164 accountId : this . provider . accountId ,
11491165 conversationId : conversation ,
11501166 data : {
11511167 content : i18next . t ( 'cw.message.notsent' , {
1152- error : error ?. length > 0 ? `_${ error } _` : '' ,
1168+ error : error ? `_${ error . toString ( ) } _` : '' ,
11531169 } ) ,
11541170 message_type : 'outgoing' ,
11551171 private : true ,
@@ -1393,7 +1409,7 @@ export class ChatwootService {
13931409 ) ;
13941410 } catch ( error ) {
13951411 if ( ! messageSent && body . conversation ?. id ) {
1396- this . onSendMessageError ( instance , body . conversation ?. id , error . toString ( ) ) ;
1412+ this . onSendMessageError ( instance , body . conversation ?. id , error ) ;
13971413 }
13981414 throw error ;
13991415 }
@@ -1853,27 +1869,6 @@ export class ChatwootService {
18531869 }
18541870 }
18551871
1856- if ( event === 'contact.is_not_in_wpp' ) {
1857- const getConversation = await this . createConversation ( instance , body ) ;
1858-
1859- if ( ! getConversation ) {
1860- this . logger . warn ( 'conversation not found' ) ;
1861- return ;
1862- }
1863-
1864- client . messages . create ( {
1865- accountId : this . provider . accountId ,
1866- conversationId : getConversation ,
1867- data : {
1868- content : `🚨 ${ i18next . t ( 'numbernotinwhatsapp' ) } ` ,
1869- message_type : 'outgoing' ,
1870- private : true ,
1871- } ,
1872- } ) ;
1873-
1874- return ;
1875- }
1876-
18771872 if ( event === 'messages.upsert' || event === 'send.message' ) {
18781873 if ( body . key . remoteJid === 'status@broadcast' ) {
18791874 return ;
0 commit comments