Skip to main content
Triggered before web chat receives a response from the agent. Use this event to inspect or modify the agent’s response before it is rendered in the UI.

Event properties

type
string
required
Always 'pre:receive'.
message
object
required
The agent’s response payload.
message.content
array
required
Array of content items in the response.
message.content[].text
string
Text content of the response item.
message.content[].type
string
Type of the response item, for example, 'text', 'user_defined'.

Example

instance.on('pre:receive', (event, instance) => {
    console.log('About to receive message:', event.message);
    
    // Modify response text
    event?.message?.content?.forEach((element) => {
        if (element?.text?.includes('assistant')) {
            element.text = element.text.replace('assistant', 'Agent');
        }
    });
    
    // Add feedback controls to the last item
    const lastItem = event?.message?.content?.[event.message.content.length - 1];
    if (lastItem) {
        lastItem.message_options = {
            feedback: {
                is_on: true,
                show_positive_details: false,
                show_negative_details: true,
                positive_options: {
                    categories: ['Helpful', 'Accurate', 'Clear'],
                    disclaimer: "Your feedback helps us improve."
                },
                negative_options: {
                    categories: ['Inaccurate', 'Incomplete', 'Confusing', 'Other'],
                    disclaimer: "Please provide details to help us improve."
                }
            }
        };
    }
});

Do you need practical examples?

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