Skip to main content
All docs
V26.1
  • AIChatControl.SendMessageAsync(String, List<IAIChatMessageContextItem>) Method

    Sends a message to the AI service.

    Namespace: DevExpress.AIIntegration.Wpf.Chat

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

    NuGet Package: DevExpress.AIIntegration.Wpf.Chat

    Declaration

    public Task SendMessageAsync(
        string text,
        List<IAIChatMessageContextItem> contexts = null
    )

    Parameters

    Name Type Description
    text String

    The message text.

    Optional Parameters

    Name Type Default Description
    contexts List<IAIChatMessageContextItem> null

    A collection of context items associated with the message.

    Returns

    Type Description
    Task

    A task that completes when the message is sent.

    Remarks

    To manually process messages sent to an AI service, handle the MessageSending event. For example, you can manually call the AI client or service of choice, and return its responses to the chat. The following example adds responses to user questions:

    <dxaichat:AIChatControl x:Name="aiChatControl"
                    MessageSending="AiChatControl_MessageSending"
                    HorizontalAlignment="Stretch" 
                    VerticalAlignment="Stretch" 
                    Margin="10">
    </dxaichat:AIChatControl>
    
    async void AiChatControl_MessageSending(object sender, AIChatControlMessageSendingEventArgs e) {
        e.Cancel = true; 
        await e.Chat.SendMessageAsync($"Processed: {e.Content}", ChatRole.User);
    }
    

    Note

    Set the e.Cancel event parameter to true to block automatic message delivery and use the AIChatControl.SendMessageAsync method to send the message to the AI service manually.

    Refer to the following help topic for additional information: AI Chat Control

    See Also