Back to Devexpress

DxAIChat.MessageSent Event

blazor-devexpress-dot-aiintegration-dot-blazor-dot-chat-dot-dxaichat-16a7bc89.md

latest2.4 KB
Original Source

DxAIChat.MessageSent Event

Fires after a user sends a message to the chat and allows you to manually process the message.

Namespace : DevExpress.AIIntegration.Blazor.Chat

Assembly : DevExpress.AIIntegration.Blazor.Chat.v25.2.dll

NuGet Package : DevExpress.AIIntegration.Blazor.Chat

Declaration

csharp
[Parameter]
public EventCallback<MessageSentEventArgs> MessageSent { get; set; }

Parameters

TypeDescription
MessageSentEventArgs

An object that contains data for this event.

|

Remarks

When a user sends a message to the chat, the MessageSent event fires. Handle this event to process this action.

Warning

The custom MessageSent event handler completely overrides the AI Chat control’s automatic message delivery. If you do not explicitly send the message in your event handler, the loading animation cycles endlessly, and the chat prompt always displays the Stop Generation button.

Use the Content event argument to access user input and the AI Chat object.

razor
<DxAIChat MessageSent="MessageSent"
          FileUploadEnabled="true" />

@code {
    async Task MessageSent(MessageSentEventArgs args) {
        if(args.Files != null && args.Files.Count > 0) {
            var fileNames = args.Files.Select(x => x.Name);
            var response = $"Processed message content: {args.Content}.{System.Environment.NewLine}";
            response += $"The message contains {args.Files.Count} attached file(s):{System.Environment.NewLine}";
            response += string.Join(System.Environment.NewLine, fileNames);
            await args.Chat.SendMessage(response, ChatRole.Assistant);
        }
    }
}

Run Demo: AI Chat - Manual Message Processing

See Also

DxAIChat Class

DxAIChat Members

DevExpress.AIIntegration.Blazor.Chat Namespace