Event properties
Always
'pre:receive'.The agent’s response payload.
Array of content items in the response.
Text content of the response item. If you need to modify the displayed text only, update this property.
Type of the response item, for example,
'text', 'user_defined'.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:Set to
true to persist client-side modifications to the backend database.When you modify message content in pre:receive, those changes only affect what displays in the UI. This triggers an automatic PATCH API call that persists your changes.Examples
The following example demonstrates how to modify agent response text and add custom feedback controls before displaying the message to the user:pre:stream:delta:
Considerations
Persistence across sessions
Modifications made inpre:receive might not run in all scenarios, for example:
- Users might close browser before response arrives.
- Users navigate away during response.
- Long-running flows return responses hours later.
- Use
pre:receivefor new messages. - Use
pre:threadLoadedfor historical messages. - Add a tracking flag in
message_state.user_definedto avoid duplicate processing.
message_state.user_defined.already_processed = true
Do you need practical examples?
Learn how to apply the features available for embedded chat into your implementation with guidance and examples.

