pluginapi

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 24 Imported by: 20

Documentation

Overview

Example
package main

import (
	"github.com/mattermost/mattermost/server/public/pluginapi"

	"github.com/mattermost/mattermost/server/public/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

func IsCloud(license *model.License) bool

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

func IsConfiguredForDevelopment

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

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

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

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

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

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

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

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

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

ClusterService exposes methods to interact with cluster nodes.

func (*ClusterService) PublishPluginEvent

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) 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(cfg *model.Config) error

SaveConfig sets the given config and persists the changes

Minimum server version: 5.2

func (*ConfigurationService) SavePluginConfig

func (c *ConfigurationService) SavePluginConfig(cfg 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

type EnsureBotOption func(*ensureBotOptions)

func ProfileImageBytes added in v0.0.18

func ProfileImageBytes(bytes []byte) EnsureBotOption

ProfileImageBytes configures EnsureBot to set a profile image from the given bytes.

Using this option overrides any previously set ProfileImagePath option.

func ProfileImagePath

func ProfileImagePath(path string) EnsureBotOption

ProfileImagePath configures EnsureBot to set a profile image from the given path.

Using this option overrides any previously set ProfileImageBytes option.

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) SetSearchableContent added in v0.0.9

func (f *FileService) SetSearchableContent(id string, content string) error

SetSearchableContent update the File Info searchable text for full text search

Minimum server version: 9.1

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

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

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) 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 internal use 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

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

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
}

type ListKeysOption

type ListKeysOption func(*listKeysOptions)

ListKeysOption used to configure a ListKeys() operation.

func WithChecker

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

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 MemoryStore added in v0.0.15

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

MemoryStore is an implementation of the plugin KV store API for testing. It's not meant for production use. It's safe for concurrent use by multiple goroutines.

func (*MemoryStore) Delete added in v0.0.15

func (s *MemoryStore) Delete(key string) error

func (*MemoryStore) DeleteAll added in v0.0.15

func (s *MemoryStore) DeleteAll() error

DeleteAll removes all key-value pairs.

func (*MemoryStore) Get added in v0.0.15

func (s *MemoryStore) Get(key string, o any) error

func (*MemoryStore) ListKeys added in v0.0.15

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

func (*MemoryStore) Set added in v0.0.15

func (s *MemoryStore) Set(key string, value any, options ...KVSetOption) (bool, error)

Set stores a key-value pair, unique per plugin. Keys prefixed with `mmi_` are reserved for internal use 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

func (*MemoryStore) SetAtomicWithRetries added in v0.0.15

func (s *MemoryStore) SetAtomicWithRetries(key string, valueFunc func(oldValue []byte) (newValue any, err error)) error

type OAuthService

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

UserService exposes methods to manipulate OAuth Apps.

func (*OAuthService) Create

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

Create creates a new OAuth App.

Minimum server version: 5.38

func (*OAuthService) Delete

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

Delete deletes an existing OAuth App by id.

Minimum server version: 5.38

func (*OAuthService) Get

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

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

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

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

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

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

Create creates a new user session.

Minimum server version: 6.2

func (*SessionService) ExtendExpiry

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

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

RevokeSession revokes an existing user session.

Minimum server version: 6.2

type ShouldProcessMessageOption

type ShouldProcessMessageOption func(*shouldProcessMessageOptions)

func AllowBots

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

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

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

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

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

func FilterChannelIDs

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

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

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

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

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

Delete deletes a slash command (identified by commandID).

Minimum server version: 5.28

func (*SlashCommandService) Execute

Execute executes a slash command.

Minimum server version: 5.26

func (*SlashCommandService) Get

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

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

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

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

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

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

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

StoreService exposes the underlying database.

func (*StoreService) Close

func (s *StoreService) Close() error

Close closes any open resources. This method is idempotent.

func (*StoreService) DriverName

func (s *StoreService) DriverName() string

DriverName returns the driver name for the datasource.

func (*StoreService) GetMasterDB

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

GetMasterDB gets the master database handle.

Minimum server version: 5.16

func (*StoreService) GetReplicaDB

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

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

GetManifest returns the manifest from the plugin bundle.

Minimum server version: 5.10

func (*SystemService) GetPluginAssetURL

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

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

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

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

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

RevokeAccessToken revokes an existing access token.

Minimum server version: 5.38

func (*UserService) RolesGrantPermission

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) UpdateRoles added in v0.0.18

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

UpdateRoles updates the roles for a user.

Minimum server version: 9.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