Skip to main content
All docs
V26.1
  • DxAIChat.MessageSending Event

    Fires when a user submits a message to the chat.

    Namespace: DevExpress.AIIntegration.Blazor.Chat

    Assembly: DevExpress.AIIntegration.Blazor.Chat.v26.1.dll

    Declaration

    [Parameter]
    public EventCallback<MessageSendingEventArgs> MessageSending { get; set; }

    Event Data

    The MessageSending event's data class is MessageSendingEventArgs. The following properties provide information specific to this event:

    Property Description
    Cancel Gets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
    CancellationToken Specifies an object that propagates a cancellation notification.
    Chat Returns the current AI Chat component.
    Contexts Returns the collection of AI resources and files attached to the chat message.
    Files Returns the collection of files attached to the chat message.
    Text Returns the text of the user message.

    Remarks

    Handle the MessageSending event to process a user message before it is added to chat history and sent to the AI service. Use the event argument to intercept message delivery, access user input and attached files, and reference the AI Chat component.

    For example, you can log a message to a database, remove personally identifiable information (PII) from the message text, add system instructions, or apply custom logic.

    The following code snippet adds a system instruction before the user message is sent:

    <DxAIChat MessageSending="OnMessageSending" />
    
    @code {
        private async Task OnMessageSending(MessageSendingEventArgs args) {
            await args.Chat.AppendMessageAsync("Translate text to Spanish", ChatRole.System);
        }
    }
    

    Run Demo: AI Chat - Manual Message Processing

    Note

    Set the MessageSendingEventArgs.Cancel property to true to block automatic message delivery and use the DxAIChat.SendMessageAsync method to send the message to the AI service manually.

    See Also