mm

package
v0.5.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: 11 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

func IsUnauthorized added in v0.5.0

func IsUnauthorized(err error) bool

IsUnauthorized reports a rejected token or failed login from Mattermost itself (its errors carry an id); a proxy's 401 page may be transient.

Types

type Channel

type Channel struct {
	ID          string `json:"id"`
	TeamID      string `json:"team_id"`
	Name        string `json:"name"`
	DisplayName string `json:"display_name"`
	// Type is O (public), P (private), D (direct) or G (group message).
	Type string `json:"type"`
}

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. With an empty loginID (access token auth) there is nothing to re-log-in with, so a 401 is returned as is.

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) CreateDirectChannel added in v0.3.0

func (c *Client) CreateDirectChannel(ctx context.Context, userID, otherID string) (*Channel, error)

CreateDirectChannel returns the direct channel between two users; the server returns the existing one if it was created before.

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) DialWS added in v0.5.0

func (c *Client) DialWS(ctx context.Context, connID string, nextSeq int64) (*WSConn, error)

DialWS opens the event websocket. A non-empty connID with nextSeq asks the server to resume that connection and replay events from nextSeq.

func (*Client) GetChannel added in v0.4.0

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

GetChannel fetches a channel 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) GetUserByUsername added in v0.3.0

func (c *Client) GetUserByUsername(ctx context.Context, username string) (*User, error)

GetUserByUsername resolves a user by username.

func (*Client) Login

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

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

func (*Client) Me added in v0.2.0

func (c *Client) Me(ctx context.Context) (*User, error)

Me returns the user the current token belongs to.

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"`
	// TimeZoneOffset (seconds) sets the day boundaries of after:/before:.
	TimeZoneOffset int `json:"time_zone_offset"`
}

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

type WSConn added in v0.5.0

type WSConn struct {
	// contains filtered or unexported fields
}

WSConn is an authenticated websocket connection to the server.

func (*WSConn) CloseNow added in v0.5.0

func (w *WSConn) CloseNow() error

CloseNow drops the connection without a close handshake, which could otherwise stall on a dead peer.

func (*WSConn) Next added in v0.5.0

func (w *WSConn) Next(ctx context.Context) (*WSEvent, error)

Next blocks until the next event. Replies to client requests are skipped.

func (*WSConn) Ping added in v0.5.0

func (w *WSConn) Ping(ctx context.Context) error

Ping sends a ping and waits for the pong; it needs a concurrent Next.

type WSEvent added in v0.5.0

type WSEvent struct {
	Event string                     `json:"event"`
	Data  map[string]json.RawMessage `json:"data"`
	Seq   int64                      `json:"seq"`
}

WSEvent is one server-pushed websocket event.

Jump to

Keyboard shortcuts

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