Bladeren bron

Handle numeric Chatwoot message types in translation

Maciek 3 weken geleden
bovenliggende
commit
63ae1a2af9
3 gewijzigde bestanden met toevoegingen van 3 en 3 verwijderingen
  1. 1 1
      src/clients/chatwootClient.ts
  2. 1 1
      src/http/routes/agentTools.ts
  3. 1 1
      tests/integration/agentTools.test.ts

+ 1 - 1
src/clients/chatwootClient.ts

@@ -22,7 +22,7 @@ export interface ChatwootConversation {
 export interface ChatwootMessage {
   id?: number | string;
   content?: string | null;
-  message_type?: 'incoming' | 'outgoing' | string;
+  message_type?: 'incoming' | 'outgoing' | string | number;
   private?: boolean;
   created_at?: number | string;
   sender?: { id?: number | string; name?: string; email?: string; type?: string };

+ 1 - 1
src/http/routes/agentTools.ts

@@ -160,7 +160,7 @@ async function firstIncomingCustomerMessage(conversationId: number): Promise<str
 }
 
 function isPublicIncoming(message: ChatwootMessage): boolean {
-  return message.private !== true && message.message_type === 'incoming';
+  return message.private !== true && (message.message_type === 'incoming' || message.message_type === 0);
 }
 
 function timestamp(message: ChatwootMessage): number {

+ 1 - 1
tests/integration/agentTools.test.ts

@@ -36,7 +36,7 @@ before(async () => {
         JSON.stringify({
           payload: [
             { id: 1, message_type: 'outgoing', content: 'Dzień dobry' },
-            { id: 2, message_type: 'incoming', private: false, created_at: 1, content: 'Guten Morgen, ich brauche Hilfe.' },
+            { id: 2, message_type: 0, private: false, created_at: 1, content: 'Guten Morgen, ich brauche Hilfe.' },
           ],
         }),
         { status: 200, headers: { 'Content-Type': 'application/json' } },