mm

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mm is a thin Mattermost REST client covering only the endpoints mmcli needs: login, fetch post/thread, search, create post, and resolve teams/channels/users. It is intentionally not the official SDK.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel struct {
	ID          string `json:"id"`
	TeamID      string `json:"team_id"`
	Name        string `json:"name"`
	DisplayName string `json:"display_name"`
}

Channel is a Mattermost channel (subset).

type Client

type Client struct {

	// OnToken, if set, is called whenever a new session token is obtained.
	OnToken func(token string)
	// contains filtered or unexported fields
}

Client talks to one Mattermost server. It is stateless across processes: a session token is cached by the caller (in the keyring) and passed back in. On a 401 the client re-logs-in once using loginID/password, then retries, and reports the fresh token via OnToken.

func New

func New(baseURL, token, loginID, password string) *Client

New builds a client. token may be empty (a request will then trigger login).

func (*Client) CreatePost

func (c *Client) CreatePost(ctx context.Context, channelID, message, rootID string) (*Post, error)

CreatePost posts a message to a channel. rootID, if non-empty, makes it a threaded reply.

func (*Client) DeletePost

func (c *Client) DeletePost(ctx context.Context, id string) error

DeletePost deletes a post by ID.

func (*Client) GetChannelByName

func (c *Client) GetChannelByName(ctx context.Context, teamID, name string) (*Channel, error)

GetChannelByName resolves a channel by name within a team.

func (*Client) GetPost

func (c *Client) GetPost(ctx context.Context, id string) (*Post, error)

GetPost fetches a single post by ID.

func (*Client) GetTeamByName

func (c *Client) GetTeamByName(ctx context.Context, name string) (*Team, error)

GetTeamByName resolves a team by its URL name.

func (*Client) GetThread

func (c *Client) GetThread(ctx context.Context, id string) (*PostList, error)

GetThread fetches the full thread containing the given post.

func (*Client) Login

func (c *Client) Login(ctx context.Context) error

Login authenticates with login_id/password and stores the session token.

func (*Client) Search

func (c *Client) Search(ctx context.Context, teamID string, opts SearchOpts) (*PostList, error)

Search runs a posts search within a team. terms may contain Mattermost modifiers (in:, from:, before:, after:).

func (*Client) UsersByIDs

func (c *Client) UsersByIDs(ctx context.Context, ids []string) ([]User, error)

UsersByIDs resolves usernames for a set of user IDs.

type Post

type Post struct {
	ID        string `json:"id"`
	CreateAt  int64  `json:"create_at"`
	UpdateAt  int64  `json:"update_at"`
	UserID    string `json:"user_id"`
	ChannelID string `json:"channel_id"`
	RootID    string `json:"root_id"`
	Message   string `json:"message"`
}

Post is a single Mattermost post (subset of fields we use).

type PostList

type PostList struct {
	Order []string         `json:"order"`
	Posts map[string]*Post `json:"posts"`
}

PostList is Mattermost's ordered post collection (threads, search results). Order lists post IDs newest-first; Posts maps ID -> Post.

type SearchOpts

type SearchOpts struct {
	Terms      string `json:"terms"`
	IsOrSearch bool   `json:"is_or_search"`
	Page       int    `json:"page"`
	PerPage    int    `json:"per_page"`
}

SearchOpts mirrors the Mattermost search request body fields we use.

type Team

type Team struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	DisplayName string `json:"display_name"`
}

Team is a Mattermost team (subset).

type User

type User struct {
	ID       string `json:"id"`
	Username string `json:"username"`
}

User is a Mattermost user (subset).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL