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 ¶
- func IsUnauthorized(err error) bool
- type Channel
- type Client
- func (c *Client) CreateDirectChannel(ctx context.Context, userID, otherID string) (*Channel, error)
- func (c *Client) CreatePost(ctx context.Context, channelID, message, rootID string, fileIDs []string) (*Post, error)
- func (c *Client) DeletePost(ctx context.Context, id string) error
- func (c *Client) DialWS(ctx context.Context, connID string, nextSeq int64) (*WSConn, error)
- func (c *Client) DownloadFile(ctx context.Context, id string, w io.Writer) error
- func (c *Client) GetChannel(ctx context.Context, id string) (*Channel, error)
- func (c *Client) GetChannelByName(ctx context.Context, teamID, name string) (*Channel, error)
- func (c *Client) GetFileInfo(ctx context.Context, id string) (*FileInfo, error)
- func (c *Client) GetPost(ctx context.Context, id string) (*Post, error)
- func (c *Client) GetTeamByName(ctx context.Context, name string) (*Team, error)
- func (c *Client) GetThread(ctx context.Context, id string) (*PostList, error)
- func (c *Client) GetUserByUsername(ctx context.Context, username string) (*User, error)
- func (c *Client) Login(ctx context.Context) error
- func (c *Client) Me(ctx context.Context) (*User, error)
- func (c *Client) Search(ctx context.Context, teamID string, opts SearchOpts) (*PostList, error)
- func (c *Client) SearchFiles(ctx context.Context, teamID string, opts SearchOpts) (*FileInfoList, error)
- func (c *Client) UploadFile(ctx context.Context, channelID, path string) (*FileInfo, error)
- func (c *Client) UsersByIDs(ctx context.Context, ids []string) ([]User, error)
- type FileInfo
- type FileInfoList
- type Post
- type PostList
- type SearchOpts
- type Team
- type User
- type WSConn
- type WSEvent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsUnauthorized ¶ added in v0.5.0
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 (*Client) CreateDirectChannel ¶ added in v0.3.0
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, fileIDs []string) (*Post, error)
CreatePost posts a message to a channel. rootID, if non-empty, makes it a threaded reply; fileIDs attach previously uploaded files.
func (*Client) DeletePost ¶
DeletePost deletes a post by ID.
func (*Client) DialWS ¶ added in v0.5.0
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) DownloadFile ¶ added in v0.6.0
DownloadFile copies an attachment's content to w, re-logging-in once on a 401 like other requests.
func (*Client) GetChannel ¶ added in v0.4.0
GetChannel fetches a channel by ID.
func (*Client) GetChannelByName ¶
GetChannelByName resolves a channel by name within a team.
func (*Client) GetFileInfo ¶ added in v0.6.0
GetFileInfo fetches attachment metadata.
func (*Client) GetTeamByName ¶
GetTeamByName resolves a team by its URL name.
func (*Client) GetUserByUsername ¶ added in v0.3.0
GetUserByUsername resolves a user by username.
func (*Client) Search ¶
Search runs a posts search within a team. terms may contain Mattermost modifiers (in:, from:, before:, after:).
func (*Client) SearchFiles ¶ added in v0.6.0
func (c *Client) SearchFiles(ctx context.Context, teamID string, opts SearchOpts) (*FileInfoList, error)
SearchFiles runs a file search (names and extracted content) within a team.
func (*Client) UploadFile ¶ added in v0.7.0
UploadFile uploads a local file into a channel and returns its info; the file is attached once a post references its ID.
type FileInfo ¶ added in v0.6.0
type FileInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Extension string `json:"extension"`
Size int64 `json:"size"`
MimeType string `json:"mime_type"`
PostID string `json:"post_id"`
ChannelID string `json:"channel_id"`
UserID string `json:"user_id"`
CreateAt int64 `json:"create_at"`
}
FileInfo describes an attachment (subset).
type FileInfoList ¶ added in v0.6.0
type FileInfoList struct {
Order []string `json:"order"`
FileInfos map[string]*FileInfo `json:"file_infos"`
}
FileInfoList is a file search result. Order is newest-first.
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"`
Metadata struct {
Files []FileInfo `json:"files"`
} `json:"metadata"`
}
Post is a single Mattermost post (subset of fields we use).
type PostList ¶
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 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
CloseNow drops the connection without a close handshake, which could otherwise stall on a dead peer.