Hey everyone
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
id
s and differentdata
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!
Thanks in advance,
Theo