pluginapi

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: Apache-2.0 Imports: 23 Imported by: 66

README

mattermost-plugin-api

GoDoc ci Code Coverage

A hackathon project to explore reworking the Mattermost Plugin API.

The plugin API as exposed in github.com/mattermost/mattermost-server/plugin began with the hope of adopting a consistent interface and style. But our vision for how to structure the API changed over time, along with our ability to remain consistent.

Fixing the API in place is difficult. Any backwards incompatible changes to the RPC API would break existing plugins. Even backwards incompatible changes to the plugin helpers would break semver, requiring a coordinated major version bump with parent repository. Adding new methods improves the experience for newer plugins, but forever clutters the plugin GoDoc.

Instead, we opted to wrap the existing RPC API and helpers with a client hosted in this separate repository. Issues fixed and improvements added include:

  • *model.AppError eliminated for all API calls, correctly returning an error interface instead
  • methods logically organized by service instead of a flat API (e.g. client.Users.List)
  • custom types eliminated in favour of simple splices (e.g. []*model.ChannelMember instead of model.ChannelMembers)
  • more consistent method names (e.g. Get, List, Create, Update, Delete)
  • functional pattern for optional parameters (e.g. List(teamId, page, perPage, ...TeamListOption))

The API exposed by this client officially replaces direct use of the RPC API and helpers. While we will maintain backwards compatibility with the existing RPC API, we may bump the major version of this repository in coordination with a breaking semver change. This will affect only plugin authors who opt in to the newer package, and existing plugins will continue to compile and run without changes using the older version of the package.

Usage of this package is altogether optional, allowing plugin authors to switch to this package as needed. However, note that all new helpers and abstractions over the RPC API are expected to be added only to this package.

Getting Started

This package is in a pre-alpha state. To start using this API with your own plugin, first change all your import statements to reference the newly moduled v6 version of the Mattermost server:

import (
-    "github.com/mattermost/mattermost-server"
+    "github.com/mattermost/mattermost-server/v6"
)

Finally, add this package as a dependency:

go get github.com/mattermost/mattermost-plugin-api

Migration Guide

(This section is a work in progress)

A complete migration guide from the old API to the new API is as follows:

	LoadPluginConfiguration(dest interface{}) error
	RegisterCommand(command *model.Command) error
	UnregisterCommand(teamId, trigger string) error
	GetSession(sessionId string) (*model.Session, *model.AppError)
	GetConfig() *model.Config
	GetUnsanitizedConfig() *model.Config
	SaveConfig(config *model.Config) *model.AppError
	GetPluginConfig() map[string]interface{}
	SavePluginConfig(config map[string]interface{}) *model.AppError
	GetBundlePath() (string, error)
	GetLicense() *model.License
	GetServerVersion() string
	GetSystemInstallDate() (int64, *model.AppError)
	GetDiagnosticId() string
	CreateUser(user *model.User) (*model.User, *model.AppError)
	DeleteUser(userId string) *model.AppError
	GetUsers(options *model.UserGetOptions) ([]*model.User, *model.AppError)
	GetUser(userId string) (*model.User, *model.AppError)
	GetUserByEmail(email string) (*model.User, *model.AppError)
	GetUserByUsername(name string) (*model.User, *model.AppError)
	GetUsersByUsernames(usernames []string) ([]*model.User, *model.AppError)
	GetUsersInTeam(teamId string, page int, perPage int) ([]*model.User, *model.AppError)
	GetTeamIcon(teamId string) ([]byte, *model.AppError)
	SetTeamIcon(teamId string, data []byte) *model.AppError
	RemoveTeamIcon(teamId string) *model.AppError
	UpdateUser(user *model.User) (*model.User, *model.AppError)
	GetUserStatus(userId string) (*model.Status, *model.AppError)
	GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.AppError)
	UpdateUserStatus(userId, status string) (*model.Status, *model.AppError)
	UpdateUserActive(userId string, active bool) *model.AppError
	GetUsersInChannel(channelId, sortBy string, page, perPage int) ([]*model.User, *model.AppError)
	GetLDAPUserAttributes(userId string, attributes []string) (map[string]string, *model.AppError)
	CreateTeam(team *model.Team) (*model.Team, *model.AppError)
	DeleteTeam(teamId string) *model.AppError
	GetTeams() ([]*model.Team, *model.AppError)
	GetTeam(teamId string) (*model.Team, *model.AppError)
	GetTeamByName(name string) (*model.Team, *model.AppError)
	GetTeamsUnreadForUser(userId string) ([]*model.TeamUnread, *model.AppError)
	UpdateTeam(team *model.Team) (*model.Team, *model.AppError)
	SearchTeams(term string) ([]*model.Team, *model.AppError)
	GetTeamsForUser(userId string) ([]*model.Team, *model.AppError)
	CreateTeamMember(teamId, userId string) (*model.TeamMember, *model.AppError)
	CreateTeamMembers(teamId string, userIds []string, requestorId string) ([]*model.TeamMember, *model.AppError)
	DeleteTeamMember(teamId, userId, requestorId string) *model.AppError
	GetTeamMembers(teamId string, page, perPage int) ([]*model.TeamMember, *model.AppError)
	GetTeamMember(teamId, userId string) (*model.TeamMember, *model.AppError)
	GetTeamMembersForUser(userId string, page int, perPage int) ([]*model.TeamMember, *model.AppError)
	UpdateTeamMemberRoles(teamId, userId, newRoles string) (*model.TeamMember, *model.AppError)
	CreateChannel(channel *model.Channel) (*model.Channel, *model.AppError)
	DeleteChannel(channelId string) *model.AppError
	GetPublicChannelsForTeam(teamId string, page, perPage int) ([]*model.Channel, *model.AppError)
	GetChannel(channelId string) (*model.Channel, *model.AppError)
	GetChannelByName(teamId, name string, includeDeleted bool) (*model.Channel, *model.AppError)
	GetChannelByNameForTeamName(teamName, channelName string, includeDeleted bool) (*model.Channel, *model.AppError)
	GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) ([]*model.Channel, *model.AppError)
	GetChannelStats(channelId string) (*model.ChannelStats, *model.AppError)
	GetDirectChannel(userId1, userId2 string) (*model.Channel, *model.AppError)
	GetGroupChannel(userIds []string) (*model.Channel, *model.AppError)
	UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError)
	SearchChannels(teamId string, term string) ([]*model.Channel, *model.AppError)
	SearchUsers(search *model.UserSearch) ([]*model.User, *model.AppError)
	SearchPostsInTeam(teamId string, paramsList []*model.SearchParams) ([]*model.Post, *model.AppError)
	AddChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError)
	AddUserToChannel(channelId, userId, asUserId string) (*model.ChannelMember, *model.AppError)
	GetChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError)
	GetChannelMembers(channelId string, page, perPage int) (*model.ChannelMembers, *model.AppError)
	GetChannelMembersByIds(channelId string, userIds []string) (*model.ChannelMembers, *model.AppError)
	GetChannelMembersForUser(teamId, userId string, page, perPage int) ([]*model.ChannelMember, *model.AppError)
	UpdateChannelMemberRoles(channelId, userId, newRoles string) (*model.ChannelMember, *model.AppError)
	UpdateChannelMemberNotifications(channelId, userId string, notifications map[string]string) (*model.ChannelMember, *model.AppError)
	GetGroup(groupId string) (*model.Group, *model.AppError)
	GetGroupByName(name string) (*model.Group, *model.AppError)
	GetGroupsForUser(userId string) ([]*model.Group, *model.AppError)
	DeleteChannelMember(channelId, userId string) *model.AppError
	CreatePost(post *model.Post) (*model.Post, *model.AppError)
	AddReaction(reaction *model.Reaction) (*model.Reaction, *model.AppError)
	RemoveReaction(reaction *model.Reaction) *model.AppError
	GetReactions(postId string) ([]*model.Reaction, *model.AppError)
	SendEphemeralPost(userId string, post *model.Post) *model.Post
	UpdateEphemeralPost(userId string, post *model.Post) *model.Post
	DeleteEphemeralPost(userId, postId string)
	DeletePost(postId string) *model.AppError
	GetPostThread(postId string) (*model.PostList, *model.AppError)
	GetPost(postId string) (*model.Post, *model.AppError)
	GetPostsSince(channelId string, time int64) (*model.PostList, *model.AppError)
	GetPostsAfter(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError)
	GetPostsBefore(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError)
	GetPostsForChannel(channelId string, page, perPage int) (*model.PostList, *model.AppError)
	GetTeamStats(teamId string) (*model.TeamStats, *model.AppError)
	UpdatePost(post *model.Post) (*model.Post, *model.AppError)
	GetProfileImage(userId string) ([]byte, *model.AppError)
	SetProfileImage(userId string, data []byte) *model.AppError
	GetEmojiList(sortBy string, page, perPage int) ([]*model.Emoji, *model.AppError)
	GetEmojiByName(name string) (*model.Emoji, *model.AppError)
	GetEmoji(emojiId string) (*model.Emoji, *model.AppError)
	CopyFileInfos(userId string, fileIds []string) ([]string, *model.AppError)
	GetFileInfo(fileId string) (*model.FileInfo, *model.AppError)
	GetFile(fileId string) ([]byte, *model.AppError)
	GetFileLink(fileId string) (string, *model.AppError)
	ReadFile(path string) ([]byte, *model.AppError)
	GetEmojiImage(emojiId string) ([]byte, string, *model.AppError)
	UploadFile(data []byte, channelId string, filename string) (*model.FileInfo, *model.AppError)
	OpenInteractiveDialog(dialog model.OpenDialogRequest) *model.AppError
	GetPlugins() ([]*model.Manifest, *model.AppError)
	EnablePlugin(id string) *model.AppError
	DisablePlugin(id string) *model.AppError
	RemovePlugin(id string) *model.AppError
	GetPluginStatus(id string) (*model.PluginStatus, *model.AppError)
	InstallPlugin(file io.Reader, replace bool) (*model.Manifest, *model.AppError)
	KVSet(key string, value []byte) *model.AppError
	KVCompareAndSet(key string, oldValue, newValue []byte) (bool, *model.AppError)
	KVCompareAndDelete(key string, oldValue []byte) (bool, *model.AppError)
	KVSetWithOptions(key string, newValue interface{}, options model.PluginKVSetOptions) (bool, *model.AppError)
	KVSetWithExpiry(key string, value []byte, expireInSeconds int64) *model.AppError
	KVGet(key string) ([]byte, *model.AppError)
	KVDelete(key string) *model.AppError
	KVDeleteAll() *model.AppError
	KVList(page, perPage int) ([]string, *model.AppError)
	PublishWebSocketEvent(event string, payload map[string]interface{}, broadcast *model.WebsocketBroadcast)
	HasPermissionTo(userId string, permission *model.Permission) bool
	HasPermissionToTeam(userId, teamId string, permission *model.Permission) bool
	HasPermissionToChannel(userId, channelId string, permission *model.Permission) bool
	LogDebug(msg string, keyValuePairs ...interface{})
	LogInfo(msg string, keyValuePairs ...interface{})
	LogError(msg string, keyValuePairs ...interface{})
	LogWarn(msg string, keyValuePairs ...interface{})
	SendMail(to, subject, htmlBody string) *model.AppError
	CreateBot(bot *model.Bot) (*model.Bot, *model.AppError)
	PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot, *model.AppError)
	GetBot(botUserId string, includeDeleted bool) (*model.Bot, *model.AppError)
	GetBots(options *model.BotGetOptions) ([]*model.Bot, *model.AppError)
	UpdateBotActive(botUserId string, active bool) (*model.Bot, *model.AppError)
	PermanentDeleteBot(botUserId string) *model.AppError
	GetBotIconImage(botUserId string) ([]byte, *model.AppError)
	SetBotIconImage(botUserId string, data []byte) *model.AppError
	DeleteBotIconImage(botUserId string) *model.AppError
	PluginHTTP(request *http.Request) *http.Response

Documentation

Overview

Example
package main

import (
	pluginapi "github.com/mattermost/mattermost-plugin-api"

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

type Plugin struct {
	plugin.MattermostPlugin
	client *pluginapi.Client
}

func (p *Plugin) OnActivate() error {
	p.client = pluginapi.NewClient(p.API, p.Driver)

	return nil
}

func main() {
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned by the plugin API when an object is not found.

Functions

func ConfigureLogrus

func ConfigureLogrus(logger *logrus.Logger, client *Client)

ConfigureLogrus configures the given logrus logger with a hook to proxy through the RPC API, discarding the default output to avoid duplicating the events across the standard STDOUT proxy.

func IsCloud added in v0.0.24

func IsCloud(license *model.License) bool

IsCloud returns true when the server is on cloud, and false otherwise.

func IsConfiguredForDevelopment added in v0.0.15

func IsConfiguredForDevelopment(config *model.Config) bool

IsConfiguredForDevelopment returns true when the server has `EnableDeveloper` and `EnableTesting` configuration settings enabled, signaling a non-production, developer mode.

func IsE10LicensedOrDevelopment added in v0.0.16

func IsE10LicensedOrDevelopment(config *model.Config, license *model.License) bool

IsE10LicensedOrDevelopment returns true when the server is at least licensed with a legacy Mattermost Enterprise E10 License or a Mattermost Professional License, or has `EnableDeveloper` and `EnableTesting` configuration settings enabled, signaling a non-production, developer mode.

func IsE20LicensedOrDevelopment added in v0.0.12

func IsE20LicensedOrDevelopment(config *model.Config, license *model.License) bool

IsE20LicensedOrDevelopment returns true when the server is licensed with a legacy Mattermost Enterprise E20 License or a Mattermost Enterprise License, or has `EnableDeveloper` and `EnableTesting` configuration settings enabled, signaling a non-production, developer mode.

func IsEnterpriseLicensedOrDevelopment added in v0.0.12

func IsEnterpriseLicensedOrDevelopment(config *model.Config, license *model.License) bool

IsEnterpriseLicensedOrDevelopment returns true when the server is licensed with any Mattermost Enterprise License, or has `EnableDeveloper` and `EnableTesting` configuration settings enabled signaling a non-production, developer mode.

Types

type BotListOption

type BotListOption func(*model.BotGetOptions)

BotListOption is an option to configure a bot List() request.

func BotIncludeDeleted

func BotIncludeDeleted() BotListOption

BotIncludeDeleted option configures bot list request to also retrieve the deleted bots.

func BotOnlyOrphans

func BotOnlyOrphans() BotListOption

BotOnlyOrphans option configures bot list request to only retrieve orphan bots.

func BotOwner

func BotOwner(id string) BotListOption

BotOwner option configures bot list request to only retrieve the bots that matches with owner's id.

type BotService

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

BotService exposes methods to manipulate bots.

func (*BotService) Create

func (b *BotService) Create(bot *model.Bot) error

Create creates the bot and corresponding user.

Minimum server version: 5.10

func (*BotService) DeletePermanently

func (b *BotService) DeletePermanently(botUserID string) error

DeletePermanently permanently deletes a bot and its corresponding user.

Minimum server version: 5.10

func (*BotService) EnsureBot added in v0.0.10

func (b *BotService) EnsureBot(bot *model.Bot, options ...EnsureBotOption) (string, error)

EnsureBot either returns an existing bot user matching the given bot, or creates a bot user from the given bot. A profile image or icon image may be optionally passed in to be set for the existing or newly created bot. Returns the id of the resulting bot. EnsureBot can safely be called multiple instances of a plugin concurrently.

Minimum server version: 5.10

func (*BotService) Get

func (b *BotService) Get(botUserID string, includeDeleted bool) (*model.Bot, error)

Get returns a bot by botUserID.

Minimum server version: 5.10

func (*BotService) List

func (b *BotService) List(page, perPage int, options ...BotListOption) ([]*model.Bot, error)

List returns a list of bots by page, count and options.

Minimum server version: 5.10

func (*BotService) Patch

func (b *BotService) Patch(botUserID string, botPatch *model.BotPatch) (*model.Bot, error)

Patch applies the given patch to the bot and corresponding user.

Minimum server version: 5.10

func (*BotService) UpdateActive

func (b *BotService) UpdateActive(botUserID string, isActive bool) (*model.Bot, error)

UpdateActive marks a bot as active or inactive, along with its corresponding user.

Minimum server version: 5.10

type ChannelService

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

ChannelService exposes methods to manipulate channels.

func (*ChannelService) AddMember

func (c *ChannelService) AddMember(channelID, userID string) (*model.ChannelMember, error)

AddMember joins a user to a channel (as if they joined themselves). This means the user will not receive notifications for joining the channel.

Minimum server version: 5.2

func (*ChannelService) AddUser

func (c *ChannelService) AddUser(channelID, userID, asUserID string) (*model.ChannelMember, error)

AddUser adds a user to a channel as if the specified user had invited them. This means the user will receive the regular notifications for being added to the channel.

Minimum server version: 5.18

func (*ChannelService) Create

func (c *ChannelService) Create(channel *model.Channel) error

Create creates a channel.

Minimum server version: 5.2

func (*ChannelService) CreateSidebarCategory added in v0.0.17

func (c *ChannelService) CreateSidebarCategory(
	userID, teamID string, newCategory *model.SidebarCategoryWithChannels) error

CreateSidebarCategory creates a new sidebar category for a set of channels.

Minimum server version: 5.38

func (*ChannelService) Delete

func (c *ChannelService) Delete(channelID string) error

Delete deletes a channel.

Minimum server version: 5.2

func (*ChannelService) DeleteMember

func (c *ChannelService) DeleteMember(channelID, userID string) error

DeleteMember deletes a channel membership for a user.

Minimum server version: 5.2

func (*ChannelService) Get

func (c *ChannelService) Get(channelID string) (*model.Channel, error)

Get gets a channel.

Minimum server version: 5.2

func (*ChannelService) GetByName

func (c *ChannelService) GetByName(teamID, channelName string, includeDeleted bool) (*model.Channel, error)

GetByName gets a channel by its name, given a team id.

Minimum server version: 5.2

func (*ChannelService) GetByNameForTeamName

func (c *ChannelService) GetByNameForTeamName(teamName, channelName string, includeDeleted bool) (*model.Channel, error)

GetByNameForTeamName gets a channel by its name, given a team name.

Minimum server version: 5.2

func (*ChannelService) GetChannelStats

func (c *ChannelService) GetChannelStats(channelID string) (*model.ChannelStats, error)

GetChannelStats gets statistics for a channel.

Minimum server version: 5.6

func (*ChannelService) GetDirect

func (c *ChannelService) GetDirect(userID1, userID2 string) (*model.Channel, error)

GetDirect gets a direct message channel.

Note that if the channel does not exist it will create it.

Minimum server version: 5.2

func (*ChannelService) GetGroup

func (c *ChannelService) GetGroup(userIDs []string) (*model.Channel, error)

GetGroup gets a group message channel.

Note that if the channel does not exist it will create it.

Minimum server version: 5.2

func (*ChannelService) GetMember

func (c *ChannelService) GetMember(channelID, userID string) (*model.ChannelMember, error)

GetMember gets a channel membership for a user.

Minimum server version: 5.2

func (*ChannelService) GetSidebarCategories added in v0.0.17

func (c *ChannelService) GetSidebarCategories(userID, teamID string) (*model.OrderedSidebarCategories, error)

GetSidebarCategories returns sidebar categories.

Minimum server version: 5.38

func (*ChannelService) ListForTeamForUser

func (c *ChannelService) ListForTeamForUser(teamID, userID string, includeDeleted bool) ([]*model.Channel, error)

ListForTeamForUser gets a list of channels for given user ID in given team ID.

Minimum server version: 5.6

func (*ChannelService) ListMembers

func (c *ChannelService) ListMembers(channelID string, page, perPage int) ([]*model.ChannelMember, error)

ListMembers gets a channel membership for all users.

Minimum server version: 5.6

func (*ChannelService) ListMembersByIDs

func (c *ChannelService) ListMembersByIDs(channelID string, userIDs []string) ([]*model.ChannelMember, error)

ListMembersByIDs gets a channel membership for a particular User

Minimum server version: 5.6

func (*ChannelService) ListMembersForUser

func (c *ChannelService) ListMembersForUser(teamID, userID string, page, perPage int) ([]*model.ChannelMember, error)

ListMembersForUser returns all channel memberships on a team for a user.

Minimum server version: 5.10

func (*ChannelService) ListPublicChannelsForTeam

func (c *ChannelService) ListPublicChannelsForTeam(teamID string, page, perPage int) ([]*model.Channel, error)

ListPublicChannelsForTeam gets a list of all channels.

Minimum server version: 5.2

func (*ChannelService) Search

func (c *ChannelService) Search(teamID, term string) ([]*model.Channel, error)

Search returns the channels on a team matching the provided search term.

Minimum server version: 5.6

func (*ChannelService) Update

func (c *ChannelService) Update(channel *model.Channel) error

Update updates a channel.

Minimum server version: 5.2

func (*ChannelService) UpdateChannelMemberNotifications

func (c *ChannelService) UpdateChannelMemberNotifications(channelID, userID string, notifications map[string]string) (*model.ChannelMember, error)

UpdateChannelMemberNotifications updates a user's notification properties for a channel.

Minimum server version: 5.2

func (*ChannelService) UpdateChannelMemberRoles

func (c *ChannelService) UpdateChannelMemberRoles(channelID, userID, newRoles string) (*model.ChannelMember, error)

UpdateChannelMemberRoles updates a user's roles for a channel.

Minimum server version: 5.2

func (*ChannelService) UpdateSidebarCategories added in v0.0.17

func (c *ChannelService) UpdateSidebarCategories(
	userID, teamID string, categories []*model.SidebarCategoryWithChannels) error

UpdateSidebarCategories updates the channel sidebar categories.

Minimum server version: 5.38

type Client

type Client struct {
	Bot           BotService
	Channel       ChannelService
	Cluster       ClusterService
	Configuration ConfigurationService
	SlashCommand  SlashCommandService
	OAuth         OAuthService
	Emoji         EmojiService
	File          FileService
	Frontend      FrontendService
	Group         GroupService
	KV            KVService
	Log           LogService
	Mail          MailService
	Plugin        PluginService
	Post          PostService
	Session       SessionService
	Store         *StoreService
	System        SystemService
	Team          TeamService
	User          UserService
	// contains filtered or unexported fields
}

Client is a streamlined wrapper over the mattermost plugin API.

func NewClient

func NewClient(api plugin.API, driver plugin.Driver) *Client

NewClient creates a new instance of Client.

This client must only be created once per plugin to prevent reacquiring of resources.

type ClusterService added in v0.1.2

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

ClusterService exposes methods to interact with cluster nodes.

func (*ClusterService) PublishPluginEvent added in v0.1.2

ClusterService broadcasts a plugin event to all other running instances of the calling plugin that are present in the cluster.

This method is used to allow plugin communication in a High-Availability cluster. The receiving side should implement the OnPluginClusterEvent hook to receive events sent through this method.

Minimum server version: 5.36

type ConfigurationService

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

ConfigurationService exposes methods to manipulate the server and plugin configuration.

func (*ConfigurationService) CheckRequiredServerConfiguration added in v0.0.18

func (c *ConfigurationService) CheckRequiredServerConfiguration(req *model.Config) (bool, error)

CheckRequiredServerConfiguration checks if the server is configured according to plugin requirements.

Minimum server version: 5.2

func (*ConfigurationService) GetConfig

func (c *ConfigurationService) GetConfig() *model.Config

GetConfig fetches the currently persisted config.

Minimum server version: 5.2

func (*ConfigurationService) GetPluginConfig

func (c *ConfigurationService) GetPluginConfig() map[string]interface{}

GetPluginConfig fetches the currently persisted config of plugin

Minimum server version: 5.6

func (*ConfigurationService) GetUnsanitizedConfig

func (c *ConfigurationService) GetUnsanitizedConfig() *model.Config

GetUnsanitizedConfig fetches the currently persisted config without removing secrets.

Minimum server version: 5.16

func (*ConfigurationService) LoadPluginConfiguration

func (c *ConfigurationService) LoadPluginConfiguration(dest interface{}) error

LoadPluginConfiguration loads the plugin's configuration. dest should be a pointer to a struct to which the configuration JSON can be unmarshalled.

Minimum server version: 5.2

func (*ConfigurationService) SaveConfig

func (c *ConfigurationService) SaveConfig(config *model.Config) error

SaveConfig sets the given config and persists the changes

Minimum server version: 5.2

func (*ConfigurationService) SavePluginConfig

func (c *ConfigurationService) SavePluginConfig(config map[string]interface{}) error

SavePluginConfig sets the given config for plugin and persists the changes

Minimum server version: 5.6

type EmojiService

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

EmojiService exposes methods to manipulate emojis.

func (*EmojiService) Get

func (e *EmojiService) Get(id string) (*model.Emoji, error)

Get gets a custom emoji by id.

Minimum server version: 5.6

func (*EmojiService) GetByName

func (e *EmojiService) GetByName(name string) (*model.Emoji, error)

GetByName gets a custom emoji by its name.

Minimum server version: 5.6

func (*EmojiService) GetImage

func (e *EmojiService) GetImage(id string) (io.Reader, string, error)

GetImage gets a custom emoji's content and format by id.

Minimum server version: 5.6

func (*EmojiService) List

func (e *EmojiService) List(sortBy string, page, count int) ([]*model.Emoji, error)

List retrieves a list of custom emojis. sortBy parameter can be: "name".

Minimum server version: 5.6

type EnsureBotOption added in v0.0.10

type EnsureBotOption func(*ensureBotOptions)

func ProfileImagePath added in v0.0.10

func ProfileImagePath(path string) EnsureBotOption

type FileService

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

FileService exposes methods to manipulate files, most often as post attachments.

func (*FileService) CopyInfos

func (f *FileService) CopyInfos(ids []string, userID string) ([]string, error)

CopyInfos duplicates the FileInfo objects referenced by the given file ids, recording the given user id as the new creator and returning the new set of file ids.

The duplicate FileInfo objects are not initially linked to a post, but may now be passed on creation of a post. Use this API to duplicate a post and its file attachments without actually duplicating the uploaded files.

Minimum server version: 5.2

func (*FileService) Get

func (f *FileService) Get(id string) (io.Reader, error)

Get gets content of a file by id.

Minimum server version: 5.8

func (*FileService) GetByPath

func (f *FileService) GetByPath(path string) (io.Reader, error)

GetByPath reads a file by its path on the dist.

Minimum server version: 5.3

func (*FileService) GetInfo

func (f *FileService) GetInfo(id string) (*model.FileInfo, error)

GetInfo gets a file's info by id.

Minimum server version: 5.3

func (f *FileService) GetLink(id string) (string, error)

GetLink gets the public link of a file by id.

Minimum server version: 5.6

func (*FileService) Upload

func (f *FileService) Upload(content io.Reader, fileName, channelID string) (*model.FileInfo, error)

Upload uploads a file to a channel to be later attached to a post.

Minimum server version: 5.6

type FrontendService

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

FrontendService exposes methods to interact with the frontend.

func (*FrontendService) OpenInteractiveDialog

func (f *FrontendService) OpenInteractiveDialog(dialog model.OpenDialogRequest) error

OpenInteractiveDialog will open an interactive dialog on a user's client that generated the trigger ID. Used with interactive message buttons, menus and slash commands.

Minimum server version: 5.6

func (*FrontendService) PublishWebSocketEvent

func (f *FrontendService) PublishWebSocketEvent(event string, payload map[string]interface{}, broadcast *model.WebsocketBroadcast)

PublishWebSocketEvent sends an event to WebSocket connections. event is the type and will be prepended with "custom_<pluginid>_". payload is the data sent with the event. Interface values must be primitive Go types or mattermost-server/model types. broadcast determines to which users to send the event.

Minimum server version: 5.2

type GroupService

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

GroupService exposes methods to manipulate groups.

func (*GroupService) Get

func (g *GroupService) Get(groupID string) (*model.Group, error)

Get gets a group by ID.

Minimum server version: 5.18

func (*GroupService) GetByName

func (g *GroupService) GetByName(name string) (*model.Group, error)

GetByName gets a group by name.

Minimum server version: 5.18

func (*GroupService) GetBySource added in v0.0.15

func (g *GroupService) GetBySource(groupSource model.GroupSource) ([]*model.Group, error)

GetBySource gets a list of all groups for the given source.

@tag Group Minimum server version: 5.35

func (*GroupService) GetMemberUsers added in v0.0.15

func (g *GroupService) GetMemberUsers(groupID string, page, perPage int) ([]*model.User, error)

GetMemberUsers gets a page of users from the given group.

Minimum server version: 5.35

func (*GroupService) ListForUser

func (g *GroupService) ListForUser(userID string) ([]*model.Group, error)

ListForUser gets the groups a user is in.

Minimum server version: 5.18

type KVService

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

KVService exposes methods to read and write key-value pairs for the active plugin.

This service cannot be used to read or write key-value pairs for other plugins.

func (*KVService) CompareAndDelete deprecated

func (k *KVService) CompareAndDelete(key string, oldValue interface{}) (bool, error)

CompareAndDelete deletes a key-value pair if the current value matches the given old value.

Returns (false, err) if DB error occurred Returns (false, nil) if current value != oldValue or key does not exist when deleting Returns (true, nil) if current value == oldValue and the key was deleted

Deprecated: CompareAndDelete exists to streamline adoption of this package for existing plugins. Use Set with the appropriate options instead.

Minimum server version: 5.18

func (*KVService) CompareAndSet deprecated

func (k *KVService) CompareAndSet(key string, oldValue, value interface{}) (bool, error)

CompareAndSet writes a key-value pair if the current value matches the given old value.

Returns (false, err) if DB error occurred Returns (false, nil) if the value was not set Returns (true, nil) if the value was set

Deprecated: CompareAndSet exists to streamline adoption of this package for existing plugins. Use Set with the appropriate options instead.

Minimum server version: 5.18

func (*KVService) Delete

func (k *KVService) Delete(key string) error

Delete deletes the given key-value pair.

An error is returned only if the value failed to be deleted. A non-existent key will return no error.

Minimum server version: 5.18

func (*KVService) DeleteAll

func (k *KVService) DeleteAll() error

DeleteAll removes all key-value pairs.

Minimum server version: 5.6

func (*KVService) Get

func (k *KVService) Get(key string, o interface{}) error

Get gets the value for the given key into the given interface.

An error is returned only if the value cannot be fetched. A non-existent key will return no error, with nothing written to the given interface.

Minimum server version: 5.2

func (*KVService) ListKeys

func (k *KVService) ListKeys(page, count int, options ...ListKeysOption) ([]string, error)

ListKeys lists all keys that match the given options. If no options are provided then all keys are returned.

Minimum server version: 5.6

func (*KVService) Set

func (k *KVService) Set(key string, value interface{}, options ...KVSetOption) (bool, error)

Set stores a key-value pair, unique per plugin. Keys prefixed with `mmi_` are reserved for use by this package and will fail to be set.

Returns (false, err) if DB error occurred Returns (false, nil) if the value was not set Returns (true, nil) if the value was set

Minimum server version: 5.18

func (*KVService) SetAtomicWithRetries added in v0.0.11

func (k *KVService) SetAtomicWithRetries(key string, valueFunc func(oldValue []byte) (newValue interface{}, err error)) error

SetAtomicWithRetries will set a key-value pair atomically using compare and set semantics: it will read key's value (to get oldValue), perform valueFunc (to get newValue), and compare and set (comparing oldValue and setting newValue).

Parameters:

`key`              is the key to get and set.
`valueFunc`        is a user-provided function that will take the old value as a []byte and
                   return the new value or an error. If valueFunc needs to operate on
                   oldValue, it will need to use the oldValue as a []byte, or convert
                   oldValue into the expected type (e.g., by parsing it, or marshaling it
                   into the expected struct). It should then return the newValue as the type
                   expected to be stored.

Returns:

Returns err if the key could not be retrieved (DB error), valueFunc returned an error,
if the key could not be set (DB error), or if the key could not be set (after retries).
Returns nil if the value was set.

Minimum server version: 5.18

func (*KVService) SetWithExpiry deprecated

func (k *KVService) SetWithExpiry(key string, value interface{}, ttl time.Duration) error

SetWithExpiry sets a key-value pair with the given expiration duration relative to now.

Deprecated: SetWithExpiry exists to streamline adoption of this package for existing plugins. Use Set with the appropriate options instead.

Minimum server version: 5.18

type KVSetOption

type KVSetOption func(*KVSetOptions)

KVSetOption is an option passed to Set() operation.

func SetAtomic

func SetAtomic(oldValue interface{}) KVSetOption

SetAtomic guarantees the write will occur only when the current value of matches the given old value. A client is expected to read the old value first, then pass it back to ensure the value has not since been modified.

func SetExpiry

func SetExpiry(ttl time.Duration) KVSetOption

SetExpiry configures a key value to expire after the given duration relative to now.

type KVSetOptions

type KVSetOptions struct {
	model.PluginKVSetOptions
	// contains filtered or unexported fields
}

TODO: Should this be un exported?

type ListKeysOption

type ListKeysOption func(*listKeysOptions)

ListKeysOption used to configure a ListKeys() operation.

func WithChecker added in v0.0.18

func WithChecker(f func(key string) (keep bool, err error)) ListKeysOption

WithChecker allows for a custom filter function to determine which keys to return. Returning true will keep the key and false will filter it out. Returning an error will halt KVListWithOptions immediately and pass the error up (with no other results).

func WithPrefix added in v0.0.18

func WithPrefix(prefix string) ListKeysOption

WithPrefix only return keys that start with the given string.

type ListTeamsOptions

type ListTeamsOptions struct {
	UserID string
}

ListTeamsOptions holds options about filter out team listing.

type LogService

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

LogService exposes methods to log to the Mattermost server log.

Note that standard error is automatically sent to the Mattermost server log, and standard output is redirected to standard error. This service enables optional structured logging.

func (*LogService) Debug

func (l *LogService) Debug(message string, keyValuePairs ...interface{})

Debug logs an error message, optionally structured with alternating key, value parameters.

func (*LogService) Error

func (l *LogService) Error(message string, keyValuePairs ...interface{})

Error logs an error message, optionally structured with alternating key, value parameters.

func (*LogService) Info

func (l *LogService) Info(message string, keyValuePairs ...interface{})

Info logs an error message, optionally structured with alternating key, value parameters.

func (*LogService) Warn

func (l *LogService) Warn(message string, keyValuePairs ...interface{})

Warn logs an error message, optionally structured with alternating key, value parameters.

type LogrusHook

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

LogrusHook is a logrus.Hook for emitting plugin logs through the RPC API for inclusion in the server logs.

To configure the default Logrus logger for use with plugin logging, simply invoke:

pluginapi.ConfigureLogrus(logrus.StandardLogger(), pluginAPIClient)

Alternatively, construct your own logger to pass to pluginapi.ConfigureLogrus.

func NewLogrusHook

func NewLogrusHook(log LogService) *LogrusHook

NewLogrusHook creates a new instance of LogrusHook.

func (*LogrusHook) Fire

func (lh *LogrusHook) Fire(entry *logrus.Entry) error

Fire proxies logrus entries through the plugin API at the appropriate level.

func (*LogrusHook) Levels

func (lh *LogrusHook) Levels() []logrus.Level

Levels allows LogrusHook to process any log level.

type MailService

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

MailService exposes methods to send email.

func (*MailService) Send

func (m *MailService) Send(to, subject, htmlBody string) error

Send sends an email to a specific address.

Minimum server version: 5.7

type OAuthService added in v0.0.18

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

UserService exposes methods to manipulate OAuth Apps.

func (*OAuthService) Create added in v0.0.18

func (o *OAuthService) Create(app *model.OAuthApp) error

Create creates a new OAuth App.

Minimum server version: 5.38

func (*OAuthService) Delete added in v0.0.18

func (o *OAuthService) Delete(appID string) error

Delete deletes an existing OAuth App by id.

Minimum server version: 5.38

func (*OAuthService) Get added in v0.0.18

func (o *OAuthService) Get(appID string) (*model.OAuthApp, error)

Get gets an existing OAuth App by id.

Minimum server version: 5.38

func (*OAuthService) Update added in v0.0.18

func (o *OAuthService) Update(app *model.OAuthApp) error

Update updates an existing OAuth App.

Minimum server version: 5.38

type PluginService

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

PluginService exposes methods to manipulate the set of plugins as well as communicate with other plugin instances.

func (*PluginService) Disable

func (p *PluginService) Disable(id string) error

Disable will disable an enabled plugin.

Minimum server version: 5.6

func (*PluginService) Enable

func (p *PluginService) Enable(id string) error

Enable will enable an plugin installed.

Minimum server version: 5.6

func (*PluginService) GetPluginStatus

func (p *PluginService) GetPluginStatus(id string) (*model.PluginStatus, error)

GetPluginStatus will return the status of a plugin.

Minimum server version: 5.6

func (*PluginService) HTTP

func (p *PluginService) HTTP(request *http.Request) *http.Response

HTTP allows inter-plugin requests to plugin APIs.

Minimum server version: 5.18

func (*PluginService) Install

func (p *PluginService) Install(file io.Reader, replace bool) (*model.Manifest, error)

Install will upload another plugin with tar.gz file. Previous version will be replaced on replace true.

Minimum server version: 5.18

func (*PluginService) InstallPluginFromURL added in v0.0.18

func (p *PluginService) InstallPluginFromURL(downloadURL string, replace bool) (*model.Manifest, error)

InstallPluginFromURL installs the plugin from the provided url.

Minimum server version: 5.18

func (*PluginService) List

func (p *PluginService) List() ([]*model.Manifest, error)

List will return a list of plugin manifests for currently active plugins.

Minimum server version: 5.6

func (*PluginService) Remove

func (p *PluginService) Remove(id string) error

Remove will disable and delete a plugin.

Minimum server version: 5.6

type PostService

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

PostService exposes methods to manipulate posts.

func (*PostService) AddReaction

func (p *PostService) AddReaction(reaction *model.Reaction) error

AddReaction add a reaction to a post.

Minimum server version: 5.3

func (*PostService) CreatePost

func (p *PostService) CreatePost(post *model.Post) error

CreatePost creates a post.

Minimum server version: 5.2

func (*PostService) DM added in v0.0.11

func (p *PostService) DM(senderUserID, receiverUserID string, post *model.Post) error

DM sends a post as a direct message

Minimum server version: 5.2

func (*PostService) DeleteEphemeralPost

func (p *PostService) DeleteEphemeralPost(userID, postID string)

DeleteEphemeralPost deletes an ephemeral message previously sent to the user. EXPERIMENTAL: This API is experimental and can be changed without advance notice.

Minimum server version: 5.2

func (*PostService) DeletePost

func (p *PostService) DeletePost(postID string) error

DeletePost deletes a post.

Minimum server version: 5.2

func (*PostService) GetPost

func (p *PostService) GetPost(postID string) (*model.Post, error)

GetPost gets a post.

Minimum server version: 5.2

func (*PostService) GetPostThread

func (p *PostService) GetPostThread(postID string) (*model.PostList, error)

GetPostThread gets a post with all the other posts in the same thread.

Minimum server version: 5.6

func (*PostService) GetPostsAfter

func (p *PostService) GetPostsAfter(channelID, postID string, page, perPage int) (*model.PostList, error)

GetPostsAfter gets a page of posts that were posted after the post provided.

Minimum server version: 5.6

func (*PostService) GetPostsBefore

func (p *PostService) GetPostsBefore(channelID, postID string, page, perPage int) (*model.PostList, error)

GetPostsBefore gets a page of posts that were posted before the post provided.

Minimum server version: 5.6

func (*PostService) GetPostsForChannel

func (p *PostService) GetPostsForChannel(channelID string, page, perPage int) (*model.PostList, error)

GetPostsForChannel gets a list of posts for a channel.

Minimum server version: 5.6

func (*PostService) GetPostsSince

func (p *PostService) GetPostsSince(channelID string, time int64) (*model.PostList, error)

GetPostsSince gets posts created after a specified time as Unix time in milliseconds.

Minimum server version: 5.6

func (*PostService) GetReactions

func (p *PostService) GetReactions(postID string) ([]*model.Reaction, error)

GetReactions get the reactions of a post.

Minimum server version: 5.3

func (*PostService) RemoveReaction

func (p *PostService) RemoveReaction(reaction *model.Reaction) error

RemoveReaction remove a reaction from a post.

Minimum server version: 5.3

func (*PostService) SearchPostsInTeam

func (p *PostService) SearchPostsInTeam(teamID string, paramsList []*model.SearchParams) ([]*model.Post, error)

SearchPostsInTeam returns a list of posts in a specific team that match the given params.

Minimum server version: 5.10

func (*PostService) SendEphemeralPost

func (p *PostService) SendEphemeralPost(userID string, post *model.Post)

SendEphemeralPost creates an ephemeral post.

Minimum server version: 5.2

func (*PostService) ShouldProcessMessage added in v0.0.18

func (p *PostService) ShouldProcessMessage(post *model.Post, options ...ShouldProcessMessageOption) (bool, error)

ShouldProcessMessage returns if the message should be processed by a message hook.

Use this method to avoid processing unnecessary messages in a MessageHasBeenPosted or MessageWillBePosted hook, and indeed in some cases avoid an infinite loop between two automated bots or plugins.

The behavior is customizable using the given options, since plugin needs may vary. By default, system messages and messages from bots will be skipped.

Minimum server version: 5.2

func (*PostService) UpdateEphemeralPost

func (p *PostService) UpdateEphemeralPost(userID string, post *model.Post)

UpdateEphemeralPost updates an ephemeral message previously sent to the user. EXPERIMENTAL: This API is experimental and can be changed without advance notice.

Minimum server version: 5.2

func (*PostService) UpdatePost

func (p *PostService) UpdatePost(post *model.Post) error

UpdatePost updates a post.

Minimum server version: 5.2

type SessionService

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

SessionService exposes methods to manipulate groups.

func (*SessionService) Create added in v0.0.22

func (s *SessionService) Create(session *model.Session) (*model.Session, error)

Create creates a new user session.

Minimum server version: 6.2

func (*SessionService) ExtendExpiry added in v0.0.22

func (s *SessionService) ExtendExpiry(sessionID string, newExpiry int64) error

ExtendSessionExpiry extends the duration of an existing session.

Minimum server version: 6.2

func (*SessionService) Get

func (s *SessionService) Get(id string) (*model.Session, error)

Get returns the session object for the Session ID

Minimum server version: 5.2

func (*SessionService) Revoke added in v0.0.22

func (s *SessionService) Revoke(sessionID string) error

RevokeSession revokes an existing user session.

Minimum server version: 6.2

type ShouldProcessMessageOption added in v0.0.18

type ShouldProcessMessageOption func(*shouldProcessMessageOptions)

func AllowBots added in v0.0.18

func AllowBots() ShouldProcessMessageOption

AllowBots configures a call to ShouldProcessMessage to return true for bot posts.

As it is typically desirable only to consume messages from human users of the system, ShouldProcessMessage ignores bot messages by default. When allowing bots, take care to avoid a loop where two plugins respond to each others posts repeatedly.

func AllowSystemMessages added in v0.0.18

func AllowSystemMessages() ShouldProcessMessageOption

AllowSystemMessages configures a call to ShouldProcessMessage to return true for system messages.

As it is typically desirable only to consume messages from users of the system, ShouldProcessMessage ignores system messages by default.

func AllowWebhook added in v0.0.18

func AllowWebhook() ShouldProcessMessageOption

AllowWebhook configures a call to ShouldProcessMessage to return true for posts from webhook.

As it is typically desirable only to consume messages from human users of the system, ShouldProcessMessage ignores webhook messages by default.

func BotID added in v0.0.18

If provided, BotID configures ShouldProcessMessage to skip its retrieval from the store.

By default, posts from all non-bot users are allowed.

func FilterChannelIDs added in v0.0.18

func FilterChannelIDs(filterChannelIDs []string) ShouldProcessMessageOption

FilterChannelIDs configures a call to ShouldProcessMessage to return true only for the given channels.

By default, posts from all channels are allowed to be processed.

func FilterUserIDs added in v0.0.18

func FilterUserIDs(filterUserIDs []string) ShouldProcessMessageOption

FilterUserIDs configures a call to ShouldProcessMessage to return true only for the given users.

By default, posts from all non-bot users are allowed.

func OnlyBotDMs added in v0.0.18

func OnlyBotDMs() ShouldProcessMessageOption

OnlyBotDMs configures a call to ShouldProcessMessage to return true only for direct messages sent to the bot created by EnsureBot.

By default, posts from all channels are allowed.

type SlashCommandService

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

SlashCommandService exposes methods to manipulate slash commands.

func (*SlashCommandService) Create added in v0.0.12

func (c *SlashCommandService) Create(command *model.Command) (*model.Command, error)

Create creates a server-owned slash command that is not handled by the plugin itself, and which will persist past the life of the plugin. The command will have its CreatorId set to "" and its PluginId set to the id of the plugin that created it.

Minimum server version: 5.28

func (*SlashCommandService) Delete added in v0.0.12

func (c *SlashCommandService) Delete(commandID string) error

Delete deletes a slash command (identified by commandID).

Minimum server version: 5.28

func (*SlashCommandService) Execute added in v0.0.12

Execute executes a slash command.

Minimum server version: 5.26

func (*SlashCommandService) Get added in v0.0.12

func (c *SlashCommandService) Get(commandID string) (*model.Command, error)

Get returns the command definition based on a command id string.

Minimum server version: 5.28

func (*SlashCommandService) List added in v0.0.12

func (c *SlashCommandService) List(teamID string) ([]*model.Command, error)

List returns the list of all slash commands for teamID. E.g., custom commands (those created through the integrations menu, the REST api, or the plugin api CreateCommand), plugin commands (those created with plugin api RegisterCommand), and builtin commands (those added internally through RegisterCommandProvider).

Minimum server version: 5.28

func (*SlashCommandService) ListBuiltIn added in v0.0.12

func (c *SlashCommandService) ListBuiltIn() ([]*model.Command, error)

ListBuiltIn returns the list of slash commands that are builtin commands (those added internally through RegisterCommandProvider).

Minimum server version: 5.28

func (*SlashCommandService) ListCustom added in v0.0.12

func (c *SlashCommandService) ListCustom(teamID string) ([]*model.Command, error)

ListCustom returns the list of slash commands for teamID that where created through the integrations menu, the REST api, or the plugin api CreateCommand.

Minimum server version: 5.28

func (*SlashCommandService) ListPlugin added in v0.0.12

func (c *SlashCommandService) ListPlugin(teamID string) ([]*model.Command, error)

ListPlugin returns the list of slash commands for teamID that were created with the plugin api RegisterCommand.

Minimum server version: 5.28

func (*SlashCommandService) Register

func (c *SlashCommandService) Register(command *model.Command) error

Register registers a custom slash command. When the command is triggered, your plugin can fulfill it via the ExecuteCommand hook.

Minimum server version: 5.2

func (*SlashCommandService) Unregister

func (c *SlashCommandService) Unregister(teamID, trigger string) error

Unregister unregisters a command previously registered via Register.

Minimum server version: 5.2

func (*SlashCommandService) Update added in v0.0.12

func (c *SlashCommandService) Update(commandID string, updatedCmd *model.Command) (*model.Command, error)

Update updates a single command (identified by commandID) with the information provided in the updatedCmd model.Command struct. The following fields in the command cannot be updated: Id, Token, CreateAt, DeleteAt, and PluginId. If updatedCmd.TeamId is blank, it will be set to commandID's TeamId.

Minimum server version: 5.28

type StoreService added in v0.0.11

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

StoreService exposes the underlying database.

func (*StoreService) Close added in v0.0.11

func (s *StoreService) Close() error

Close closes any open resources. This method is idempotent.

func (*StoreService) DriverName added in v0.0.11

func (s *StoreService) DriverName() string

DriverName returns the driver name for the datasource.

func (*StoreService) GetMasterDB added in v0.0.11

func (s *StoreService) GetMasterDB() (*sql.DB, error)

GetMasterDB gets the master database handle.

Minimum server version: 5.16

func (*StoreService) GetReplicaDB added in v0.0.11

func (s *StoreService) GetReplicaDB() (*sql.DB, error)

GetReplicaDB gets the replica database handle. Returns masterDB if a replica is not configured.

Minimum server version: 5.16

type SystemService

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

SystemService exposes methods to query system properties.

func (*SystemService) GetBundlePath

func (s *SystemService) GetBundlePath() (string, error)

GetBundlePath returns the absolute path where the plugin's bundle was unpacked.

Minimum server version: 5.10

func (*SystemService) GetDiagnosticID

func (s *SystemService) GetDiagnosticID() string

GetDiagnosticID returns a unique identifier used by the server for diagnostic reports.

Minimum server version: 5.10

func (*SystemService) GetLicense

func (s *SystemService) GetLicense() *model.License

GetLicense returns the current license used by the Mattermost server. Returns nil if the the server does not have a license.

Minimum server version: 5.10

func (*SystemService) GetManifest added in v0.0.10

func (s *SystemService) GetManifest() (*model.Manifest, error)

GetManifest returns the manifest from the plugin bundle.

Minimum server version: 5.10

func (*SystemService) GetPluginAssetURL added in v0.0.18

func (s *SystemService) GetPluginAssetURL(pluginID, asset string) (string, error)

GetPluginAssetURL builds a URL to the given asset in the assets directory. Use this URL to link to assets from the webapp, or for third-party integrations with your plugin.

Minimum server version: 5.2

func (*SystemService) GetServerVersion

func (s *SystemService) GetServerVersion() string

GetServerVersion return the current Mattermost server version

Minimum server version: 5.4

func (*SystemService) GetSystemInstallDate

func (s *SystemService) GetSystemInstallDate() (time.Time, error)

GetSystemInstallDate returns the time that Mattermost was first installed and ran.

Minimum server version: 5.10

func (*SystemService) IsEnterpriseReady added in v0.0.22

func (s *SystemService) IsEnterpriseReady() bool

IsEnterpriseReady returns true if the Mattermost server is configured as Enterprise Ready.

Minimum server version: 6.1

func (*SystemService) RequestTrialLicense added in v0.0.16

func (s *SystemService) RequestTrialLicense(requesterID string, users int, termsAccepted, receiveEmailsAccepted bool) error

RequestTrialLicense requests a trial license and installs it in the server. If the server version is lower than 5.36.0, an error is returned.

Minimum server version: 5.36

type TeamListOption

type TeamListOption func(*ListTeamsOptions)

TeamListOption is used to filter team listing.

func FilterTeamsByUser

func FilterTeamsByUser(userID string) TeamListOption

FilterTeamsByUser option is used to filter teams by user.

type TeamService

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

TeamService exposes methods to manipulate teams and their members.

func (*TeamService) Create

func (t *TeamService) Create(team *model.Team) error

Create creates a team.

Minimum server version: 5.2

func (*TeamService) CreateMember

func (t *TeamService) CreateMember(teamID, userID string) (*model.TeamMember, error)

CreateMember creates a team membership.

Minimum server version: 5.2

func (*TeamService) CreateMembers

func (t *TeamService) CreateMembers(teamID string, userIDs []string, requestorID string) ([]*model.TeamMember, error)

CreateMembers creates a team membership for all provided user ids.

Minimum server version: 5.2

func (*TeamService) Delete

func (t *TeamService) Delete(teamID string) error

Delete deletes a team.

Minimum server version: 5.2

func (*TeamService) DeleteIcon

func (t *TeamService) DeleteIcon(teamID string) error

DeleteIcon removes the team icon.

Minimum server version: 5.6

func (*TeamService) DeleteMember

func (t *TeamService) DeleteMember(teamID, userID, requestorID string) error

DeleteMember deletes a team membership.

Minimum server version: 5.2

func (*TeamService) Get

func (t *TeamService) Get(teamID string) (*model.Team, error)

Get gets a team.

Minimum server version: 5.2

func (*TeamService) GetByName

func (t *TeamService) GetByName(name string) (*model.Team, error)

GetByName gets a team by its name.

Minimum server version: 5.2

func (*TeamService) GetIcon

func (t *TeamService) GetIcon(teamID string) (io.Reader, error)

GetIcon gets the team icon.

Minimum server version: 5.6

func (*TeamService) GetMember

func (t *TeamService) GetMember(teamID, userID string) (*model.TeamMember, error)

GetMember returns a specific membership.

Minimum server version: 5.2

func (*TeamService) GetStats

func (t *TeamService) GetStats(teamID string) (*model.TeamStats, error)

GetStats gets a team's statistics

Minimum server version: 5.8

func (*TeamService) List

func (t *TeamService) List(options ...TeamListOption) ([]*model.Team, error)

List gets a list of teams by options.

Minimum server version: 5.2 Minimum server version when LimitTeamsToUser() option is used: 5.6

func (*TeamService) ListMembers

func (t *TeamService) ListMembers(teamID string, page, perPage int) ([]*model.TeamMember, error)

ListMembers returns the memberships of a specific team.

Minimum server version: 5.2

func (*TeamService) ListMembersForUser

func (t *TeamService) ListMembersForUser(userID string, page, perPage int) ([]*model.TeamMember, error)

ListMembersForUser returns all team memberships for a user.

Minimum server version: 5.10

func (*TeamService) ListUnreadForUser

func (t *TeamService) ListUnreadForUser(userID string) ([]*model.TeamUnread, error)

ListUnreadForUser gets the unread message and mention counts for each team to which the given user belongs.

Minimum server version: 5.6

func (*TeamService) ListUsers

func (t *TeamService) ListUsers(teamID string, page, count int) ([]*model.User, error)

GetUsers lists users of the team.

Minimum server version: 5.6

func (*TeamService) Search

func (t *TeamService) Search(term string) ([]*model.Team, error)

Search search a team.

Minimum server version: 5.8

func (*TeamService) SetIcon

func (t *TeamService) SetIcon(teamID string, content io.Reader) error

SetIcon sets the team icon.

Minimum server version: 5.6

func (*TeamService) Update

func (t *TeamService) Update(team *model.Team) error

Update updates a team.

Minimum server version: 5.2

func (*TeamService) UpdateMemberRoles

func (t *TeamService) UpdateMemberRoles(teamID, userID, newRoles string) (*model.TeamMember, error)

UpdateMemberRoles updates the role for a team membership.

Minimum server version: 5.2

type UserService

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

UserService exposes methods to manipulate users.

func (*UserService) Create

func (u *UserService) Create(user *model.User) error

Create creates a user.

Minimum server version: 5.2

func (*UserService) CreateAccessToken added in v0.0.18

func (u *UserService) CreateAccessToken(userID, description string) (*model.UserAccessToken, error)

CreateAccessToken creates a new access token.

Minimum server version: 5.38

func (*UserService) Delete

func (u *UserService) Delete(userID string) error

Delete deletes a user.

Minimum server version: 5.2

func (*UserService) Get

func (u *UserService) Get(userID string) (*model.User, error)

Get gets a user.

Minimum server version: 5.2

func (*UserService) GetByEmail

func (u *UserService) GetByEmail(email string) (*model.User, error)

GetByEmail gets a user by their email address.

Minimum server version: 5.2

func (*UserService) GetByUsername

func (u *UserService) GetByUsername(username string) (*model.User, error)

GetByUsername gets a user by their username.

Minimum server version: 5.2

func (*UserService) GetLDAPAttributes

func (u *UserService) GetLDAPAttributes(userID string, attributes []string) (map[string]string, error)

GetLDAPAttributes will return LDAP attributes for a user. The attributes parameter should be a list of attributes to pull. Returns a map with attribute names as keys and the user's attributes as values. Requires an enterprise license, LDAP to be configured and for the user to use LDAP as an authentication method.

Minimum server version: 5.3

func (*UserService) GetProfileImage

func (u *UserService) GetProfileImage(userID string) (io.Reader, error)

GetProfileImage gets user's profile image.

Minimum server version: 5.6

func (*UserService) GetStatus

func (u *UserService) GetStatus(userID string) (*model.Status, error)

GetStatus will get a user's status.

Minimum server version: 5.2

func (*UserService) HasPermissionTo

func (u *UserService) HasPermissionTo(userID string, permission *model.Permission) bool

HasPermissionTo check if the user has the permission at system scope.

Minimum server version: 5.3

func (*UserService) HasPermissionToChannel

func (u *UserService) HasPermissionToChannel(userID, channelID string, permission *model.Permission) bool

HasPermissionToChannel check if the user has the permission at channel scope.

Minimum server version: 5.3

func (*UserService) HasPermissionToTeam

func (u *UserService) HasPermissionToTeam(userID, teamID string, permission *model.Permission) bool

HasPermissionToTeam check if the user has the permission at team scope.

Minimum server version: 5.3

func (*UserService) List

func (u *UserService) List(options *model.UserGetOptions) ([]*model.User, error)

List a list of users based on search options.

Minimum server version: 5.10

func (*UserService) ListByUsernames

func (u *UserService) ListByUsernames(usernames []string) ([]*model.User, error)

ListByUsernames gets users by their usernames.

Minimum server version: 5.6

func (*UserService) ListInChannel

func (u *UserService) ListInChannel(channelID, sortBy string, page, perPage int) ([]*model.User, error)

ListInChannel returns a page of users in a channel. Page counting starts at 0. The sortBy parameter can be: "username" or "status".

Minimum server version: 5.6

func (*UserService) ListInTeam

func (u *UserService) ListInTeam(teamID string, page, perPage int) ([]*model.User, error)

ListInTeam gets users in team.

Minimum server version: 5.6

func (*UserService) ListStatusesByIDs

func (u *UserService) ListStatusesByIDs(userIDs []string) ([]*model.Status, error)

ListStatusesByIDs will return a list of user statuses based on the provided slice of user IDs.

Minimum server version: 5.2

func (*UserService) RevokeAccessToken added in v0.0.18

func (u *UserService) RevokeAccessToken(tokenID string) error

RevokeAccessToken revokes an existing access token.

Minimum server version: 5.38

func (*UserService) RolesGrantPermission added in v0.0.22

func (u *UserService) RolesGrantPermission(roleNames []string, permissionID string) bool

RolesGrantPermission check if the specified roles grant the specified permission

Minimum server version: 6.3

func (*UserService) Search

func (u *UserService) Search(search *model.UserSearch) ([]*model.User, error)

Search returns a list of users based on some search criteria.

Minimum server version: 5.6

func (*UserService) SetProfileImage

func (u *UserService) SetProfileImage(userID string, content io.Reader) error

SetProfileImage sets a user's profile image.

Minimum server version: 5.6

func (*UserService) Update

func (u *UserService) Update(user *model.User) error

Update updates a user.

Minimum server version: 5.2

func (*UserService) UpdateActive

func (u *UserService) UpdateActive(userID string, active bool) error

UpdateActive deactivates or reactivates an user.

Minimum server version: 5.8

func (*UserService) UpdateStatus

func (u *UserService) UpdateStatus(userID, status string) (*model.Status, error)

UpdateStatus will set a user's status until the user, or another integration/plugin, sets it back to online. The status parameter can be: "online", "away", "dnd", or "offline".

Minimum server version: 5.2

Directories

Path Synopsis
package cluster exposes synchronization primitives to ensure correct behavior across multiple plugin instances in a Mattermost cluster.
package cluster exposes synchronization primitives to ensure correct behavior across multiple plugin instances in a Mattermost cluster.
experimental
bot
bot/mocks
Package mock_bot is a generated GoMock package.
Package mock_bot is a generated GoMock package.
bot/poster/mock_import
Package mock_import is a generated GoMock package.
Package mock_import is a generated GoMock package.
oauther/mock_oauther
Package mock_oauther is a generated GoMock package.
Package mock_oauther is a generated GoMock package.
oauther/mocks
Package mock_oauther is a generated GoMock package.
Package mock_oauther is a generated GoMock package.
panel/mocks
Package mock_panel is a generated GoMock package.
Package mock_panel is a generated GoMock package.
telemetry
Package telemetry allows you to add telemetry to your plugins.
Package telemetry allows you to add telemetry to your plugins.
package i18n provides methods to read translations files and localize strings.
package i18n provides methods to read translations files and localize strings.

Jump to

Keyboard shortcuts

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