Skip to main content
Triggered before the chat sends a message to the agent. Use this event to inspect or modify the message content before it is dispatched to the backend.
For comprehensive guidance on handling user input, see Handling user input.
When you modify messages in the pre:send event, two properties control different aspects of the message: By default, when a user types a message, the same text is used for both LLM processing and UI display. When you modify message.content:
  1. The modified content is sent to the agent for processing.
  2. The UI continues to display the original user input unless you also update display_text.
This separation allows you to transform messages for the agent while preserving what the user sees in the chat interface.

Event properties

type
string
required
Always 'pre:send'.
message
object
required
The message payload to send to the agent. It contains the user’s input and metadata.
message.message
object
required
The message object containing the content.
message.message.content
string
required
Text content sent to the agent for LLM processing. When you modify this property in the pre:send event handler, the agent receives the modified text, but the user continues to see their original input in the chat UI unless you also update message_state.input.display_text.
message.message.message_state
object
State information for the message. Use this object to control what the user sees in the chat UI independently from what the agent receives.
message.message.message_state.input.display_text
string
Text displayed to the user in the chat UI. When present, this property takes priority over message.message.content for display purposes. Set this property when you want the user to see different text than what is sent to the agent, for example, showing original input while sending translated text, or displaying a modified version of the message.

Examples

The following example demonstrates how to modify message content and add metadata before sending to the agent:
The following example demonstrates how to translate user messages before sending to the agent while displaying the original text in the UI:

Considerations

Common patterns

The pre:send event supports several common patterns for handling user input:

Do you need practical examples?

Learn how to apply the features available for embedded chat into your implementation with guidance and examples.