Skip to content

bvdcode/Mattermost.NET

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Nuget Static Badge GitHub Actions Workflow Status NuGet version (Mattermost.NET) CodeFactor GitHub repo size

Mattermost.NET

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.


Installation

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

Usage

Create a new bot

using Mattermost.NET;
const string server = "https://mm.your-server.com"; // or https://community.mattermost.com by default
MattermostClient client = new(server);

Authenticate the bot with credentials

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);

Subscribe to post updates

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!");
}

Start the bot updates

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.

Stop the bot

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.


License

Distributed under the MIT License. See LICENSE.md for more information.

Contact

E-Mail

About

.NET SDK for Mattermost v4 API with WebSocket real-time updates

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages