Skip to main content
The Entries endpoint saves conversation messages with associated emotion data to persistent storage. It maintains up to 20 entries and prevents duplicate messages.

Endpoint

POST http://localhost:5000/api/save-entry

Request body

messages
array
required
Array of message objects from the conversation. Each message should contain type, content, timestamp, and optional emotion data.

Response

success
boolean
Indicates whether the entry was saved successfully

Example request

curl -X POST http://localhost:5000/api/save-entry \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {
        "type": "user_message",
        "message": {
          "content": "I had a really great day today!"
        },
        "receivedAt": "2026-03-04T10:30:00Z",
        "models": {
          "prosody": {
            "scores": {
              "joy": 0.85,
              "contentment": 0.72,
              "interest": 0.68,
              "excitement": 0.55
            }
          }
        }
      },
      {
        "type": "assistant_message",
        "message": {
          "content": "That's wonderful to hear!"
        },
        "receivedAt": "2026-03-04T10:30:05Z"
      }
    ]
  }'

Example response

{
  "success": true
}

Error responses

error
string
Description of the error that occurred

Invalid messages format (400)

{
  "error": "Invalid messages format"
}

Save failed (500)

{
  "error": "Failed to save entry"
}

Stored entry format

Entries are stored in Backend/data/entries.json with the following structure:
[
  {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "timestamp": 1709550600000,
    "messages": [
      {
        "type": "user_message",
        "content": "I had a really great day today!",
        "emotions": [
          {
            "emotion": "joy",
            "score": 0.85
          },
          {
            "emotion": "contentment",
            "score": 0.72
          },
          {
            "emotion": "interest",
            "score": 0.68
          }
        ],
        "timestamp": "2026-03-04T10:30:00Z"
      }
    ]
  }
]

Behavior details

Message filtering

Only messages with type "user_message" or "assistant_message" are saved. Other message types are filtered out.

Emotion processing

When emotion data is present in models.prosody.scores:
  1. All emotions are sorted by score (highest to lowest)
  2. The top 3 emotions are extracted
  3. Each emotion is stored with its name and score
If no emotion data is provided, the emotions array will be empty.

Duplicate prevention

The endpoint prevents duplicate messages by:
  1. Generating a unique identifier from timestamp and content
  2. Checking if this identifier already exists in stored entries
  3. Only saving messages that don’t already exist

Entry limit

The system maintains a maximum of 20 entries. When a new entry is added:
  1. If there are already 20 entries, the oldest entry is removed
  2. The new entry is appended to the end
Each entry is assigned a unique UUID and timestamp when created.
Entries are stored in Backend/data/entries.json. The directory is created automatically if it doesn’t exist.
The endpoint returns {"success": true} even if no new messages were saved (due to duplicates). Check the stored file to verify new entries were added.

Build docs developers (and LLMs) love