Triggered before a conversation thread is loaded from history. Use this event to inspect or modify the messages before they are displayed in the chat UI.
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.
State information for the message.
Example
instance . on ( 'pre:threadLoaded' , ( event , instance ) => {
console . log ( 'Loading thread with messages:' , event . messages );
// Add feedback controls to all agent responses
event ?. messages . forEach (( message ) => {
if ( message ?. sender === 'response' ) {
const [ lastItem ] = message . content ;
lastItem . message_options = {
feedback: {
is_on: true
}
};
// Initialize feedback state
message . message_state = {
content: {
1 : {
feedback: {
text: "" ,
is_positive: true ,
selected_categories: []
}
}
}
};
}
});
// Modify first message
if ( event . messages . length > 0 ) {
event . messages [ 0 ]. content [ 0 ]. text = 'Previous conversation loaded' ;
}
});
Do you need practical examples? Learn how to apply the features available for embedded chat into your implementation with guidance and examples.