Mattermost Logo
Edit on GitHub

Server Reference

This is the documentation for the Go github.com/mattermost/mattermost-server/plugin package. It can also be found on GoDoc

The plugin package is used by Mattermost server plugins written in go. It also enables the Mattermost server to manage and interact with the running plugin environment.

Note that this package exports a large number of types prefixed with Z_. These are public only to allow their use with Hashicorp's go-plugin (and net/rpc). Do not use these directly.

API 

The API can be used to retrieve data or perform actions on behalf of the plugin. Most methods have direct counterparts in the REST API and very similar behavior.

Plugins obtain access to the API by embedding MattermostPlugin and accessing the API member directly.

Hooks 

Hooks describes the methods a plugin may implement to automatically receive the corresponding event.

A plugin only need implement the hooks it cares about. The MattermostPlugin provides some default implementations for convenience but may be overridden.

Helpers 

Helpers provide a common patterns plugins use.

Plugins obtain access to the Helpers by embedding MattermostPlugin.

Examples


API

(API) LoadPluginConfiguration 

LoadPluginConfiguration(dest interface{}) error

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

@tag Plugin Minimum server version: 5.2

(API) RegisterCommand 

RegisterCommand(command *model.Command) error

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

@tag Command Minimum server version: 5.2

(API) UnregisterCommand 

UnregisterCommand(teamId, trigger string) error

UnregisterCommand unregisters a command previously registered via RegisterCommand.

@tag Command Minimum server version: 5.2

(API) GetSession 

GetSession(sessionId string) (*model.Session, *model.AppError)

GetSession returns the session object for the Session ID

Minimum server version: 5.2

(API) GetConfig 

GetConfig() *model.Config

GetConfig fetches the currently persisted config

@tag Configuration Minimum server version: 5.2

(API) GetUnsanitizedConfig 

GetUnsanitizedConfig() *model.Config

GetUnsanitizedConfig fetches the currently persisted config without removing secrets.

@tag Configuration Minimum server version: 5.16

(API) SaveConfig 

SaveConfig(config *model.Config) *model.AppError

SaveConfig sets the given config and persists the changes

@tag Configuration Minimum server version: 5.2

(API) GetPluginConfig 

GetPluginConfig() map[string]interface{}

GetPluginConfig fetches the currently persisted config of plugin

@tag Plugin Minimum server version: 5.6

(API) SavePluginConfig 

SavePluginConfig(config map[string]interface{}) *model.AppError

SavePluginConfig sets the given config for plugin and persists the changes

@tag Plugin Minimum server version: 5.6

(API) GetBundlePath 

GetBundlePath() (string, error)

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

@tag Plugin Minimum server version: 5.10

(API) GetLicense 

GetLicense() *model.License

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

@tag Server Minimum server version: 5.10

(API) GetServerVersion 

GetServerVersion() string

GetServerVersion return the current Mattermost server version

@tag Server Minimum server version: 5.4

(API) GetSystemInstallDate 

GetSystemInstallDate() (int64, *model.AppError)

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

@tag Server Minimum server version: 5.10

(API) GetDiagnosticId 

GetDiagnosticId() string

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

@tag Server Minimum server version: 5.10

(API) CreateUser 

CreateUser(user *model.User) (*model.User, *model.AppError)

CreateUser creates a user.

@tag User Minimum server version: 5.2

(API) DeleteUser 

DeleteUser(userId string) *model.AppError

DeleteUser deletes a user.

@tag User Minimum server version: 5.2

(API) GetUsers 

GetUsers(options *model.UserGetOptions) ([]*model.User, *model.AppError)

GetUsers a list of users based on search options.

@tag User Minimum server version: 5.10

(API) GetUser 

GetUser(userId string) (*model.User, *model.AppError)

GetUser gets a user.

@tag User Minimum server version: 5.2

(API) GetUserByEmail 

GetUserByEmail(email string) (*model.User, *model.AppError)

GetUserByEmail gets a user by their email address.

@tag User Minimum server version: 5.2

(API) GetUserByUsername 

GetUserByUsername(name string) (*model.User, *model.AppError)

GetUserByUsername gets a user by their username.

@tag User Minimum server version: 5.2

(API) GetUsersByUsernames 

GetUsersByUsernames(usernames []string) ([]*model.User, *model.AppError)

GetUsersByUsernames gets users by their usernames.

@tag User Minimum server version: 5.6

(API) GetUsersInTeam 

GetUsersInTeam(teamId string, page int, perPage int) ([]*model.User, *model.AppError)

GetUsersInTeam gets users in team.

@tag User @tag Team Minimum server version: 5.6

(API) GetTeamIcon 

GetTeamIcon(teamId string) ([]byte, *model.AppError)

GetTeamIcon gets the team icon.

@tag Team Minimum server version: 5.6

(API) SetTeamIcon 

SetTeamIcon(teamId string, data []byte) *model.AppError

SetTeamIcon sets the team icon.

@tag Team Minimum server version: 5.6

(API) RemoveTeamIcon 

RemoveTeamIcon(teamId string) *model.AppError

RemoveTeamIcon removes the team icon.

@tag Team Minimum server version: 5.6

(API) UpdateUser 

UpdateUser(user *model.User) (*model.User, *model.AppError)

UpdateUser updates a user.

@tag User Minimum server version: 5.2

(API) GetUserStatus 

GetUserStatus(userId string) (*model.Status, *model.AppError)

GetUserStatus will get a user's status.

@tag User Minimum server version: 5.2

(API) GetUserStatusesByIds 

GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.AppError)

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

@tag User Minimum server version: 5.2

(API) UpdateUserStatus 

UpdateUserStatus(userId, status string) (*model.Status, *model.AppError)

UpdateUserStatus 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".

@tag User Minimum server version: 5.2

(API) UpdateUserActive 

UpdateUserActive(userId string, active bool) *model.AppError

UpdateUserActive deactivates or reactivates an user.

@tag User Minimum server version: 5.8

(API) GetUsersInChannel 

GetUsersInChannel(channelId, sortBy string, page, perPage int) ([]*model.User, *model.AppError)

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

@tag User @tag Channel Minimum server version: 5.6

(API) GetLDAPUserAttributes 

GetLDAPUserAttributes(userId string, attributes []string) (map[string]string, *model.AppError)

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

@tag User Minimum server version: 5.3

(API) CreateTeam 

CreateTeam(team *model.Team) (*model.Team, *model.AppError)

CreateTeam creates a team.

@tag Team Minimum server version: 5.2

(API) DeleteTeam 

DeleteTeam(teamId string) *model.AppError

DeleteTeam deletes a team.

@tag Team Minimum server version: 5.2

(API) GetTeams 

GetTeams() ([]*model.Team, *model.AppError)

GetTeam gets all teams.

@tag Team Minimum server version: 5.2

(API) GetTeam 

GetTeam(teamId string) (*model.Team, *model.AppError)

GetTeam gets a team.

@tag Team Minimum server version: 5.2

(API) GetTeamByName 

GetTeamByName(name string) (*model.Team, *model.AppError)

GetTeamByName gets a team by its name.

@tag Team Minimum server version: 5.2

(API) GetTeamsUnreadForUser 

GetTeamsUnreadForUser(userId string) ([]*model.TeamUnread, *model.AppError)

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

@tag Team @tag User Minimum server version: 5.6

(API) UpdateTeam 

UpdateTeam(team *model.Team) (*model.Team, *model.AppError)

UpdateTeam updates a team.

@tag Team Minimum server version: 5.2

(API) SearchTeams 

SearchTeams(term string) ([]*model.Team, *model.AppError)

SearchTeams search a team.

@tag Team Minimum server version: 5.8

(API) GetTeamsForUser 

GetTeamsForUser(userId string) ([]*model.Team, *model.AppError)

GetTeamsForUser returns list of teams of given user ID.

@tag Team @tag User Minimum server version: 5.6

(API) CreateTeamMember 

CreateTeamMember(teamId, userId string) (*model.TeamMember, *model.AppError)

CreateTeamMember creates a team membership.

@tag Team @tag User Minimum server version: 5.2

(API) CreateTeamMembers 

CreateTeamMembers(teamId string, userIds []string, requestorId string) ([]*model.TeamMember, *model.AppError)

CreateTeamMembers creates a team membership for all provided user ids.

@tag Team @tag User Minimum server version: 5.2

(API) DeleteTeamMember 

DeleteTeamMember(teamId, userId, requestorId string) *model.AppError

DeleteTeamMember deletes a team membership.

@tag Team @tag User Minimum server version: 5.2

(API) GetTeamMembers 

GetTeamMembers(teamId string, page, perPage int) ([]*model.TeamMember, *model.AppError)

GetTeamMembers returns the memberships of a specific team.

@tag Team @tag User Minimum server version: 5.2

(API) GetTeamMember 

GetTeamMember(teamId, userId string) (*model.TeamMember, *model.AppError)

GetTeamMember returns a specific membership.

@tag Team @tag User Minimum server version: 5.2

(API) GetTeamMembersForUser 

GetTeamMembersForUser(userId string, page int, perPage int) ([]*model.TeamMember, *model.AppError)

GetTeamMembersForUser returns all team memberships for a user.

@tag Team @tag User Minimum server version: 5.10

(API) UpdateTeamMemberRoles 

UpdateTeamMemberRoles(teamId, userId, newRoles string) (*model.TeamMember, *model.AppError)

UpdateTeamMemberRoles updates the role for a team membership.

@tag Team @tag User Minimum server version: 5.2

(API) CreateChannel 

CreateChannel(channel *model.Channel) (*model.Channel, *model.AppError)

CreateChannel creates a channel.

@tag Channel Minimum server version: 5.2

(API) DeleteChannel 

DeleteChannel(channelId string) *model.AppError

DeleteChannel deletes a channel.

@tag Channel Minimum server version: 5.2

(API) GetPublicChannelsForTeam 

GetPublicChannelsForTeam(teamId string, page, perPage int) ([]*model.Channel, *model.AppError)

GetPublicChannelsForTeam gets a list of all channels.

@tag Channel @tag Team Minimum server version: 5.2

(API) GetChannel 

GetChannel(channelId string) (*model.Channel, *model.AppError)

GetChannel gets a channel.

@tag Channel Minimum server version: 5.2

(API) GetChannelByName 

GetChannelByName(teamId, name string, includeDeleted bool) (*model.Channel, *model.AppError)

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

@tag Channel Minimum server version: 5.2

(API) GetChannelByNameForTeamName 

GetChannelByNameForTeamName(teamName, channelName string, includeDeleted bool) (*model.Channel, *model.AppError)

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

@tag Channel @tag Team Minimum server version: 5.2

(API) GetChannelsForTeamForUser 

GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) ([]*model.Channel, *model.AppError)

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

@tag Channel @tag Team @tag User Minimum server version: 5.6

(API) GetChannelStats 

GetChannelStats(channelId string) (*model.ChannelStats, *model.AppError)

GetChannelStats gets statistics for a channel.

@tag Channel Minimum server version: 5.6

(API) GetDirectChannel 

GetDirectChannel(userId1, userId2 string) (*model.Channel, *model.AppError)

GetDirectChannel gets a direct message channel. If the channel does not exist it will create it.

@tag Channel @tag User Minimum server version: 5.2

(API) GetGroupChannel 

GetGroupChannel(userIds []string) (*model.Channel, *model.AppError)

GetGroupChannel gets a group message channel. If the channel does not exist it will create it.

@tag Channel @tag User Minimum server version: 5.2

(API) UpdateChannel 

UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError)

UpdateChannel updates a channel.

@tag Channel Minimum server version: 5.2

(API) SearchChannels 

SearchChannels(teamId string, term string) ([]*model.Channel, *model.AppError)

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

@tag Channel Minimum server version: 5.6

(API) SearchUsers 

SearchUsers(search *model.UserSearch) ([]*model.User, *model.AppError)

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

@tag User Minimum server version: 5.6

(API) SearchPostsInTeam 

SearchPostsInTeam(teamId string, paramsList []*model.SearchParams) ([]*model.Post, *model.AppError)

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

@tag Post @tag Team Minimum server version: 5.10

(API) AddChannelMember 

AddChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError)

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

@tag Channel @tag User Minimum server version: 5.2

(API) AddUserToChannel 

AddUserToChannel(channelId, userId, asUserId string) (*model.ChannelMember, *model.AppError)

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

@tag User @tag Channel Minimum server version: 5.18

(API) GetChannelMember 

GetChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError)

GetChannelMember gets a channel membership for a user.

@tag Channel @tag User Minimum server version: 5.2

(API) GetChannelMembers 

GetChannelMembers(channelId string, page, perPage int) (*model.ChannelMembers, *model.AppError)

GetChannelMembers gets a channel membership for all users.

@tag Channel @tag User Minimum server version: 5.6

(API) GetChannelMembersByIds 

GetChannelMembersByIds(channelId string, userIds []string) (*model.ChannelMembers, *model.AppError)

GetChannelMembersByIds gets a channel membership for a particular User

@tag Channel @tag User Minimum server version: 5.6

(API) GetChannelMembersForUser 

GetChannelMembersForUser(teamId, userId string, page, perPage int) ([]*model.ChannelMember, *model.AppError)

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

@tag Channel @tag User Minimum server version: 5.10

(API) UpdateChannelMemberRoles 

UpdateChannelMemberRoles(channelId, userId, newRoles string) (*model.ChannelMember, *model.AppError)

UpdateChannelMemberRoles updates a user's roles for a channel.

@tag Channel @tag User Minimum server version: 5.2

(API) UpdateChannelMemberNotifications 

UpdateChannelMemberNotifications(channelId, userId string, notifications map[string]string) (*model.ChannelMember, *model.AppError)

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

@tag Channel @tag User Minimum server version: 5.2

(API) GetGroup 

GetGroup(groupId string) (*model.Group, *model.AppError)

GetGroup gets a group by ID.

@tag Group Minimum server version: 5.18

(API) GetGroupByName 

GetGroupByName(name string) (*model.Group, *model.AppError)

GetGroupByName gets a group by name.

@tag Group Minimum server version: 5.18

(API) GetGroupsForUser 

GetGroupsForUser(userId string) ([]*model.Group, *model.AppError)

GetGroupsForUser gets the groups a user is in.

@tag Group @tag User Minimum server version: 5.18

(API) DeleteChannelMember 

DeleteChannelMember(channelId, userId string) *model.AppError

DeleteChannelMember deletes a channel membership for a user.

@tag Channel @tag User Minimum server version: 5.2

(API) CreatePost 

CreatePost(post *model.Post) (*model.Post, *model.AppError)

CreatePost creates a post.

@tag Post Minimum server version: 5.2

(API) AddReaction 

AddReaction(reaction *model.Reaction) (*model.Reaction, *model.AppError)

AddReaction add a reaction to a post.

@tag Post Minimum server version: 5.3

(API) RemoveReaction 

RemoveReaction(reaction *model.Reaction) *model.AppError

RemoveReaction remove a reaction from a post.

@tag Post Minimum server version: 5.3

(API) GetReactions 

GetReactions(postId string) ([]*model.Reaction, *model.AppError)

GetReaction get the reactions of a post.

@tag Post Minimum server version: 5.3

(API) SendEphemeralPost 

SendEphemeralPost(userId string, post *model.Post) *model.Post

SendEphemeralPost creates an ephemeral post.

@tag Post Minimum server version: 5.2

(API) UpdateEphemeralPost 

UpdateEphemeralPost(userId string, post *model.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.

@tag Post Minimum server version: 5.2

(API) DeleteEphemeralPost 

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.

@tag Post Minimum server version: 5.2

(API) DeletePost 

DeletePost(postId string) *model.AppError

DeletePost deletes a post.

@tag Post Minimum server version: 5.2

(API) GetPostThread 

GetPostThread(postId string) (*model.PostList, *model.AppError)

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

@tag Post Minimum server version: 5.6

(API) GetPost 

GetPost(postId string) (*model.Post, *model.AppError)

GetPost gets a post.

@tag Post Minimum server version: 5.2

(API) GetPostsSince 

GetPostsSince(channelId string, time int64) (*model.PostList, *model.AppError)

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

@tag Post @tag Channel Minimum server version: 5.6

(API) GetPostsAfter 

GetPostsAfter(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError)

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

@tag Post @tag Channel Minimum server version: 5.6

(API) GetPostsBefore 

GetPostsBefore(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError)

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

@tag Post @tag Channel Minimum server version: 5.6

(API) GetPostsForChannel 

GetPostsForChannel(channelId string, page, perPage int) (*model.PostList, *model.AppError)

GetPostsForChannel gets a list of posts for a channel.

@tag Post @tag Channel Minimum server version: 5.6

(API) GetTeamStats 

GetTeamStats(teamId string) (*model.TeamStats, *model.AppError)

GetTeamStats gets a team's statistics

@tag Team Minimum server version: 5.8

(API) UpdatePost 

UpdatePost(post *model.Post) (*model.Post, *model.AppError)

UpdatePost updates a post.

@tag Post Minimum server version: 5.2

(API) GetProfileImage 

GetProfileImage(userId string) ([]byte, *model.AppError)

GetProfileImage gets user's profile image.

@tag User Minimum server version: 5.6

(API) SetProfileImage 

SetProfileImage(userId string, data []byte) *model.AppError

SetProfileImage sets a user's profile image.

@tag User Minimum server version: 5.6

(API) GetEmojiList 

GetEmojiList(sortBy string, page, perPage int) ([]*model.Emoji, *model.AppError)

GetEmojiList returns a page of custom emoji on the system.

The sortBy parameter can be: "name".

@tag Emoji Minimum server version: 5.6

(API) GetEmojiByName 

GetEmojiByName(name string) (*model.Emoji, *model.AppError)

GetEmojiByName gets an emoji by it's name.

@tag Emoji Minimum server version: 5.6

(API) GetEmoji 

GetEmoji(emojiId string) (*model.Emoji, *model.AppError)

GetEmoji returns a custom emoji based on the emojiId string.

@tag Emoji Minimum server version: 5.6

(API) CopyFileInfos 

CopyFileInfos(userId string, fileIds []string) ([]string, *model.AppError)

CopyFileInfos 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 to CreatePost. Use this API to duplicate a post and its file attachments without actually duplicating the uploaded files.

@tag File @tag User Minimum server version: 5.2

(API) GetFileInfo 

GetFileInfo(fileId string) (*model.FileInfo, *model.AppError)

GetFileInfo gets a File Info for a specific fileId

@tag File Minimum server version: 5.3

(API) GetFile 

GetFile(fileId string) ([]byte, *model.AppError)

GetFile gets content of a file by it's ID

@tag File Minimum server version: 5.8

GetFileLink(fileId string) (string, *model.AppError)

GetFileLink gets the public link to a file by fileId.

@tag File Minimum server version: 5.6

(API) ReadFile 

ReadFile(path string) ([]byte, *model.AppError)

ReadFile reads the file from the backend for a specific path

@tag File Minimum server version: 5.3

(API) GetEmojiImage 

GetEmojiImage(emojiId string) ([]byte, string, *model.AppError)

GetEmojiImage returns the emoji image.

@tag Emoji Minimum server version: 5.6

(API) UploadFile 

UploadFile(data []byte, channelId string, filename string) (*model.FileInfo, *model.AppError)

UploadFile will upload a file to a channel using a multipart request, to be later attached to a post.

@tag File @tag Channel Minimum server version: 5.6

(API) OpenInteractiveDialog 

OpenInteractiveDialog(dialog model.OpenDialogRequest) *model.AppError

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

(API) GetPlugins 

GetPlugins() ([]*model.Manifest, *model.AppError)

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

@tag Plugin Minimum server version: 5.6

(API) EnablePlugin 

EnablePlugin(id string) *model.AppError

EnablePlugin will enable an plugin installed.

@tag Plugin Minimum server version: 5.6

(API) DisablePlugin 

DisablePlugin(id string) *model.AppError

DisablePlugin will disable an enabled plugin.

@tag Plugin Minimum server version: 5.6

(API) RemovePlugin 

RemovePlugin(id string) *model.AppError

RemovePlugin will disable and delete a plugin.

@tag Plugin Minimum server version: 5.6

(API) GetPluginStatus 

GetPluginStatus(id string) (*model.PluginStatus, *model.AppError)

GetPluginStatus will return the status of a plugin.

@tag Plugin Minimum server version: 5.6

(API) InstallPlugin 

InstallPlugin(file io.Reader, replace bool) (*model.Manifest, *model.AppError)

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

@tag Plugin Minimum server version: 5.18

(API) KVSet 

KVSet(key string, value []byte) *model.AppError

KVSet stores a key-value pair, unique per plugin. Provided helper functions and internal plugin code will use the prefix `mmi_` before keys. Do not use this prefix.

@tag KeyValueStore Minimum server version: 5.2

(API) KVCompareAndSet 

KVCompareAndSet(key string, oldValue, newValue []byte) (bool, *model.AppError)

KVCompareAndSet updates a key-value pair, unique per plugin, but only if the current value matches the given oldValue. Inserts a new key if oldValue == nil. Returns (false, err) if DB error occurred Returns (false, nil) if current value != oldValue or key already exists when inserting Returns (true, nil) if current value == oldValue or new key is inserted

@tag KeyValueStore Minimum server version: 5.12

(API) KVCompareAndDelete 

KVCompareAndDelete(key string, oldValue []byte) (bool, *model.AppError)

KVCompareAndDelete deletes a key-value pair, unique per plugin, but only if the current value matches the given oldValue. 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

@tag KeyValueStore Minimum server version: 5.16

(API) KVSetWithOptions 

KVSetWithOptions(key string, value []byte, options model.PluginKVSetOptions) (bool, *model.AppError)

KVSetWithOptions stores a key-value pair, unique per plugin, according to the given options. 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.20

(API) KVSetWithExpiry 

KVSetWithExpiry(key string, value []byte, expireInSeconds int64) *model.AppError

KVSet stores a key-value pair with an expiry time, unique per plugin.

@tag KeyValueStore Minimum server version: 5.6

(API) KVGet 

KVGet(key string) ([]byte, *model.AppError)

KVGet retrieves a value based on the key, unique per plugin. Returns nil for non-existent keys.

@tag KeyValueStore Minimum server version: 5.2

(API) KVDelete 

KVDelete(key string) *model.AppError

KVDelete removes a key-value pair, unique per plugin. Returns nil for non-existent keys.

@tag KeyValueStore Minimum server version: 5.2

(API) KVDeleteAll 

KVDeleteAll() *model.AppError

KVDeleteAll removes all key-value pairs for a plugin.

@tag KeyValueStore Minimum server version: 5.6

(API) KVList 

KVList(page, perPage int) ([]string, *model.AppError)

KVList lists all keys for a plugin.

@tag KeyValueStore Minimum server version: 5.6

(API) PublishWebSocketEvent 

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

(API) HasPermissionTo 

HasPermissionTo(userId string, permission *model.Permission) bool

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

@tag User Minimum server version: 5.3

(API) HasPermissionToTeam 

HasPermissionToTeam(userId, teamId string, permission *model.Permission) bool

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

@tag User @tag Team Minimum server version: 5.3

(API) HasPermissionToChannel 

HasPermissionToChannel(userId, channelId string, permission *model.Permission) bool

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

@tag User @tag Channel Minimum server version: 5.3

(API) LogDebug 

LogDebug(msg string, keyValuePairs []interface{}) 

LogDebug writes a log message to the Mattermost server log file. Appropriate context such as the plugin name will already be added as fields so plugins do not need to add that info.

@tag Logging Minimum server version: 5.2

(API) LogInfo 

LogInfo(msg string, keyValuePairs []interface{}) 

LogInfo writes a log message to the Mattermost server log file. Appropriate context such as the plugin name will already be added as fields so plugins do not need to add that info.

@tag Logging Minimum server version: 5.2

(API) LogError 

LogError(msg string, keyValuePairs []interface{}) 

LogError writes a log message to the Mattermost server log file. Appropriate context such as the plugin name will already be added as fields so plugins do not need to add that info.

@tag Logging Minimum server version: 5.2

(API) LogWarn 

LogWarn(msg string, keyValuePairs []interface{}) 

LogWarn writes a log message to the Mattermost server log file. Appropriate context such as the plugin name will already be added as fields so plugins do not need to add that info.

@tag Logging Minimum server version: 5.2

(API) SendMail 

SendMail(to, subject, htmlBody string) *model.AppError

SendMail sends an email to a specific address

Minimum server version: 5.7

(API) CreateBot 

CreateBot(bot *model.Bot) (*model.Bot, *model.AppError)

CreateBot creates the given bot and corresponding user.

@tag Bot Minimum server version: 5.10

(API) PatchBot 

PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot, *model.AppError)

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

@tag Bot Minimum server version: 5.10

(API) GetBot 

GetBot(botUserId string, includeDeleted bool) (*model.Bot, *model.AppError)

GetBot returns the given bot.

@tag Bot Minimum server version: 5.10

(API) GetBots 

GetBots(options *model.BotGetOptions) ([]*model.Bot, *model.AppError)

GetBots returns the requested page of bots.

@tag Bot Minimum server version: 5.10

(API) UpdateBotActive 

UpdateBotActive(botUserId string, active bool) (*model.Bot, *model.AppError)

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

@tag Bot Minimum server version: 5.10

(API) PermanentDeleteBot 

PermanentDeleteBot(botUserId string) *model.AppError

PermanentDeleteBot permanently deletes a bot and its corresponding user.

@tag Bot Minimum server version: 5.10

(API) GetBotIconImage 

GetBotIconImage(botUserId string) ([]byte, *model.AppError)

GetBotIconImage gets LHS bot icon image.

@tag Bot Minimum server version: 5.14

(API) SetBotIconImage 

SetBotIconImage(botUserId string, data []byte) *model.AppError

SetBotIconImage sets LHS bot icon image. Icon image must be SVG format, all other formats are rejected.

@tag Bot Minimum server version: 5.14

(API) DeleteBotIconImage 

DeleteBotIconImage(botUserId string) *model.AppError

DeleteBotIconImage deletes LHS bot icon image.

@tag Bot Minimum server version: 5.14

(API) PluginHTTP 

PluginHTTP(request *http.Request) *http.Response

PluginHTTP allows inter-plugin requests to plugin APIs.

Minimum server version: 5.18

(API) LoadPluginConfiguration 

LoadPluginConfiguration(dest interface{}) error

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

@tag Plugin Minimum server version: 5.2

(API) RegisterCommand 

RegisterCommand(command *model.Command) error

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

@tag Command Minimum server version: 5.2

(API) UnregisterCommand 

UnregisterCommand(teamId, trigger string) error

UnregisterCommand unregisters a command previously registered via RegisterCommand.

@tag Command Minimum server version: 5.2

(API) GetSession 

GetSession(sessionId string) (*model.Session, *model.AppError)

GetSession returns the session object for the Session ID

Minimum server version: 5.2

(API) GetConfig 

GetConfig() *model.Config

GetConfig fetches the currently persisted config

@tag Configuration Minimum server version: 5.2

(API) GetUnsanitizedConfig 

GetUnsanitizedConfig() *model.Config

GetUnsanitizedConfig fetches the currently persisted config without removing secrets.

@tag Configuration Minimum server version: 5.16

(API) SaveConfig 

SaveConfig(config *model.Config) *model.AppError

SaveConfig sets the given config and persists the changes

@tag Configuration Minimum server version: 5.2

(API) GetPluginConfig 

GetPluginConfig() map[string]interface{}

GetPluginConfig fetches the currently persisted config of plugin

@tag Plugin Minimum server version: 5.6

(API) SavePluginConfig 

SavePluginConfig(config map[string]interface{}) *model.AppError

SavePluginConfig sets the given config for plugin and persists the changes

@tag Plugin Minimum server version: 5.6

(API) GetBundlePath 

GetBundlePath() (string, error)

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

@tag Plugin Minimum server version: 5.10

(API) GetLicense 

GetLicense() *model.License

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

@tag Server Minimum server version: 5.10

(API) GetServerVersion 

GetServerVersion() string

GetServerVersion return the current Mattermost server version

@tag Server Minimum server version: 5.4

(API) GetSystemInstallDate 

GetSystemInstallDate() (int64, *model.AppError)

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

@tag Server Minimum server version: 5.10

(API) GetDiagnosticId 

GetDiagnosticId() string

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

@tag Server Minimum server version: 5.10

(API) CreateUser 

CreateUser(user *model.User) (*model.User, *model.AppError)

CreateUser creates a user.

@tag User Minimum server version: 5.2

(API) DeleteUser 

DeleteUser(userId string) *model.AppError

DeleteUser deletes a user.

@tag User Minimum server version: 5.2

(API) GetUsers 

GetUsers(options *model.UserGetOptions) ([]*model.User, *model.AppError)

GetUsers a list of users based on search options.

@tag User Minimum server version: 5.10

(API) GetUser 

GetUser(userId string) (*model.User, *model.AppError)

GetUser gets a user.

@tag User Minimum server version: 5.2

(API) GetUserByEmail 

GetUserByEmail(email string) (*model.User, *model.AppError)

GetUserByEmail gets a user by their email address.

@tag User Minimum server version: 5.2

(API) GetUserByUsername 

GetUserByUsername(name string) (*model.User, *model.AppError)

GetUserByUsername gets a user by their username.

@tag User Minimum server version: 5.2

(API) GetUsersByUsernames 

GetUsersByUsernames(usernames []string) ([]*model.User, *model.AppError)

GetUsersByUsernames gets users by their usernames.

@tag User Minimum server version: 5.6

(API) GetUsersInTeam 

GetUsersInTeam(teamId string, page int, perPage int) ([]*model.User, *model.AppError)

GetUsersInTeam gets users in team.

@tag User @tag Team Minimum server version: 5.6

(API) GetTeamIcon 

GetTeamIcon(teamId string) ([]byte, *model.AppError)

GetTeamIcon gets the team icon.

@tag Team Minimum server version: 5.6

(API) SetTeamIcon 

SetTeamIcon(teamId string, data []byte) *model.AppError

SetTeamIcon sets the team icon.

@tag Team Minimum server version: 5.6

(API) RemoveTeamIcon 

RemoveTeamIcon(teamId string) *model.AppError

RemoveTeamIcon removes the team icon.

@tag Team Minimum server version: 5.6

(API) UpdateUser 

UpdateUser(user *model.User) (*model.User, *model.AppError)

UpdateUser updates a user.

@tag User Minimum server version: 5.2

(API) GetUserStatus 

GetUserStatus(userId string) (*model.Status, *model.AppError)

GetUserStatus will get a user's status.

@tag User Minimum server version: 5.2

(API) GetUserStatusesByIds 

GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.AppError)

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

@tag User Minimum server version: 5.2

(API) UpdateUserStatus 

UpdateUserStatus(userId, status string) (*model.Status, *model.AppError)

UpdateUserStatus 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".

@tag User Minimum server version: 5.2

(API) UpdateUserActive 

UpdateUserActive(userId string, active bool) *model.AppError

UpdateUserActive deactivates or reactivates an user.

@tag User Minimum server version: 5.8

(API) GetUsersInChannel 

GetUsersInChannel(channelId, sortBy string, page, perPage int) ([]*model.User, *model.AppError)

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

@tag User @tag Channel Minimum server version: 5.6

(API) GetLDAPUserAttributes 

GetLDAPUserAttributes(userId string, attributes []string) (map[string]string, *model.AppError)

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

@tag User Minimum server version: 5.3

(API) CreateTeam 

CreateTeam(team *model.Team) (*model.Team, *model.AppError)

CreateTeam creates a team.

@tag Team Minimum server version: 5.2

(API) DeleteTeam 

DeleteTeam(teamId string) *model.AppError

DeleteTeam deletes a team.

@tag Team Minimum server version: 5.2

(API) GetTeams 

GetTeams() ([]*model.Team, *model.AppError)

GetTeam gets all teams.

@tag Team Minimum server version: 5.2

(API) GetTeam 

GetTeam(teamId string) (*model.Team, *model.AppError)

GetTeam gets a team.

@tag Team Minimum server version: 5.2

(API) GetTeamByName 

GetTeamByName(name string) (*model.Team, *model.AppError)

GetTeamByName gets a team by its name.

@tag Team Minimum server version: 5.2

(API) GetTeamsUnreadForUser 

GetTeamsUnreadForUser(userId string) ([]*model.TeamUnread, *model.AppError)

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

@tag Team @tag User Minimum server version: 5.6

(API) UpdateTeam 

UpdateTeam(team *model.Team) (*model.Team, *model.AppError)

UpdateTeam updates a team.

@tag Team Minimum server version: 5.2

(API) SearchTeams 

SearchTeams(term string) ([]*model.Team, *model.AppError)

SearchTeams search a team.

@tag Team Minimum server version: 5.8

(API) GetTeamsForUser 

GetTeamsForUser(userId string) ([]*model.Team, *model.AppError)

GetTeamsForUser returns list of teams of given user ID.

@tag Team @tag User Minimum server version: 5.6

(API) CreateTeamMember 

CreateTeamMember(teamId, userId string) (*model.TeamMember, *model.AppError)

CreateTeamMember creates a team membership.

@tag Team @tag User Minimum server version: 5.2

(API) CreateTeamMembers 

CreateTeamMembers(teamId string, userIds []string, requestorId string) ([]*model.TeamMember, *model.AppError)

CreateTeamMembers creates a team membership for all provided user ids.

@tag Team @tag User Minimum server version: 5.2

(API) DeleteTeamMember 

DeleteTeamMember(teamId, userId, requestorId string) *model.AppError

DeleteTeamMember deletes a team membership.

@tag Team @tag User Minimum server version: 5.2

(API) GetTeamMembers 

GetTeamMembers(teamId string, page, perPage int) ([]*model.TeamMember, *model.AppError)

GetTeamMembers returns the memberships of a specific team.

@tag Team @tag User Minimum server version: 5.2

(API) GetTeamMember 

GetTeamMember(teamId, userId string) (*model.TeamMember, *model.AppError)

GetTeamMember returns a specific membership.

@tag Team @tag User Minimum server version: 5.2

(API) GetTeamMembersForUser 

GetTeamMembersForUser(userId string, page int, perPage int) ([]*model.TeamMember, *model.AppError)

GetTeamMembersForUser returns all team memberships for a user.

@tag Team @tag User Minimum server version: 5.10

(API) UpdateTeamMemberRoles 

UpdateTeamMemberRoles(teamId, userId, newRoles string) (*model.TeamMember, *model.AppError)

UpdateTeamMemberRoles updates the role for a team membership.

@tag Team @tag User Minimum server version: 5.2

(API) CreateChannel 

CreateChannel(channel *model.Channel) (*model.Channel, *model.AppError)

CreateChannel creates a channel.

@tag Channel Minimum server version: 5.2

(API) DeleteChannel 

DeleteChannel(channelId string) *model.AppError

DeleteChannel deletes a channel.

@tag Channel Minimum server version: 5.2

(API) GetPublicChannelsForTeam 

GetPublicChannelsForTeam(teamId string, page, perPage int) ([]*model.Channel, *model.AppError)

GetPublicChannelsForTeam gets a list of all channels.

@tag Channel @tag Team Minimum server version: 5.2

(API) GetChannel 

GetChannel(channelId string) (*model.Channel, *model.AppError)

GetChannel gets a channel.

@tag Channel Minimum server version: 5.2

(API) GetChannelByName 

GetChannelByName(teamId, name string, includeDeleted bool) (*model.Channel, *model.AppError)

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

@tag Channel Minimum server version: 5.2

(API) GetChannelByNameForTeamName 

GetChannelByNameForTeamName(teamName, channelName string, includeDeleted bool) (*model.Channel, *model.AppError)

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

@tag Channel @tag Team Minimum server version: 5.2

(API) GetChannelsForTeamForUser 

GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) ([]*model.Channel, *model.AppError)

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

@tag Channel @tag Team @tag User Minimum server version: 5.6

(API) GetChannelStats 

GetChannelStats(channelId string) (*model.ChannelStats, *model.AppError)

GetChannelStats gets statistics for a channel.

@tag Channel Minimum server version: 5.6

(API) GetDirectChannel 

GetDirectChannel(userId1, userId2 string) (*model.Channel, *model.AppError)

GetDirectChannel gets a direct message channel. If the channel does not exist it will create it.

@tag Channel @tag User Minimum server version: 5.2

(API) GetGroupChannel 

GetGroupChannel(userIds []string) (*model.Channel, *model.AppError)

GetGroupChannel gets a group message channel. If the channel does not exist it will create it.

@tag Channel @tag User Minimum server version: 5.2

(API) UpdateChannel 

UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError)

UpdateChannel updates a channel.

@tag Channel Minimum server version: 5.2

(API) SearchChannels 

SearchChannels(teamId string, term string) ([]*model.Channel, *model.AppError)

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

@tag Channel Minimum server version: 5.6

(API) SearchUsers 

SearchUsers(search *model.UserSearch) ([]*model.User, *model.AppError)

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

@tag User Minimum server version: 5.6

(API) SearchPostsInTeam 

SearchPostsInTeam(teamId string, paramsList []*model.SearchParams) ([]*model.Post, *model.AppError)

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

@tag Post @tag Team Minimum server version: 5.10

(API) AddChannelMember 

AddChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError)

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

@tag Channel @tag User Minimum server version: 5.2

(API) AddUserToChannel 

AddUserToChannel(channelId, userId, asUserId string) (*model.ChannelMember, *model.AppError)

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

@tag User @tag Channel Minimum server version: 5.18

(API) GetChannelMember 

GetChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError)

GetChannelMember gets a channel membership for a user.

@tag Channel @tag User Minimum server version: 5.2

(API) GetChannelMembers 

GetChannelMembers(channelId string, page, perPage int) (*model.ChannelMembers, *model.AppError)

GetChannelMembers gets a channel membership for all users.

@tag Channel @tag User Minimum server version: 5.6

(API) GetChannelMembersByIds 

GetChannelMembersByIds(channelId string, userIds []string) (*model.ChannelMembers, *model.AppError)

GetChannelMembersByIds gets a channel membership for a particular User

@tag Channel @tag User Minimum server version: 5.6

(API) GetChannelMembersForUser 

GetChannelMembersForUser(teamId, userId string, page, perPage int) ([]*model.ChannelMember, *model.AppError)

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

@tag Channel @tag User Minimum server version: 5.10

(API) UpdateChannelMemberRoles 

UpdateChannelMemberRoles(channelId, userId, newRoles string) (*model.ChannelMember, *model.AppError)

UpdateChannelMemberRoles updates a user's roles for a channel.

@tag Channel @tag User Minimum server version: 5.2

(API) UpdateChannelMemberNotifications 

UpdateChannelMemberNotifications(channelId, userId string, notifications map[string]string) (*model.ChannelMember, *model.AppError)

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

@tag Channel @tag User Minimum server version: 5.2

(API) GetGroup 

GetGroup(groupId string) (*model.Group, *model.AppError)

GetGroup gets a group by ID.

@tag Group Minimum server version: 5.18

(API) GetGroupByName 

GetGroupByName(name string) (*model.Group, *model.AppError)

GetGroupByName gets a group by name.

@tag Group Minimum server version: 5.18

(API) GetGroupsForUser 

GetGroupsForUser(userId string) ([]*model.Group, *model.AppError)

GetGroupsForUser gets the groups a user is in.

@tag Group @tag User Minimum server version: 5.18

(API) DeleteChannelMember 

DeleteChannelMember(channelId, userId string) *model.AppError

DeleteChannelMember deletes a channel membership for a user.

@tag Channel @tag User Minimum server version: 5.2

(API) CreatePost 

CreatePost(post *model.Post) (*model.Post, *model.AppError)

CreatePost creates a post.

@tag Post Minimum server version: 5.2

(API) AddReaction 

AddReaction(reaction *model.Reaction) (*model.Reaction, *model.AppError)

AddReaction add a reaction to a post.

@tag Post Minimum server version: 5.3

(API) RemoveReaction 

RemoveReaction(reaction *model.Reaction) *model.AppError

RemoveReaction remove a reaction from a post.

@tag Post Minimum server version: 5.3

(API) GetReactions 

GetReactions(postId string) ([]*model.Reaction, *model.AppError)

GetReaction get the reactions of a post.

@tag Post Minimum server version: 5.3

(API) SendEphemeralPost 

SendEphemeralPost(userId string, post *model.Post) *model.Post

SendEphemeralPost creates an ephemeral post.

@tag Post Minimum server version: 5.2

(API) UpdateEphemeralPost 

UpdateEphemeralPost(userId string, post *model.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.

@tag Post Minimum server version: 5.2

(API) DeleteEphemeralPost 

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.

@tag Post Minimum server version: 5.2

(API) DeletePost 

DeletePost(postId string) *model.AppError

DeletePost deletes a post.

@tag Post Minimum server version: 5.2

(API) GetPostThread 

GetPostThread(postId string) (*model.PostList, *model.AppError)

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

@tag Post Minimum server version: 5.6

(API) GetPost 

GetPost(postId string) (*model.Post, *model.AppError)

GetPost gets a post.

@tag Post Minimum server version: 5.2

(API) GetPostsSince 

GetPostsSince(channelId string, time int64) (*model.PostList, *model.AppError)

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

@tag Post @tag Channel Minimum server version: 5.6

(API) GetPostsAfter 

GetPostsAfter(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError)

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

@tag Post @tag Channel Minimum server version: 5.6

(API) GetPostsBefore 

GetPostsBefore(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError)

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

@tag Post @tag Channel Minimum server version: 5.6

(API) GetPostsForChannel 

GetPostsForChannel(channelId string, page, perPage int) (*model.PostList, *model.AppError)

GetPostsForChannel gets a list of posts for a channel.

@tag Post @tag Channel Minimum server version: 5.6

(API) GetTeamStats 

GetTeamStats(teamId string) (*model.TeamStats, *model.AppError)

GetTeamStats gets a team's statistics

@tag Team Minimum server version: 5.8

(API) UpdatePost 

UpdatePost(post *model.Post) (*model.Post, *model.AppError)

UpdatePost updates a post.

@tag Post Minimum server version: 5.2

(API) GetProfileImage 

GetProfileImage(userId string) ([]byte, *model.AppError)

GetProfileImage gets user's profile image.

@tag User Minimum server version: 5.6

(API) SetProfileImage 

SetProfileImage(userId string, data []byte) *model.AppError

SetProfileImage sets a user's profile image.

@tag User Minimum server version: 5.6

(API) GetEmojiList 

GetEmojiList(sortBy string, page, perPage int) ([]*model.Emoji, *model.AppError)

GetEmojiList returns a page of custom emoji on the system.

The sortBy parameter can be: "name".

@tag Emoji Minimum server version: 5.6

(API) GetEmojiByName 

GetEmojiByName(name string) (*model.Emoji, *model.AppError)

GetEmojiByName gets an emoji by it's name.

@tag Emoji Minimum server version: 5.6

(API) GetEmoji 

GetEmoji(emojiId string) (*model.Emoji, *model.AppError)

GetEmoji returns a custom emoji based on the emojiId string.

@tag Emoji Minimum server version: 5.6

(API) CopyFileInfos 

CopyFileInfos(userId string, fileIds []string) ([]string, *model.AppError)

CopyFileInfos 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 to CreatePost. Use this API to duplicate a post and its file attachments without actually duplicating the uploaded files.

@tag File @tag User Minimum server version: 5.2

(API) GetFileInfo 

GetFileInfo(fileId string) (*model.FileInfo, *model.AppError)

GetFileInfo gets a File Info for a specific fileId

@tag File Minimum server version: 5.3

(API) GetFile 

GetFile(fileId string) ([]byte, *model.AppError)

GetFile gets content of a file by it's ID

@tag File Minimum server version: 5.8

GetFileLink(fileId string) (string, *model.AppError)

GetFileLink gets the public link to a file by fileId.

@tag File Minimum server version: 5.6

(API) ReadFile 

ReadFile(path string) ([]byte, *model.AppError)

ReadFile reads the file from the backend for a specific path

@tag File Minimum server version: 5.3

(API) GetEmojiImage 

GetEmojiImage(emojiId string) ([]byte, string, *model.AppError)

GetEmojiImage returns the emoji image.

@tag Emoji Minimum server version: 5.6

(API) UploadFile 

UploadFile(data []byte, channelId string, filename string) (*model.FileInfo, *model.AppError)

UploadFile will upload a file to a channel using a multipart request, to be later attached to a post.

@tag File @tag Channel Minimum server version: 5.6

(API) OpenInteractiveDialog 

OpenInteractiveDialog(dialog model.OpenDialogRequest) *model.AppError

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

(API) GetPlugins 

GetPlugins() ([]*model.Manifest, *model.AppError)

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

@tag Plugin Minimum server version: 5.6

(API) EnablePlugin 

EnablePlugin(id string) *model.AppError

EnablePlugin will enable an plugin installed.

@tag Plugin Minimum server version: 5.6

(API) DisablePlugin 

DisablePlugin(id string) *model.AppError

DisablePlugin will disable an enabled plugin.

@tag Plugin Minimum server version: 5.6

(API) RemovePlugin 

RemovePlugin(id string) *model.AppError

RemovePlugin will disable and delete a plugin.

@tag Plugin Minimum server version: 5.6

(API) GetPluginStatus 

GetPluginStatus(id string) (*model.PluginStatus, *model.AppError)

GetPluginStatus will return the status of a plugin.

@tag Plugin Minimum server version: 5.6

(API) InstallPlugin 

InstallPlugin(file io.Reader, replace bool) (*model.Manifest, *model.AppError)

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

@tag Plugin Minimum server version: 5.18

(API) KVSet 

KVSet(key string, value []byte) *model.AppError

KVSet stores a key-value pair, unique per plugin. Provided helper functions and internal plugin code will use the prefix `mmi_` before keys. Do not use this prefix.

@tag KeyValueStore Minimum server version: 5.2

(API) KVCompareAndSet 

KVCompareAndSet(key string, oldValue, newValue []byte) (bool, *model.AppError)

KVCompareAndSet updates a key-value pair, unique per plugin, but only if the current value matches the given oldValue. Inserts a new key if oldValue == nil. Returns (false, err) if DB error occurred Returns (false, nil) if current value != oldValue or key already exists when inserting Returns (true, nil) if current value == oldValue or new key is inserted

@tag KeyValueStore Minimum server version: 5.12

(API) KVCompareAndDelete 

KVCompareAndDelete(key string, oldValue []byte) (bool, *model.AppError)

KVCompareAndDelete deletes a key-value pair, unique per plugin, but only if the current value matches the given oldValue. 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

@tag KeyValueStore Minimum server version: 5.16

(API) KVSetWithOptions 

KVSetWithOptions(key string, value []byte, options model.PluginKVSetOptions) (bool, *model.AppError)

KVSetWithOptions stores a key-value pair, unique per plugin, according to the given options. 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.20

(API) KVSetWithExpiry 

KVSetWithExpiry(key string, value []byte, expireInSeconds int64) *model.AppError

KVSet stores a key-value pair with an expiry time, unique per plugin.

@tag KeyValueStore Minimum server version: 5.6

(API) KVGet 

KVGet(key string) ([]byte, *model.AppError)

KVGet retrieves a value based on the key, unique per plugin. Returns nil for non-existent keys.

@tag KeyValueStore Minimum server version: 5.2

(API) KVDelete 

KVDelete(key string) *model.AppError

KVDelete removes a key-value pair, unique per plugin. Returns nil for non-existent keys.

@tag KeyValueStore Minimum server version: 5.2

(API) KVDeleteAll 

KVDeleteAll() *model.AppError

KVDeleteAll removes all key-value pairs for a plugin.

@tag KeyValueStore Minimum server version: 5.6

(API) KVList 

KVList(page, perPage int) ([]string, *model.AppError)

KVList lists all keys for a plugin.

@tag KeyValueStore Minimum server version: 5.6

(API) PublishWebSocketEvent 

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

(API) HasPermissionTo 

HasPermissionTo(userId string, permission *model.Permission) bool

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

@tag User Minimum server version: 5.3

(API) HasPermissionToTeam 

HasPermissionToTeam(userId, teamId string, permission *model.Permission) bool

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

@tag User @tag Team Minimum server version: 5.3

(API) HasPermissionToChannel 

HasPermissionToChannel(userId, channelId string, permission *model.Permission) bool

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

@tag User @tag Channel Minimum server version: 5.3

(API) LogDebug 

LogDebug(msg string, keyValuePairs []interface{}) 

LogDebug writes a log message to the Mattermost server log file. Appropriate context such as the plugin name will already be added as fields so plugins do not need to add that info.

@tag Logging Minimum server version: 5.2

(API) LogInfo 

LogInfo(msg string, keyValuePairs []interface{}) 

LogInfo writes a log message to the Mattermost server log file. Appropriate context such as the plugin name will already be added as fields so plugins do not need to add that info.

@tag Logging Minimum server version: 5.2

(API) LogError 

LogError(msg string, keyValuePairs []interface{}) 

LogError writes a log message to the Mattermost server log file. Appropriate context such as the plugin name will already be added as fields so plugins do not need to add that info.

@tag Logging Minimum server version: 5.2

(API) LogWarn 

LogWarn(msg string, keyValuePairs []interface{}) 

LogWarn writes a log message to the Mattermost server log file. Appropriate context such as the plugin name will already be added as fields so plugins do not need to add that info.

@tag Logging Minimum server version: 5.2

(API) SendMail 

SendMail(to, subject, htmlBody string) *model.AppError

SendMail sends an email to a specific address

Minimum server version: 5.7

(API) CreateBot 

CreateBot(bot *model.Bot) (*model.Bot, *model.AppError)

CreateBot creates the given bot and corresponding user.

@tag Bot Minimum server version: 5.10

(API) PatchBot 

PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot, *model.AppError)

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

@tag Bot Minimum server version: 5.10

(API) GetBot 

GetBot(botUserId string, includeDeleted bool) (*model.Bot, *model.AppError)

GetBot returns the given bot.

@tag Bot Minimum server version: 5.10

(API) GetBots 

GetBots(options *model.BotGetOptions) ([]*model.Bot, *model.AppError)

GetBots returns the requested page of bots.

@tag Bot Minimum server version: 5.10

(API) UpdateBotActive 

UpdateBotActive(botUserId string, active bool) (*model.Bot, *model.AppError)

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

@tag Bot Minimum server version: 5.10

(API) PermanentDeleteBot 

PermanentDeleteBot(botUserId string) *model.AppError

PermanentDeleteBot permanently deletes a bot and its corresponding user.

@tag Bot Minimum server version: 5.10

(API) GetBotIconImage 

GetBotIconImage(botUserId string) ([]byte, *model.AppError)

GetBotIconImage gets LHS bot icon image.

@tag Bot Minimum server version: 5.14

(API) SetBotIconImage 

SetBotIconImage(botUserId string, data []byte) *model.AppError

SetBotIconImage sets LHS bot icon image. Icon image must be SVG format, all other formats are rejected.

@tag Bot Minimum server version: 5.14

(API) DeleteBotIconImage 

DeleteBotIconImage(botUserId string) *model.AppError

DeleteBotIconImage deletes LHS bot icon image.

@tag Bot Minimum server version: 5.14

(API) PluginHTTP 

PluginHTTP(request *http.Request) *http.Response

PluginHTTP allows inter-plugin requests to plugin APIs.

Minimum server version: 5.18


Hooks

(Hooks) OnActivate 

OnActivate() error

OnActivate is invoked when the plugin is activated. If an error is returned, the plugin will be terminated. The plugin will not receive hooks until after OnActivate returns without error. OnConfigurationChange will be called once before OnActivate.

(Hooks) Implemented 

Implemented() ([]string, error)

Implemented returns a list of hooks that are implemented by the plugin. Plugins do not need to provide an implementation. Any given will be ignored.

(Hooks) OnDeactivate 

OnDeactivate() error

OnDeactivate is invoked when the plugin is deactivated. This is the plugin's last chance to use the API, and the plugin will be terminated shortly after this invocation. The plugin will stop receiving hooks just prior to this method being called.

(Hooks) OnConfigurationChange 

OnConfigurationChange() error

OnConfigurationChange is invoked when configuration changes may have been made. Any returned error is logged, but does not stop the plugin. You must be prepared to handle a configuration failure gracefully. It is called once before OnActivate.

(Hooks) ServeHTTP 

ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) 

ServeHTTP allows the plugin to implement the http.Handler interface. Requests destined for the /plugins/{id} path will be routed to the plugin.

The Mattermost-User-Id header will be present if (and only if) the request is by an authenticated user.

(Hooks) ExecuteCommand 

ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError)

ExecuteCommand executes a command that has been previously registered via the RegisterCommand API.

(Hooks) UserHasBeenCreated 

UserHasBeenCreated(c *plugin.Context, user *model.User) 

UserHasBeenCreated is invoked after a user was created.

Minimum server version: 5.10

(Hooks) UserWillLogIn 

UserWillLogIn(c *plugin.Context, user *model.User) string

UserWillLogIn before the login of the user is returned. Returning a non empty string will reject the login event. If you don't need to reject the login event, see UserHasLoggedIn

(Hooks) UserHasLoggedIn 

UserHasLoggedIn(c *plugin.Context, user *model.User) 

UserHasLoggedIn is invoked after a user has logged in.

(Hooks) MessageWillBePosted 

MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string)

MessageWillBePosted is invoked when a message is posted by a user before it is committed to the database. If you also want to act on edited posts, see MessageWillBeUpdated.

To reject a post, return an non-empty string describing why the post was rejected. To modify the post, return the replacement, non-nil *model.Post and an empty string. To allow the post without modification, return a nil *model.Post and an empty string. To dismiss the post, return a nil *model.Post and the const DismissPostError string.

If you don't need to modify or reject posts, use MessageHasBeenPosted instead.

Note that this method will be called for posts created by plugins, including the plugin that created the post.

(Hooks) MessageWillBeUpdated 

MessageWillBeUpdated(c *plugin.Context, newPost, oldPost *model.Post) (*model.Post, string)

MessageWillBeUpdated is invoked when a message is updated by a user before it is committed to the database. If you also want to act on new posts, see MessageWillBePosted. Return values should be the modified post or nil if rejected and an explanation for the user. On rejection, the post will be kept in its previous state.

If you don't need to modify or rejected updated posts, use MessageHasBeenUpdated instead.

Note that this method will be called for posts updated by plugins, including the plugin that updated the post.

(Hooks) MessageHasBeenPosted 

MessageHasBeenPosted(c *plugin.Context, post *model.Post) 

MessageHasBeenPosted is invoked after the message has been committed to the database. If you need to modify or reject the post, see MessageWillBePosted Note that this method will be called for posts created by plugins, including the plugin that created the post.

(Hooks) MessageHasBeenUpdated 

MessageHasBeenUpdated(c *plugin.Context, newPost, oldPost *model.Post) 

MessageHasBeenUpdated is invoked after a message is updated and has been updated in the database. If you need to modify or reject the post, see MessageWillBeUpdated Note that this method will be called for posts created by plugins, including the plugin that created the post.

(Hooks) ChannelHasBeenCreated 

ChannelHasBeenCreated(c *plugin.Context, channel *model.Channel) 

ChannelHasBeenCreated is invoked after the channel has been committed to the database.

(Hooks) UserHasJoinedChannel 

UserHasJoinedChannel(c *plugin.Context, channelMember *model.ChannelMember, actor *model.User) 

UserHasJoinedChannel is invoked after the membership has been committed to the database. If actor is not nil, the user was invited to the channel by the actor.

(Hooks) UserHasLeftChannel 

UserHasLeftChannel(c *plugin.Context, channelMember *model.ChannelMember, actor *model.User) 

UserHasLeftChannel is invoked after the membership has been removed from the database. If actor is not nil, the user was removed from the channel by the actor.

(Hooks) UserHasJoinedTeam 

UserHasJoinedTeam(c *plugin.Context, teamMember *model.TeamMember, actor *model.User) 

UserHasJoinedTeam is invoked after the membership has been committed to the database. If actor is not nil, the user was added to the team by the actor.

(Hooks) UserHasLeftTeam 

UserHasLeftTeam(c *plugin.Context, teamMember *model.TeamMember, actor *model.User) 

UserHasLeftTeam is invoked after the membership has been removed from the database. If actor is not nil, the user was removed from the team by the actor.

(Hooks) FileWillBeUploaded 

FileWillBeUploaded(c *plugin.Context, info *model.FileInfo, file io.Reader, output io.Writer) (*model.FileInfo, string)

FileWillBeUploaded is invoked when a file is uploaded, but before it is committed to backing store. Read from file to retrieve the body of the uploaded file.

To reject a file upload, return an non-empty string describing why the file was rejected. To modify the file, write to the output and/or return a non-nil *model.FileInfo, as well as an empty string. To allow the file without modification, do not write to the output and return a nil *model.FileInfo and an empty string.

Note that this method will be called for files uploaded by plugins, including the plugin that uploaded the post. FileInfo.Size will be automatically set properly if you modify the file.

(Hooks) OnActivate 

OnActivate() error

OnActivate is invoked when the plugin is activated. If an error is returned, the plugin will be terminated. The plugin will not receive hooks until after OnActivate returns without error. OnConfigurationChange will be called once before OnActivate.

(Hooks) Implemented 

Implemented() ([]string, error)

Implemented returns a list of hooks that are implemented by the plugin. Plugins do not need to provide an implementation. Any given will be ignored.

(Hooks) OnDeactivate 

OnDeactivate() error

OnDeactivate is invoked when the plugin is deactivated. This is the plugin's last chance to use the API, and the plugin will be terminated shortly after this invocation. The plugin will stop receiving hooks just prior to this method being called.

(Hooks) OnConfigurationChange 

OnConfigurationChange() error

OnConfigurationChange is invoked when configuration changes may have been made. Any returned error is logged, but does not stop the plugin. You must be prepared to handle a configuration failure gracefully. It is called once before OnActivate.

(Hooks) ServeHTTP 

ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) 

ServeHTTP allows the plugin to implement the http.Handler interface. Requests destined for the /plugins/{id} path will be routed to the plugin.

The Mattermost-User-Id header will be present if (and only if) the request is by an authenticated user.

(Hooks) ExecuteCommand 

ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError)

ExecuteCommand executes a command that has been previously registered via the RegisterCommand API.

(Hooks) UserHasBeenCreated 

UserHasBeenCreated(c *plugin.Context, user *model.User) 

UserHasBeenCreated is invoked after a user was created.

Minimum server version: 5.10

(Hooks) UserWillLogIn 

UserWillLogIn(c *plugin.Context, user *model.User) string

UserWillLogIn before the login of the user is returned. Returning a non empty string will reject the login event. If you don't need to reject the login event, see UserHasLoggedIn

(Hooks) UserHasLoggedIn 

UserHasLoggedIn(c *plugin.Context, user *model.User) 

UserHasLoggedIn is invoked after a user has logged in.

(Hooks) MessageWillBePosted 

MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string)

MessageWillBePosted is invoked when a message is posted by a user before it is committed to the database. If you also want to act on edited posts, see MessageWillBeUpdated.

To reject a post, return an non-empty string describing why the post was rejected. To modify the post, return the replacement, non-nil *model.Post and an empty string. To allow the post without modification, return a nil *model.Post and an empty string. To dismiss the post, return a nil *model.Post and the const DismissPostError string.

If you don't need to modify or reject posts, use MessageHasBeenPosted instead.

Note that this method will be called for posts created by plugins, including the plugin that created the post.

(Hooks) MessageWillBeUpdated 

MessageWillBeUpdated(c *plugin.Context, newPost, oldPost *model.Post) (*model.Post, string)

MessageWillBeUpdated is invoked when a message is updated by a user before it is committed to the database. If you also want to act on new posts, see MessageWillBePosted. Return values should be the modified post or nil if rejected and an explanation for the user. On rejection, the post will be kept in its previous state.

If you don't need to modify or rejected updated posts, use MessageHasBeenUpdated instead.

Note that this method will be called for posts updated by plugins, including the plugin that updated the post.

(Hooks) MessageHasBeenPosted 

MessageHasBeenPosted(c *plugin.Context, post *model.Post) 

MessageHasBeenPosted is invoked after the message has been committed to the database. If you need to modify or reject the post, see MessageWillBePosted Note that this method will be called for posts created by plugins, including the plugin that created the post.

(Hooks) MessageHasBeenUpdated 

MessageHasBeenUpdated(c *plugin.Context, newPost, oldPost *model.Post) 

MessageHasBeenUpdated is invoked after a message is updated and has been updated in the database. If you need to modify or reject the post, see MessageWillBeUpdated Note that this method will be called for posts created by plugins, including the plugin that created the post.

(Hooks) ChannelHasBeenCreated 

ChannelHasBeenCreated(c *plugin.Context, channel *model.Channel) 

ChannelHasBeenCreated is invoked after the channel has been committed to the database.

(Hooks) UserHasJoinedChannel 

UserHasJoinedChannel(c *plugin.Context, channelMember *model.ChannelMember, actor *model.User) 

UserHasJoinedChannel is invoked after the membership has been committed to the database. If actor is not nil, the user was invited to the channel by the actor.

(Hooks) UserHasLeftChannel 

UserHasLeftChannel(c *plugin.Context, channelMember *model.ChannelMember, actor *model.User) 

UserHasLeftChannel is invoked after the membership has been removed from the database. If actor is not nil, the user was removed from the channel by the actor.

(Hooks) UserHasJoinedTeam 

UserHasJoinedTeam(c *plugin.Context, teamMember *model.TeamMember, actor *model.User) 

UserHasJoinedTeam is invoked after the membership has been committed to the database. If actor is not nil, the user was added to the team by the actor.

(Hooks) UserHasLeftTeam 

UserHasLeftTeam(c *plugin.Context, teamMember *model.TeamMember, actor *model.User) 

UserHasLeftTeam is invoked after the membership has been removed from the database. If actor is not nil, the user was removed from the team by the actor.

(Hooks) FileWillBeUploaded 

FileWillBeUploaded(c *plugin.Context, info *model.FileInfo, file io.Reader, output io.Writer) (*model.FileInfo, string)

FileWillBeUploaded is invoked when a file is uploaded, but before it is committed to backing store. Read from file to retrieve the body of the uploaded file.

To reject a file upload, return an non-empty string describing why the file was rejected. To modify the file, write to the output and/or return a non-nil *model.FileInfo, as well as an empty string. To allow the file without modification, do not write to the output and return a nil *model.FileInfo and an empty string.

Note that this method will be called for files uploaded by plugins, including the plugin that uploaded the post. FileInfo.Size will be automatically set properly if you modify the file.


Helpers

(Helpers) EnsureBot 

EnsureBot(bot *model.Bot, options []plugin.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.

Minimum server version: 5.10

(Helpers) KVSetJSON 

KVSetJSON(key string, value interface{}) error

KVSetJSON stores a key-value pair, unique per plugin, marshalling the given value as a JSON string.

Deprecated: Use p.API.KVSetWithOptions instead.

Minimum server version: 5.2

(Helpers) KVCompareAndSetJSON 

KVCompareAndSetJSON(key string, oldValue interface{}, newValue interface{}) (bool, error)

KVCompareAndSetJSON updates a key-value pair, unique per plugin, but only if the current value matches the given oldValue after marshalling as a JSON string. Inserts a new key if oldValue == nil. Returns (false, err) if DB error occurred Returns (false, nil) if current value != oldValue or key already exists when inserting Returns (true, nil) if current value == oldValue or new key is inserted

Deprecated: Use p.API.KVSetWithOptions instead.

Minimum server version: 5.12

(Helpers) KVCompareAndDeleteJSON 

KVCompareAndDeleteJSON(key string, oldValue interface{}) (bool, error)

KVCompareAndDeleteJSON deletes a key-value pair, unique per plugin, but only if the current value matches the given oldValue after marshalling as a JSON string. Returns (false, err) if DB error occurred Returns (false, nil) if current value != oldValue or the key was already deleted Returns (true, nil) if current value == oldValue

Minimum server version: 5.16

(Helpers) KVGetJSON 

KVGetJSON(key string, value interface{}) (bool, error)

KVGetJSON retrieves a value based on the key, unique per plugin, unmarshalling the previously set JSON string into the given value. Returns true if the key exists.

Minimum server version: 5.2

(Helpers) KVSetWithExpiryJSON 

KVSetWithExpiryJSON(key string, value interface{}, expireInSeconds int64) error

KVSetWithExpiryJSON stores a key-value pair with an expiry time, unique per plugin, marshalling the given value as a JSON string.

Deprecated: Use p.API.KVSetWithOptions instead.

Minimum server version: 5.6

(Helpers) ShouldProcessMessage 

ShouldProcessMessage(post *model.Post, options []plugin.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 behaviour 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

(Helpers) EnsureBot 

EnsureBot(bot *model.Bot, options []plugin.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.

Minimum server version: 5.10

(Helpers) KVSetJSON 

KVSetJSON(key string, value interface{}) error

KVSetJSON stores a key-value pair, unique per plugin, marshalling the given value as a JSON string.

Deprecated: Use p.API.KVSetWithOptions instead.

Minimum server version: 5.2

(Helpers) KVCompareAndSetJSON 

KVCompareAndSetJSON(key string, oldValue interface{}, newValue interface{}) (bool, error)

KVCompareAndSetJSON updates a key-value pair, unique per plugin, but only if the current value matches the given oldValue after marshalling as a JSON string. Inserts a new key if oldValue == nil. Returns (false, err) if DB error occurred Returns (false, nil) if current value != oldValue or key already exists when inserting Returns (true, nil) if current value == oldValue or new key is inserted

Deprecated: Use p.API.KVSetWithOptions instead.

Minimum server version: 5.12

(Helpers) KVCompareAndDeleteJSON 

KVCompareAndDeleteJSON(key string, oldValue interface{}) (bool, error)

KVCompareAndDeleteJSON deletes a key-value pair, unique per plugin, but only if the current value matches the given oldValue after marshalling as a JSON string. Returns (false, err) if DB error occurred Returns (false, nil) if current value != oldValue or the key was already deleted Returns (true, nil) if current value == oldValue

Minimum server version: 5.16

(Helpers) KVGetJSON 

KVGetJSON(key string, value interface{}) (bool, error)

KVGetJSON retrieves a value based on the key, unique per plugin, unmarshalling the previously set JSON string into the given value. Returns true if the key exists.

Minimum server version: 5.2

(Helpers) KVSetWithExpiryJSON 

KVSetWithExpiryJSON(key string, value interface{}, expireInSeconds int64) error

KVSetWithExpiryJSON stores a key-value pair with an expiry time, unique per plugin, marshalling the given value as a JSON string.

Deprecated: Use p.API.KVSetWithOptions instead.

Minimum server version: 5.6

(Helpers) ShouldProcessMessage 

ShouldProcessMessage(post *model.Post, options []plugin.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 behaviour 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


Examples

(Example) HelloWorld 

This example demonstrates a plugin that handles HTTP requests which respond by greeting the world.

package main

import (
	"fmt"
	"net/http"

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

type HelloWorldPlugin struct {
	plugin.MattermostPlugin
}

func (p *HelloWorldPlugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, "Hello, world!")
}

// This example demonstrates a plugin that handles HTTP requests which respond by greeting the
// world.
func main() {
	plugin.ClientMain(&HelloWorldPlugin{})
}

(Example) HelpPlugin 

package main

import (
	"strings"
	"sync"

	"github.com/pkg/errors"

	"github.com/mattermost/mattermost-server/v5/model"
	"github.com/mattermost/mattermost-server/v5/plugin"
)

// configuration represents the configuration for this plugin as exposed via the Mattermost
// server configuration.
type configuration struct {
	TeamName	string
	ChannelName	string

	// channelId is resolved when the public configuration fields above change
	channelId	string
}

type HelpPlugin struct {
	plugin.MattermostPlugin

	// configurationLock synchronizes access to the configuration.
	configurationLock	sync.RWMutex

	// configuration is the active plugin configuration. Consult getConfiguration and
	// setConfiguration for usage.
	configuration	*configuration
}

// getConfiguration retrieves the active configuration under lock, making it safe to use
// concurrently. The active configuration may change underneath the client of this method, but
// the struct returned by this API call is considered immutable.
func (p *HelpPlugin) getConfiguration() *configuration {
	p.configurationLock.RLock()
	defer p.configurationLock.RUnlock()

	if p.configuration == nil {
		return &configuration{}
	}

	return p.configuration
}

// setConfiguration replaces the active configuration under lock.
//
// Do not call setConfiguration while holding the configurationLock, as sync.Mutex is not
// reentrant.
func (p *HelpPlugin) setConfiguration(configuration *configuration) {
	// Replace the active configuration under lock.
	p.configurationLock.Lock()
	defer p.configurationLock.Unlock()
	p.configuration = configuration
}

// OnConfigurationChange updates the active configuration for this plugin under lock.
func (p *HelpPlugin) OnConfigurationChange() error {
	var configuration = new(configuration)

	// Load the public configuration fields from the Mattermost server configuration.
	if err := p.API.LoadPluginConfiguration(configuration); err != nil {
		return errors.Wrap(err, "failed to load plugin configuration")
	}

	team, err := p.API.GetTeamByName(configuration.TeamName)
	if err != nil {
		return errors.Wrapf(err, "failed to find team %s", configuration.TeamName)
	}

	channel, err := p.API.GetChannelByName(configuration.ChannelName, team.Id, false)
	if err != nil {
		return errors.Wrapf(err, "failed to find channel %s", configuration.ChannelName)
	}

	configuration.channelId = channel.Id

	p.setConfiguration(configuration)

	return nil
}

func (p *HelpPlugin) MessageHasBeenPosted(c *plugin.Context, post *model.Post) {
	configuration := p.getConfiguration()

	// Ignore posts not in the configured channel
	if post.ChannelId != configuration.channelId {
		return
	}

	// Ignore posts this plugin made.
	if sentByPlugin, _ := post.Props["sent_by_plugin"].(bool); sentByPlugin {
		return
	}

	// Ignore posts without a plea for help.
	if !strings.Contains(post.Message, "help") {
		return
	}

	p.API.SendEphemeralPost(post.UserId, &model.Post{
		ChannelId:	configuration.channelId,
		Message:	"You asked for help? Checkout https://about.mattermost.com/help/",
		Props: map[string]interface{}{
			"sent_by_plugin": true,
		},
	})
}

func main() {
	plugin.ClientMain(&HelpPlugin{})
}