@@ -231,12 +231,19 @@ export class ChatwootService {
231231
232232 if ( qrcode ) {
233233 this . logger . verbose ( 'create conversation in chatwoot' ) ;
234+ const data = {
235+ contact_id : contactId . toString ( ) ,
236+ inbox_id : inboxId . toString ( ) ,
237+ } ;
238+
239+ if ( this . provider . conversation_pending ) {
240+ data [ 'status' ] = 'pending' ;
241+ }
242+
243+ console . log ( 'this.provider' , this . provider ) ;
234244 const conversation = await client . conversations . create ( {
235245 accountId : this . provider . account_id ,
236- data : {
237- contact_id : contactId . toString ( ) ,
238- inbox_id : inboxId . toString ( ) ,
239- } ,
246+ data,
240247 } ) ;
241248
242249 if ( ! conversation ) {
@@ -521,24 +528,39 @@ export class ChatwootService {
521528 } ) ) as any ;
522529
523530 if ( contactConversations ) {
531+ let conversation : any ;
532+ if ( this . provider . reopen_conversation ) {
533+ conversation = contactConversations . payload . find (
534+ ( conversation ) => conversation . inbox_id == filterInbox . id ,
535+ ) ;
536+ } else {
537+ conversation = contactConversations . payload . find (
538+ ( conversation ) =>
539+ conversation . status !== 'resolved' &&
540+ conversation . inbox_id == filterInbox . id ,
541+ ) ;
542+ }
524543 this . logger . verbose ( 'return conversation if exists' ) ;
525- const conversation = contactConversations . payload . find (
526- ( conversation ) =>
527- conversation . status !== 'resolved' && conversation . inbox_id == filterInbox . id ,
528- ) ;
544+
529545 if ( conversation ) {
530546 this . logger . verbose ( 'conversation found' ) ;
531547 return conversation . id ;
532548 }
533549 }
534550
535551 this . logger . verbose ( 'create conversation in chatwoot' ) ;
552+ const data = {
553+ contact_id : contactId . toString ( ) ,
554+ inbox_id : filterInbox . id . toString ( ) ,
555+ } ;
556+
557+ if ( this . provider . conversation_pending ) {
558+ data [ 'status' ] = 'pending' ;
559+ }
560+
536561 const conversation = await client . conversations . create ( {
537562 accountId : this . provider . account_id ,
538- data : {
539- contact_id : `${ contactId } ` ,
540- inbox_id : `${ filterInbox . id } ` ,
541- } ,
563+ data,
542564 } ) ;
543565
544566 if ( ! conversation ) {
0 commit comments