Plugin.Maui.Chat 0.2.0-preview1

This is a prerelease version of Plugin.Maui.Chat.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Plugin.Maui.Chat --version 0.2.0-preview1                
NuGet\Install-Package Plugin.Maui.Chat -Version 0.2.0-preview1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Plugin.Maui.Chat" Version="0.2.0-preview1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Plugin.Maui.Chat --version 0.2.0-preview1                
#r "nuget: Plugin.Maui.Chat, 0.2.0-preview1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Plugin.Maui.Chat as a Cake Addin
#addin nuget:?package=Plugin.Maui.Chat&version=0.2.0-preview1&prerelease

// Install Plugin.Maui.Chat as a Cake Tool
#tool nuget:?package=Plugin.Maui.Chat&version=0.2.0-preview1&prerelease                

alternate text is missing from this package README image

Plugin.Maui.Chat

Plugin.Maui.Chat provides highly customizable chat control. By default colors corresponds to those set in Resources\Styles\Colors.xaml, but can be easily changed (see: Customized usage).

As for now this control enables only text messaging but soon it will be upgraded with some additional features like voice messages, speech-to-text transcription, text-to-speech converter and much more:)

The UI was tested only on Android. In near future the Windows version will also be polished.

Install Plugin

NuGet

Available on NuGet.

Install with the dotnet CLI: dotnet add package Plugin.Maui.Chat, or through the NuGet Package Manager in Visual Studio.

Supported Platforms

Platform Minimum Version Supported
iOS 11+
macOS 10.15+
Android 5.0 (API 21)
Windows 11 and 10 version 1809+

API Usage

Chat control may be roughly divided in two fields:

  • the list of messages of ChatMessages type;
  • the user message entry field with buttons attached.

ChatMessage consist four properties:

  • DateTime which is getter only and provides the date and time at which ChatMessage was created. The visibility of message timestamp can be set by related property (see: Sent and received messages);
  • Type of MessageType which can be Sent (written by user), Received (sent to the user) or System (informational type).
  • Author of string type is the author of the message. The visibility of message author can be set by related property (see: Sent and received messages);
  • Text is message's content

The send button is by default disabled if the field is empty or consist only whitespace characters.

Visibility of other buttons in the user message entry field as well as their's icons, colors and behaviors can be easily switched on or off. See: Customized usage.

Below examples assumes using MVVM architecture with ViewModel binded to the XAML page.

Dependency Injection

This NuGet depends on MAUI Community Toolkit, so you will first need to register the Feature with the MAUI Community Toolkit.

builder.UseMauiCommunityToolkit();

XAML

To use Chat you need to register Plugin.Maui.Chat.Controls namespace by adding below line to XAML file opening tag.

Make sure you are adding Plugin.Maui.Chat.Controls namespace, not the Plugin.Maui.Chat!

<ContentPage ...
             xmlns:chat="clr-namespace:Plugin.Maui.Chat.Controls;assembly=Plugin.Maui.Chat"
             ...>

Simple usage

All you have to do to get started is feed these three properties:

XAML:

<chat:Chat UserMessage="{Binding UserMessage}"
           ChatMessages="{Binding ChatMessages}"
           SendMessageCommand="{Binding SendMessageCommand}"
           Margin="10"/>

ViewModel:

[ObservableProperty]
string? _userMessage;

public ObservableCollection<ChatMessage> ChatMessages { get; set; } = [];

[RelayCommand]
async Task SendMessageAsync()
{
    ...
}

Customized usage

Below you will find code snippets for each section of Chat control and some descriptions.

Messages
Sent and received messages

The properties in both are analogous and related to colors of texts and background as well as visibility of message's author and timestamp fields.

SentMessageBackgroundColor="{StaticResource Primary}"
IsSentMessageAuthorVisible="True"
SentMessageAuthorTextColor="{StaticResource Secondary}"
IsSentMessageTimestampVisible="True"
SentMessageTimestampTextColor="{StaticResource Secondary}"
SentMessageContentTextColor="{StaticResource Secondary}"

ReceivedMessageBackgroundColor="{StaticResource Secondary}"
IsReceivedMessageAuthorVisible="True"
ReceivedMessageAuthorTextColor="{StaticResource Tertiary}"
IsReceivedMessageTimestampVisible="True"
ReceivedMessageTimestampTextColor="{StaticResource Tertiary}"
ReceivedMessageContentTextColor="{StaticResource Primary}"
System message

You can set text and background color.

SystemMessageBackgroundColor="{StaticResource Gray200}"
SystemMessageTextColor="{StaticResource Gray900}"
Status field

Status is a field just above the user entry. The purpose of this field is to inform user about some actions taking place, i.e. "Sandy is typing..."

Status="{Binding Status}"
IsStatusVisible="{Binding IsStatusVisible}"
StatusTextColor="{StaticResource Gray500}"

Status is a string type. IsStatusVisible is a bool type.

Buttons
Send message

By default button is disabled when user message entry is empty or consist only whitespace characters. This can be changed by setting the IsSendMessageEnabled property.

By default button is not visible, but it has already set icon and color. You can easily change button's icon, color, visibility and of course bind the method (command) triggered by pushing the button.

SendMessageCommand="{Binding SendMessageCommand}"
IsSendMessageVisible="True"
SendMessageIcon="{Static resources:Icons.PaperPlane}"
SendMessageColor="{StaticResource Primary}"
Start/stop record toggle, Hands-free mode toggle, Take photo and Add attachment buttons

Analogous to Send message button there are already presetted colors and icon's which can easily be changed by related properties. For now there are no default commands binded to buttons.

StartStopRecordToggleCommand="{Binding StartStopRecordToggleCommand}"
IsStartStopRecordToggleVisible="True"
StartStopRecordToggleIcon="{Static resources:Icons.Microphone}"

HandsFreeModeToggleCommand="{Binding HandsFreeModeToggleCommand}"
IsHandsFreeModeToggleVisible="True"
HandsFreeModeToggleIcon="{Static resources:Icons.Headphones}"

AddAttachmentCommand="{Binding AddAttachmentCommand}"
IsAddAttachmentVisible="True"
AddAttachmentIcon="{Static resources:Icons.PaperClip}"
AddAttachmentColor="{StaticResource Primary}"

TakePhotoCommand="{Binding TakePhotoCommand}"
IsTakePhotoVisible="True"
TakePhotoIcon="{Static resources:Icons.Camera}"
TakePhotoColor="{StaticResource Primary}"

Credits

All icons comes from flaticon.com's UICONS series.

Product Compatible and additional computed target framework versions.
.NET net8.0-android34.0 is compatible.  net8.0-ios17.5 is compatible.  net8.0-maccatalyst17.5 is compatible.  net8.0-windows10.0.19041 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Plugin.Maui.Chat:

Package Downloads
Plugin.Maui.ChatGPT

Provides text and voice communication with OpenAI's ChatGPT.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.1 153 10/13/2024
2.0.0 96 10/11/2024
1.0.1 97 10/10/2024
1.0.0 76 10/10/2024
0.4.4 81 10/8/2024
0.4.3 81 10/8/2024
0.4.2 86 10/6/2024
0.4.1 91 10/6/2024
0.4.0 90 10/5/2024
0.3.0 97 9/28/2024
0.3.0-preview4 82 9/26/2024
0.2.2 104 9/8/2024
0.2.1 120 9/7/2024
0.2.0-preview1 101 9/6/2024
0.1.2-preview1 99 9/2/2024