Skip to content

Commit e4e00d9

Browse files
committed
feat: adicionar timestamp correto nas mensagens enviadas ao Chatwoot
1 parent dcd7b47 commit e4e00d9

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,7 @@ export class ChatwootService {
12071207
messageBody?: any,
12081208
sourceId?: string,
12091209
quotedMsg?: MessageModel,
1210+
timestamp?: number, // Timestamp em segundos (Unix timestamp)
12101211
) {
12111212
const client = await this.clientCw(instance);
12121213

@@ -1235,6 +1236,7 @@ export class ChatwootService {
12351236
...replyToIds,
12361237
},
12371238
source_reply_id: sourceReplyId ? sourceReplyId.toString() : null,
1239+
created_at: timestamp || undefined, // Usa timestamp se fornecido
12381240
},
12391241
});
12401242
},
@@ -2848,6 +2850,16 @@ export class ChatwootService {
28482850
content = `${bodyMessage}`;
28492851
}
28502852

2853+
// Converte timestamp para segundos (Chatwoot usa Unix timestamp em segundos)
2854+
let messageTimestamp: number | undefined;
2855+
if (body.messageTimestamp) {
2856+
if (Long.isLong(body.messageTimestamp)) {
2857+
messageTimestamp = body.messageTimestamp.toNumber();
2858+
} else {
2859+
messageTimestamp = Number(body.messageTimestamp);
2860+
}
2861+
}
2862+
28512863
const send = await this.createMessage(
28522864
instance,
28532865
getConversation,
@@ -2858,6 +2870,7 @@ export class ChatwootService {
28582870
body,
28592871
'WAID:' + body.key.id,
28602872
quotedMsg,
2873+
messageTimestamp,
28612874
);
28622875

28632876
if (!send) {
@@ -2874,6 +2887,16 @@ export class ChatwootService {
28742887

28752888
return send;
28762889
} else {
2890+
// Converte timestamp para segundos (Chatwoot usa Unix timestamp em segundos)
2891+
let messageTimestamp: number | undefined;
2892+
if (body.messageTimestamp) {
2893+
if (Long.isLong(body.messageTimestamp)) {
2894+
messageTimestamp = body.messageTimestamp.toNumber();
2895+
} else {
2896+
messageTimestamp = Number(body.messageTimestamp);
2897+
}
2898+
}
2899+
28772900
const send = await this.createMessage(
28782901
instance,
28792902
getConversation,
@@ -2884,6 +2907,7 @@ export class ChatwootService {
28842907
body,
28852908
'WAID:' + body.key.id,
28862909
quotedMsg,
2910+
messageTimestamp,
28872911
);
28882912

28892913
if (!send) {

0 commit comments

Comments
 (0)