Browse Source

Fix: [object Object] displayed instead of message text

Fixed message display showing '[object Object]' instead of actual text.

Root cause: Message content structure from Letta API different than expected

Solution:
- Created getMessageContent() helper function
- Tries multiple formats: messages[0].content, messages[0].text, message field
- Handles string, object, and array types
- JSON stringifies objects if needed
- Added debug logging to see actual API response structure

Before: Message column shows '[object Object]'
After: Shows actual message text

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta <noreply@letta.com>
Cameron Pfiffer 3 months ago
parent
commit
84c15f5b23
1 changed files with 26 additions and 2 deletions
  1. 26 2
      dashboard.html

+ 26 - 2
dashboard.html

@@ -617,6 +617,12 @@
                 console.log('Letta API response:', data); // Debug log
                 const schedules = data.scheduled_messages || data.schedules || data || [];
                 
+                // Debug: Log first schedule if available
+                if (schedules.length > 0) {
+                    console.log('First schedule:', schedules[0]);
+                    console.log('First schedule messages:', schedules[0].messages);
+                }
+                
                 // Split into one-time and recurring
                 const onetime = schedules.filter(s => s.schedule?.type === 'one-time');
                 const recurring = schedules.filter(s => s.schedule?.type === 'recurring');
@@ -626,7 +632,7 @@
                         <td class="mono">${s.id?.substring(0, 8) || 'N/A'}...</td>
                         <td class="mono">${s.agent_id || 'N/A'}</td>
                         <td>${s.next_scheduled_at ? fromUnixMs(s.next_scheduled_at) : 'N/A'}</td>
-                        <td>${truncate(s.messages?.[0]?.content || s.message || 'N/A', 50)}</td>
+                        <td>${truncate(getMessageContent(s), 50)}</td>
                         <td><button class="danger sm" onclick="deleteSchedule('${s.id}')">Delete</button></td>
                     </tr>
                 `).join('') : '<tr><td colspan="5" class="empty">No one-time schedules</td></tr>';
@@ -637,7 +643,7 @@
                         <td class="mono">${s.agent_id || 'N/A'}</td>
                         <td class="mono">${s.schedule?.cron_expression || 'N/A'}</td>
                         <td>UTC</td>
-                        <td>${truncate(s.messages?.[0]?.content || s.message || 'N/A', 50)}</td>
+                        <td>${truncate(getMessageContent(s), 50)}</td>
                         <td>${s.next_scheduled_at ? fromUnixMs(s.next_scheduled_at) : 'Never'}</td>
                         <td><button class="danger sm" onclick="deleteSchedule('${s.id}')">Delete</button></td>
                     </tr>
@@ -778,8 +784,26 @@
         }
 
         function truncate(str, len) {
+            if (!str) return '';
+            if (typeof str === 'object') str = JSON.stringify(str);
             return str.length > len ? str.substring(0, len) + '...' : str;
         }
+        
+        function getMessageContent(schedule) {
+            // Try different possible message formats
+            if (schedule.messages && Array.isArray(schedule.messages) && schedule.messages.length > 0) {
+                const msg = schedule.messages[0];
+                if (typeof msg === 'string') return msg;
+                if (msg.content) {
+                    if (typeof msg.content === 'string') return msg.content;
+                    if (typeof msg.content === 'object') return JSON.stringify(msg.content);
+                }
+                if (msg.text) return msg.text;
+                return JSON.stringify(msg);
+            }
+            if (schedule.message) return schedule.message;
+            return 'N/A';
+        }
     </script>
 </body>
 </html>