Chat Events
The Telerik UI for Blazor Chat component exposes various events that allow you to implement custom functionality and handle user interactions. This article lists the available events and provides examples for the most common use cases.
OnSendMessage
The OnSendMessage event fires when a user sends a new message. Use this event to handle message processing, validation, and persistence.
After the event handler executes, the Chat automatically scrolls down to the last message.
Handle the Chat OnSendMessage event
OnResendMessage
The OnResendMessage event fires when a user clicks the resend button of a failed message. Use this event to handle error message retry.
Handle the Chat OnResendMessage event
OnSuggestionClick
The OnSuggestionClick event fires when a user clicks on a quick reply suggestion. You can use this event to customize suggestion handling.
If the handler adds new messages to the Chat, call the component Refresh() method to scroll down to the last message.
Handle Chat suggestion clicks
OnDownload
The OnDownload event fires when a user downloads files from a message. Use this event to handle file access, logging, or custom download logic.
Handle Chat file downloads
<TelerikChat Data="@ChatData"
OnDownload="@OnChatDownload">
</TelerikChat>
@code {
private async Task OnChatDownload(ChatDownloadEventArgs args)
{
foreach (FileSelectFileInfo file in args.Files)
{
// Implement custom download logic
}
}
}
OnMessageUnpin
The OnMessageUnpin event fires when a user unpins a message. Handle this event to update your data model and persist the change.
Handle Chat message unpinning
<TelerikChat Data="@ChatData"
OnMessageUnpin="@OnChatMessageUnpin">
</TelerikChat>
@code {
private List<Message> ChatData { get; set; } = new();
private void OnChatMessageUnpin(ChatMessageUnpinEventArgs args)
{
var message = ChatData.First(m => m.Id == args.MessageId);
message.IsPinned = false;
}
}
OnInputValueChanged
The OnInputValueChanged event fires when the input value changes. Use this for real-time validation, auto-save drafts, or typing indicators.
Handle Chat input value changes
<TelerikChat Data="@ChatData"
InputValue="@ChatInputValue"
OnInputValueChanged="@OnChatInputValueChanged">
</TelerikChat>
@code {
private List<Message> ChatData { get; set; } = new();
private string ChatInputValue { get; set; } = string.Empty;
private void OnChatInputValueChanged(string newValue)
{
ChatInputValue = newValue;
}
}
Event Arguments
The Chat events provide specific argument types with relevant data:
| Event | Arguments Type | Key Properties |
|---|---|---|
OnSendMessage | ChatSendMessageEventArgs | Message, Files, ReplyMessageId |
OnResendMessage | ChatResendMessageEventArgs | MessageId |
OnSuggestionClick | ChatSuggestionClickEventArgs | Suggestion, IsCancelled |
OnDownload | ChatDownloadEventArgs | Files, MessageId |
OnMessageUnpin | ChatMessageUnpinEventArgs | MessageId |
OnInputValueChanged | string | The current input value |
OnLoadMoreMessages | ChatLoadMoreMessagesEventArgs | StartIndex, EndIndex |
OnReferencedMessageClick | ChatReferencedMessageClickEventArgs | Id |