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.

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
The text content of the user’s message.

Example

instance.on('pre:send', (event, instance) => {
    console.log('About to send message:', event.message);
    
    // Convert message to uppercase before sending
    if (event?.message?.message?.content) {
        event.message.message.content = event.message.message.content.toUpperCase();
    }
    
    // Add custom metadata
    event.message.metadata = {
        timestamp: Date.now(),
        source: 'web-chat'
    };
});

Do you need practical examples?

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