File tree Expand file tree Collapse file tree 5 files changed +41
-1
lines changed
Expand file tree Collapse file tree 5 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,8 @@ TYPEBOT_KEEP_OPEN=false
122122# Chatwoot
123123# If you leave this option as false, when deleting the message for everyone on WhatsApp, it will not be deleted on Chatwoot.
124124CHATWOOT_MESSAGE_DELETE = false # false | true
125+ # If you leave this option as true, when sending a message in Chatwoot, the client's last message will be marked as read on WhatsApp.
126+ CHATWOOT_MESSAGE_READ = false # false | true
125127# This db connection is used to import messages from whatsapp to chatwoot database
126128CHATWOOT_IMPORT_DATABASE_CONNECTION_URI = postgres://user:password@hostname:port/dbname
127129CHATWOOT_IMPORT_DATABASE_PLACEHOLDER_MEDIA_MESSAGE = true
Original file line number Diff line number Diff line change @@ -164,6 +164,7 @@ export type QrCode = { LIMIT: number; COLOR: string };
164164export type Typebot = { API_VERSION : string ; KEEP_OPEN : boolean } ;
165165export type Chatwoot = {
166166 MESSAGE_DELETE : boolean ;
167+ MESSAGE_READ : boolean ;
167168 IMPORT : {
168169 DATABASE : {
169170 CONNECTION : {
@@ -379,6 +380,7 @@ export class ConfigService {
379380 } ,
380381 CHATWOOT : {
381382 MESSAGE_DELETE : process . env . CHATWOOT_MESSAGE_DELETE === 'false' ,
383+ MESSAGE_READ : process . env . CHATWOOT_MESSAGE_READ === 'false' ,
382384 IMPORT : {
383385 DATABASE : {
384386 CONNECTION : {
Original file line number Diff line number Diff line change @@ -166,6 +166,8 @@ TYPEBOT:
166166CHATWOOT :
167167 # If you leave this option as false, when deleting the message for everyone on WhatsApp, it will not be deleted on Chatwoot.
168168 MESSAGE_DELETE : true # false | true
169+ # If you leave this option as true, when sending a message in Chatwoot, the client's last message will be marked as read on WhatsApp.
170+ MESSAGE_READ : false # false | true
169171 IMPORT :
170172 # This db connection is used to import messages from whatsapp to chatwoot database
171173 DATABASE :
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ class ChatwootMessage {
1515 inboxId ?: number ;
1616 conversationId ?: number ;
1717 contactInbox ?: { sourceId : string } ;
18+ isRead ?: boolean ;
1819}
1920
2021export class MessageRaw {
@@ -36,8 +37,9 @@ export class MessageRaw {
3637type MessageRawBoolean < T > = {
3738 [ P in keyof T ] ?: 0 | 1 ;
3839} ;
39- export type MessageRawSelect = Omit < MessageRawBoolean < MessageRaw > , 'key' > & {
40+ export type MessageRawSelect = Omit < Omit < MessageRawBoolean < MessageRaw > , 'key' > , 'chatwoot '> & {
4041 key ?: MessageRawBoolean < Key > ;
42+ chatwoot ?: MessageRawBoolean < ChatwootMessage > ;
4143} ;
4244
4345const messageSchema = new Schema < MessageRaw > ( {
@@ -60,6 +62,7 @@ const messageSchema = new Schema<MessageRaw>({
6062 inboxId : { type : Number } ,
6163 conversationId : { type : Number } ,
6264 contactInbox : { type : Object } ,
65+ isRead : { type : Boolean } ,
6366 } ,
6467} ) ;
6568
Original file line number Diff line number Diff line change @@ -1354,6 +1354,37 @@ export class ChatwootService {
13541354 ) ;
13551355 }
13561356 }
1357+
1358+ const chatwootRead = this . configService . get < Chatwoot > ( 'CHATWOOT' ) . MESSAGE_READ ;
1359+ if ( chatwootRead ) {
1360+ const lastMessage = await this . repository . message . find ( {
1361+ where : {
1362+ key : {
1363+ fromMe : false ,
1364+ } ,
1365+ owner : instance . instanceName ,
1366+ } ,
1367+ limit : 1 ,
1368+ } ) ;
1369+ if ( lastMessage . length > 0 && ! lastMessage [ 0 ] . chatwoot ?. isRead ) {
1370+ waInstance ?. markMessageAsRead ( {
1371+ read_messages : lastMessage . map ( ( msg ) => ( {
1372+ id : msg . key ?. id ,
1373+ fromMe : msg . key ?. fromMe ,
1374+ remoteJid : msg . key ?. remoteJid ,
1375+ } ) ) ,
1376+ } ) ;
1377+ const updateMessage = lastMessage . map ( ( msg ) => ( {
1378+ key : msg . key ,
1379+ owner : msg . owner ,
1380+ chatwoot : {
1381+ ...msg . chatwoot ,
1382+ isRead : true ,
1383+ } ,
1384+ } ) ) ;
1385+ this . repository . message . update ( updateMessage , instance . instanceName , true ) ;
1386+ }
1387+ }
13571388 }
13581389
13591390 if ( body . message_type === 'template' && body . event === 'message_created' ) {
You can’t perform that action at this time.
0 commit comments