From 8dfe16975ddb74a4c97ded10e28546f39ac362dd Mon Sep 17 00:00:00 2001 From: Alfredo Gallardo Date: Wed, 29 Nov 2023 16:09:49 -0300 Subject: [PATCH] - fix: error when lastMessage is null (#98) --- apps/shinkai-visor/src/components/inboxes/inboxes.tsx | 2 +- libs/shinkai-message-ts/src/utils/shinkai_message_handler.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/shinkai-visor/src/components/inboxes/inboxes.tsx b/apps/shinkai-visor/src/components/inboxes/inboxes.tsx index 45c323201..68209e9b6 100644 --- a/apps/shinkai-visor/src/components/inboxes/inboxes.tsx +++ b/apps/shinkai-visor/src/components/inboxes/inboxes.tsx @@ -132,7 +132,7 @@ export const Inboxes = () => { {inbox.custom_name}
- {getMessageContent(inbox.last_message)} + {inbox.last_message && getMessageContent(inbox.last_message)}
diff --git a/libs/shinkai-message-ts/src/utils/shinkai_message_handler.ts b/libs/shinkai-message-ts/src/utils/shinkai_message_handler.ts index 3ae6630c0..e5da0ade4 100644 --- a/libs/shinkai-message-ts/src/utils/shinkai_message_handler.ts +++ b/libs/shinkai-message-ts/src/utils/shinkai_message_handler.ts @@ -18,7 +18,8 @@ export const isJobMessage = (message: ShinkaiMessage) => { ); }; -export const getMessageContent = (message: ShinkaiMessage) => { +export const getMessageContent = (message: ShinkaiMessage): string => { + if (!message) return ''; // unnencrypted content if (message.body && 'unencrypted' in message.body) { if ('unencrypted' in message.body.unencrypted.message_data) { @@ -47,7 +48,7 @@ export const getMessageContent = (message: ShinkaiMessage) => { return message.body.unencrypted.message_data.encrypted.content; } // raw content for encrypted body - return message.body?.encrypted.content; + return message.body?.encrypted.content || ''; }; export const getMessageFilesInbox = (message: ShinkaiMessage): string | undefined => {