New to Telerik UI for .NET MAUI? Start a free 30-day trial

.NET MAUI Chat Suggested Actions

The RadChat control enables you to add suggestions for the users. You can achieve this by adding SuggestedActionsItem instances to the Items collection of RadChat.

Adding the Suggested Actions

The following example demonstrates how to create and set up a SuggestedActionsItem:

this.chat.Items.Add(new TextMessage { Text = "Hello" });
this.chat.Items.Add(new TextMessage { Text = "Hi", Author = this.chat.Author });
this.chat.Items.Add(new TextMessage { Text = "How can I help you?" });
this.chat.Items.Add(new TextMessage { Text = "I need help with buying some tickets.", Author = this.chat.Author });
this.chat.Items.Add(new TimeBreak() { Text = "Last read (Time Break)" });
this.chat.Items.Add(new TextMessage { Text = "Here's a list of possible actions:" });

var suggestedActionsItem = new SuggestedActionsItem();
suggestedActionsItem.Actions = this.GetSuggestedActions(suggestedActionsItem);
this.chat.Items.Add(suggestedActionsItem);

Then, the GetSuggestedActions method populates the Actions property with a collection of SuggestedAction items:

private ICollection<SuggestedAction> GetSuggestedActions(SuggestedActionsItem suggestedActionsItem)
{
    var actions = new List<SuggestedAction>();

    for (int i = 0; i < 5; i++)
    {
        int actionIndex = i;
        actions.Add(new SuggestedAction
        {
            Text = "Action " + i,
            Command = new Command(() =>
            {
                this.chat.Items.Remove(suggestedActionsItem);
                this.chat.Items.Add(new TextMessage { Author = this.chat.Author, Text = "Action " + actionIndex });
            }),
        });
    }
    return actions;
}

RadChat with suggested actions

.NET MAUI Chat with suggested actions

See Also

In this article