Event properties
Always
'pre:threadLoaded'.Array of messages to load into the chat.
Unique identifier for the message.
Sender type:
'user' or 'response'.Array of content items in the message.
Text content of the message item. If you need to modify the displayed text only, update this property.
Type of the content item, for example,
'text'.State information for the message. You can create a new object with the spread operator before adding nested custom properties.
A dedicated namespace for your custom metadata. Use this namespace to:
- Prevent conflicts with system properties.
- Keep your custom data organized.
- Ensure future platform updates do not break your code.
message_state object and a new user_defined object inside it. Add your custom properties inside user_defined.If
message_state or user_defined was previously sealed or made non-extensible, directly assigning a new nested property can throw an Object is not extensible error in strict mode. To make your code more robust and preserve existing properties, use the spread operator to create a fresh object reference before adding custom fields:Array of message IDs to persist to the backend database.When you modify historical messages in
pre:threadLoaded, those changes only affect what displays in the UI. To save your modifications to the backend, add the messageId of each modified message to this array. This triggers automatic PATCH API calls that persist your changes.Examples
The following example demonstrates how to modify historical messages when loading a conversation thread, including adding feedback controls to agent responses and updating message text:Considerations
Complement to pre:receive
Use both events together for consistent modifications and ensure that all messages are processed:
pre:receivehandles new messages.pre:threadLoadedhandles historical messages.
- Set a tracking flag in
message_state.user_definedduringpre:receive. - Check for this flag in
pre:threadLoaded. - Process only messages without the flag.
message_state.user_defined.already_translated = true
Do you need practical examples?
Learn how to apply the features available for embedded chat into your implementation with guidance and examples.

