Ready-to-use .NET Standard library for convenient development of Mattermost bots.
Mattermost.NET is a production-ready .NET Standard library for building bots and integrations for the Mattermost platform. It provides a clean, strongly-typed C# interface over the Mattermost API, with support for messaging, channel management, file uploads, and real-time WebSocket updates. The client handles authentication, reconnection, and offers async methods for most operations. Published on NuGet under the MIT license.
The library is available as a NuGet package. You can install it using the NuGet Package Manager or the dotnet
CLI.
dotnet add package Mattermost.NET
using Mattermost.NET;
const string server = "https://mm.your-server.com"; // or https://community.mattermost.com by default
MattermostClient client = new(server);
var botUser = await client.LoginAsync(username, password);
// Or you can use constructor if you have API key, ex. personal or bot token
// It will automatically authenticate the bot
const string token = "37VlFKySIZn6gryA85cR1GKBQkjmfRZ6";
MattermostClient client = new(server, token);
client.OnMessageReceived += ClientOnMessageReceived;
private static void ClientOnMessageReceived(object? sender, MessageEventArgs e)
{
if (string.IsNullOrWhiteSpace(e.Message.Post.Text))
{
return;
}
e.Client.SendMessageAsync(e.Message.Post.ChannelId, "Hello, World!");
}
await client.StartReceivingAsync();
Note: The bot will automatically reconnect if the connection is lost. It's not required to call
StartReceivingAsync
if you don't want to receive updates through the WebSocket connection.
await client.StopReceivingAsync();
The rest of the methods are implemented according to the Mattermost API. You can find them in IMattermostClient.
If you are looking for another methods, please visit the Mattermost API documentation and create an issue in the GitHub repository with what exact methods you need - I will add them as soon as possible.
Distributed under the MIT License. See LICENSE.md for more information.