diff options
Diffstat (limited to 'plugin/api.go')
-rw-r--r-- | plugin/api.go | 84 |
1 files changed, 75 insertions, 9 deletions
diff --git a/plugin/api.go b/plugin/api.go index d62c2f069..76df9377a 100644 --- a/plugin/api.go +++ b/plugin/api.go @@ -4,13 +4,15 @@ package plugin import ( + "github.com/hashicorp/go-plugin" "github.com/mattermost/mattermost-server/model" ) // 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 can obtain access to the API by implementing the OnActivate hook. +// Plugins obtain access to the API by embedding MattermostPlugin and accessing the API member +// directly. type API interface { // LoadPluginConfiguration loads the plugin's configuration. dest should be a pointer to a // struct that the configuration JSON can be unmarshalled to. @@ -23,6 +25,12 @@ type API interface { // UnregisterCommand unregisters a command previously registered via RegisterCommand. UnregisterCommand(teamId, trigger string) error + // GetConfig fetches the currently persisted config + GetConfig() *model.Config + + // SaveConfig sets the given config and persists the changes + SaveConfig(config *model.Config) *model.AppError + // CreateUser creates a user. CreateUser(user *model.User) (*model.User, *model.AppError) @@ -47,6 +55,9 @@ type API interface { // DeleteTeam deletes a team. DeleteTeam(teamId string) *model.AppError + // GetTeam gets all teams. + GetTeams() ([]*model.Team, *model.AppError) + // GetTeam gets a team. GetTeam(teamId string) (*model.Team, *model.AppError) @@ -56,12 +67,33 @@ type API interface { // UpdateTeam updates a team. UpdateTeam(team *model.Team) (*model.Team, *model.AppError) + // CreateTeamMember creates a team membership. + CreateTeamMember(teamId, userId string) (*model.TeamMember, *model.AppError) + + // CreateTeamMember creates a team membership for all provided user ids. + CreateTeamMembers(teamId string, userIds []string, requestorId string) ([]*model.TeamMember, *model.AppError) + + // DeleteTeamMember deletes a team membership. + DeleteTeamMember(teamId, userId, requestorId string) *model.AppError + + // GetTeamMembers returns the memberships of a specific team. + GetTeamMembers(teamId string, offset, limit int) ([]*model.TeamMember, *model.AppError) + + // GetTeamMember returns a specific membership. + GetTeamMember(teamId, userId string) (*model.TeamMember, *model.AppError) + + // UpdateTeamMemberRoles updates the role for a team membership. + UpdateTeamMemberRoles(teamId, userId, newRoles string) (*model.TeamMember, *model.AppError) + // CreateChannel creates a channel. CreateChannel(channel *model.Channel) (*model.Channel, *model.AppError) // DeleteChannel deletes a channel. DeleteChannel(channelId string) *model.AppError + // GetChannels gets a list of all channels. + GetPublicChannelsForTeam(teamId string, offset, limit int) (*model.ChannelList, *model.AppError) + // GetChannel gets a channel. GetChannel(channelId string) (*model.Channel, *model.AppError) @@ -95,6 +127,9 @@ type API interface { // CreatePost creates a post. CreatePost(post *model.Post) (*model.Post, *model.AppError) + // SendEphemeralPost creates an ephemeral post. + SendEphemeralPost(userId string, post *model.Post) *model.Post + // DeletePost deletes a post. DeletePost(postId string) *model.AppError @@ -104,17 +139,48 @@ type API interface { // UpdatePost updates a post. UpdatePost(post *model.Post) (*model.Post, *model.AppError) - // KeyValueStore returns an object for accessing the persistent key value storage. - KeyValueStore() KeyValueStore -} - -type KeyValueStore interface { // Set will store a key-value pair, unique per plugin. - Set(key string, value []byte) *model.AppError + KVSet(key string, value []byte) *model.AppError // Get will retrieve a value based on the key. Returns nil for non-existent keys. - Get(key string) ([]byte, *model.AppError) + KVGet(key string) ([]byte, *model.AppError) // Delete will remove a key-value pair. Returns nil for non-existent keys. - Delete(key string) *model.AppError + KVDelete(key string) *model.AppError + + // 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 + PublishWebSocketEvent(event string, payload map[string]interface{}, broadcast *model.WebsocketBroadcast) + + // 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. + // keyValuePairs should be primitive go types or other values that can be encoded by encoding/gob + LogDebug(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. + // keyValuePairs should be primitive go types or other values that can be encoded by encoding/gob + LogInfo(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. + // keyValuePairs should be primitive go types or other values that can be encoded by encoding/gob + LogError(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. + // keyValuePairs should be primitive go types or other values that can be encoded by encoding/gob + LogWarn(msg string, keyValuePairs ...interface{}) +} + +var handshake = plugin.HandshakeConfig{ + ProtocolVersion: 1, + MagicCookieKey: "MATTERMOST_PLUGIN", + MagicCookieValue: "Securely message teams, anywhere.", } |