SDKs overview

Mattermost provides Software Development Kits (SDKs) and client libraries designed to facilitate programmatic interaction with its platform. These tools enable developers to build custom applications, automate workflows, create bots, and integrate Mattermost with other systems. The SDKs abstract the underlying REST API and WebSocket API details, allowing developers to focus on application logic rather than low-level HTTP requests or WebSocket message parsing. Mattermost's open-source nature extends to its SDKs, encouraging community contributions and broader language support beyond the officially maintained versions.

The official Mattermost SDKs are primarily maintained for Go and JavaScript, reflecting the platform's core development languages and common integration needs. These SDKs are developed to ensure compatibility with Mattermost server versions and provide a stable interface for developers. The Go SDK is often utilized for server-side applications, command-line tools, and backend integrations, while the JavaScript SDK is typically used for web-based clients, browser extensions, and Node.js applications. Both SDKs offer methods for authentication, user management, channel operations, message posting, and real-time event handling via WebSockets, providing comprehensive access to Mattermost functionalities as detailed in the Mattermost API reference documentation.

Official SDKs by language

Mattermost officially supports SDKs for Go and JavaScript. These SDKs are developed and maintained by the Mattermost core team, ensuring they are kept up-to-date with server API changes and best practices. Developers are encouraged to use these official libraries for robust and reliable integrations.

Language Package/Module Install Command Maturity Use Case
Go github.com/mattermost/mattermost-server/v6/model go get github.com/mattermost/mattermost-server/v6/model Stable Server-side applications, CLI tools, backend integrations, custom plugins
JavaScript mattermost-redux (for web/React), mattermost-client (for Node.js) npm install mattermost-redux or npm install mattermost-client Stable Web applications, desktop clients, Node.js bots, browser extensions

The Go SDK provides a structured way to interact with the Mattermost API, offering client methods for various actions such as creating users, posting messages, and managing channels. It is designed to be idiomatic Go, making it accessible for developers familiar with the language. For instance, the mattermost-server/v6/model package includes data structures and client functions that map directly to the Mattermost REST API endpoints. This allows for type-safe development and reduces the boilerplate code typically required for raw HTTP requests.

The JavaScript ecosystem for Mattermost is split into a few key packages. mattermost-redux is a core library used within the official Mattermost web and desktop clients, providing a Redux-based state management layer for API interactions. For Node.js environments or simpler client implementations, mattermost-client offers a direct API client. These libraries facilitate real-time updates via WebSockets, enabling applications to react to new messages, user status changes, and other events as they occur on the Mattermost server. Developers building custom Mattermost clients or integrations often consult the Mattermost developer reference client documentation for examples and best practices.

Installation

Installing the Mattermost SDKs involves using standard package managers for Go and JavaScript environments. Ensure your development environment is correctly set up for the respective language.

Go SDK Installation

To install the Go SDK, you typically use the go get command. This command fetches the specified package and its dependencies and installs them in your Go module cache. For the Mattermost Go SDK, which is part of the server repository, you would use:

go get github.com/mattermost/mattermost-server/v6/model

After running this command, the model package and its dependencies will be available for import in your Go projects. Ensure your Go environment variables (like GOPATH and GOBIN) are correctly configured, though modern Go module usage often handles this automatically.

JavaScript SDK Installation

For JavaScript projects, you'll use npm (Node Package Manager) or yarn. The choice of package depends on your specific use case:

For web applications or React-based clients (using mattermost-redux):

npm install mattermost-redux

or

yarn add mattermost-redux

For Node.js applications or simpler client interactions (using mattermost-client):

npm install mattermost-client

or

yarn add mattermost-client

These commands add the respective packages to your project's node_modules directory and update your package.json file. You can then import and use the client in your JavaScript or TypeScript files.

Quickstart example

This quickstart example demonstrates how to use the Mattermost Go SDK to create a client, log in, and post a message to a channel. This assumes you have a running Mattermost server and valid credentials.

Go SDK Quickstart: Post a Message

First, create a new Go file (e.g., main.go) and add the following code:

package main

import (
	"fmt"
	"log"

	"github.com/mattermost/mattermost-server/v6/model"
)

func main() {
	// Configuration
	serverURL := "http://localhost:8065" // Replace with your Mattermost server URL
	username := "your_username"
	password := "your_password"
	teamName := "your_team_name"
	channelName := "town-square"
	messageContent := "Hello from Go SDK!"

	// Create a new client
	client := model.NewAPIv4Client(serverURL)

	// Log in to Mattermost
	user, _, err := client.Login(username, password)
	if err != nil {
		log.Fatalf("Failed to log in: %s", err.Error())
	}
	fmt.Printf("Logged in as: %s\n", user.Username)

	// Get the target team
	team, _, err := client.GetTeamByName(teamName, "")
	if err != nil {
		log.Fatalf("Failed to get team '%s': %s", teamName, err.Error())
	}

	// Get the target channel
	channel, _, err := client.GetChannelByName(channelName, team.Id, "")
	if err != nil {
		log.Fatalf("Failed to get channel '%s' in team '%s': %s", channelName, teamName, err.Error())
	}

	// Create a new post object
	post := &model.Post{
		ChannelId: channel.Id,
		Message:   messageContent,
	}

	// Post the message
	_, _, err = client.CreatePost(post)
	if err != nil {
		log.Fatalf("Failed to create post: %s", err.Error())
	}
	fmt.Println("Message posted successfully!")

	// Logout (optional)
	_, err = client.Logout()
	if err != nil {
		log.Printf("Warning: Failed to log out: %s", err.Error())
	}
}

Before running:

  1. Replace http://localhost:8065 with the actual URL of your Mattermost server.
  2. Update your_username and your_password with valid Mattermost user credentials.
  3. Set your_team_name to an existing team where the user has access.
  4. Ensure the town-square channel exists, or change channelName to another accessible channel.

To run this example:

go run main.go

This script will log into your Mattermost instance, retrieve the specified team and channel, and then post a message. Error handling is included to catch common issues during the process. For more complex interactions, such as listening to WebSocket events or managing users, refer to the Mattermost Go client integration guide.

Community libraries

Beyond the official Go and JavaScript SDKs, the open-source nature of Mattermost has led to the development of various community-contributed libraries and wrappers for other programming languages. These libraries are typically maintained by individual developers or community groups and may vary in their level of completeness, documentation, and active maintenance. Developers exploring these options should review the project's GitHub repository for activity, issue resolution, and compatibility with their Mattermost server version.

Some examples of community-driven efforts include:

  • Python Clients: Several Python libraries exist, offering different levels of abstraction over the Mattermost REST API. These are popular for scripting, creating bots, and integrating with Python-based data processing or automation tools. Developers can search for mattermost python client on package repositories like PyPI to find available options.
  • PHP Clients: For PHP applications, community libraries provide interfaces to interact with Mattermost, often used for webhooks, custom commands, and integrations with content management systems or backend services.
  • Ruby Clients: Ruby gems are available that wrap the Mattermost API, allowing Ruby developers to build bots or integrate Mattermost into Ruby on Rails applications.
  • Rust Clients: Emerging Rust libraries cater to developers seeking performance and memory safety, providing asynchronous clients for Mattermost interactions.

When considering a community library, it is advisable to:

  • Check Repository Activity: Look for recent commits, active pull requests, and responsive issue tracking.
  • Review Documentation: Ensure the library has clear documentation and examples.
  • Verify Compatibility: Confirm the library supports the Mattermost API version you are targeting. Mattermost's API documentation notes versioning practices, which can be helpful when assessing third-party client compatibility, as detailed in the Mattermost API upgrade guide.
  • Examine License: Understand the licensing terms of the community library.

While official SDKs offer guaranteed compatibility and support, community libraries extend Mattermost's reach into diverse programming environments, fostering a broader ecosystem of integrations and custom solutions. For instance, developers frequently use Python to create bots, as highlighted by various community tutorials on building conversational agents and integrations, which can then interact with Mattermost via these community-supported clients.