Trouble Parsing Chat History from SSE-like Xano Response — Only Getting One Message

Hey everyone :waving_hand:

I’m building a chat interface in WeWeb connected to Xano, and I’m stuck trying to properly display the chat history.

Context:

  • Xano is sending a stream of objects that each look like this:
{
  "id": 1748778803728,
  "data": "[{\"user_id\":1,\"question\":\"What could I do with Xano ?\",\"response\":\"...\",\"created_at\":1748722670763}]"
}

{
  "id": 1748778803728,
  "data": "[{\"user_id\":1,\"question\":\"What could I do with Xano ?\",\"response\":\"...\",\"created_at\":1748722670763}]"
}

What I’ve tried:

I wrote a custom JavaScript formula like this:

// Get the raw data from collection
const rawData = collections['846f3d62-d20c-41f3-978f-1d57fae656f3']?.['data'];

// Split messages by 'id:' to separate each SSE message
const messages = rawData?.split('id:')
    .filter(Boolean) // Remove empty strings
    .map(message => {
        try {
            // Extract the data portion after 'data:'
            const dataMatch = message.split('data:')[1];
            if (!dataMatch) return [];
            
            // Parse the JSON data
            return JSON.parse(dataMatch.trim());
        } catch (e) {
            console.error('Error parsing message:', e);
            return [];
        }
    })
    .flat(); // Flatten because each message is an array

// Remove duplicates based on question and created_at
const uniqueMessages = messages?.filter((message, index, self) =>
    index === self.findIndex((m) =>
        m?.question === message?.question &&
        m?.created_at === message?.created_at
    )
);

// Sort by created_at in descending order (most recent first)
return uniqueMessages?.sort((a, b) => b?.created_at - a?.created_at) || [];

Issue:

  • I only get one item showing up in the chat UI.
  • But in the data preview panel, I can clearly see that the collection has multiple records with unique ids and different data fields.
  • If I log things in the formula, I can see all entries — but only one renders in the repeater.

Question:

Is there something wrong with how I’m returning the array to the Repeater?
Or is there a better pattern to handle this kind of stringified JSON array list from a collection?

Any help or insights would be hugely appreciated! :folded_hands:

Thanks in advance,
Theo

Hi Theo, welcome back :waving_hand:

Can you share a screenshot of your formula and your collection element?

Also, have you tried editing your custom formula with our AI?

Hey @Agustin_Carozo, thanks for your reply.

Actually I resolved the issue !

1 Like

Great!

Would you mind sharing how you did it?

Hey @Agustin_Carozo – sure!

The issue came from how I was parsing the SSE-style string. Even though multiple messages were visible in the logs, only one was rendering because of how the repeater expected the data format.

I changed my custom formula to:

  • Split only on newlines
  • Extract lines starting with data:
  • Parse each individually (some were arrays)
  • Flatten and filter out empty entries
  • Then sorted and deduplicated them
1 Like