github.com/turgay/mattermost-server@v5.3.2-0.20181002173352-2945e8a2b0ce+incompatible/plugin/api.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package plugin
     5  
     6  import (
     7  	"github.com/hashicorp/go-plugin"
     8  	"github.com/mattermost/mattermost-server/model"
     9  )
    10  
    11  // The API can be used to retrieve data or perform actions on behalf of the plugin. Most methods
    12  // have direct counterparts in the REST API and very similar behavior.
    13  //
    14  // Plugins obtain access to the API by embedding MattermostPlugin and accessing the API member
    15  // directly.
    16  type API interface {
    17  	// LoadPluginConfiguration loads the plugin's configuration. dest should be a pointer to a
    18  	// struct that the configuration JSON can be unmarshalled to.
    19  	LoadPluginConfiguration(dest interface{}) error
    20  
    21  	// RegisterCommand registers a custom slash command. When the command is triggered, your plugin
    22  	// can fulfill it via the ExecuteCommand hook.
    23  	RegisterCommand(command *model.Command) error
    24  
    25  	// UnregisterCommand unregisters a command previously registered via RegisterCommand.
    26  	UnregisterCommand(teamId, trigger string) error
    27  
    28  	// GetSession returns the session object for the Session ID
    29  	GetSession(sessionId string) (*model.Session, *model.AppError)
    30  
    31  	// GetConfig fetches the currently persisted config
    32  	GetConfig() *model.Config
    33  
    34  	// SaveConfig sets the given config and persists the changes
    35  	SaveConfig(config *model.Config) *model.AppError
    36  
    37  	// GetServerVersion return the current Mattermost server version
    38  	GetServerVersion() string
    39  
    40  	// CreateUser creates a user.
    41  	CreateUser(user *model.User) (*model.User, *model.AppError)
    42  
    43  	// DeleteUser deletes a user.
    44  	DeleteUser(userId string) *model.AppError
    45  
    46  	// GetUser gets a user.
    47  	GetUser(userId string) (*model.User, *model.AppError)
    48  
    49  	// GetUserByEmail gets a user by their email address.
    50  	GetUserByEmail(email string) (*model.User, *model.AppError)
    51  
    52  	// GetUserByUsername gets a user by their username.
    53  	GetUserByUsername(name string) (*model.User, *model.AppError)
    54  
    55  	// UpdateUser updates a user.
    56  	UpdateUser(user *model.User) (*model.User, *model.AppError)
    57  
    58  	// GetUserStatus will get a user's status.
    59  	GetUserStatus(userId string) (*model.Status, *model.AppError)
    60  
    61  	// GetUserStatusesByIds will return a list of user statuses based on the provided slice of user IDs.
    62  	GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.AppError)
    63  
    64  	// UpdateUserStatus will set a user's status until the user, or another integration/plugin, sets it back to online.
    65  	// The status parameter can be: "online", "away", "dnd", or "offline".
    66  	UpdateUserStatus(userId, status string) (*model.Status, *model.AppError)
    67  
    68  	// GetLDAPUserAttributes will return LDAP attributes for a user.
    69  	// The attributes parameter should be a list of attributes to pull.
    70  	// Returns a map with attribute names as keys and the user's attributes as values.
    71  	// Requires an enterprise license, LDAP to be configured and for the user to use LDAP as an authentication method.
    72  	GetLDAPUserAttributes(userId string, attributes []string) (map[string]string, *model.AppError)
    73  
    74  	// CreateTeam creates a team.
    75  	CreateTeam(team *model.Team) (*model.Team, *model.AppError)
    76  
    77  	// DeleteTeam deletes a team.
    78  	DeleteTeam(teamId string) *model.AppError
    79  
    80  	// GetTeam gets all teams.
    81  	GetTeams() ([]*model.Team, *model.AppError)
    82  
    83  	// GetTeam gets a team.
    84  	GetTeam(teamId string) (*model.Team, *model.AppError)
    85  
    86  	// GetTeamByName gets a team by its name.
    87  	GetTeamByName(name string) (*model.Team, *model.AppError)
    88  
    89  	// UpdateTeam updates a team.
    90  	UpdateTeam(team *model.Team) (*model.Team, *model.AppError)
    91  
    92  	// CreateTeamMember creates a team membership.
    93  	CreateTeamMember(teamId, userId string) (*model.TeamMember, *model.AppError)
    94  
    95  	// CreateTeamMember creates a team membership for all provided user ids.
    96  	CreateTeamMembers(teamId string, userIds []string, requestorId string) ([]*model.TeamMember, *model.AppError)
    97  
    98  	// DeleteTeamMember deletes a team membership.
    99  	DeleteTeamMember(teamId, userId, requestorId string) *model.AppError
   100  
   101  	// GetTeamMembers returns the memberships of a specific team.
   102  	GetTeamMembers(teamId string, offset, limit int) ([]*model.TeamMember, *model.AppError)
   103  
   104  	// GetTeamMember returns a specific membership.
   105  	GetTeamMember(teamId, userId string) (*model.TeamMember, *model.AppError)
   106  
   107  	// UpdateTeamMemberRoles updates the role for a team membership.
   108  	UpdateTeamMemberRoles(teamId, userId, newRoles string) (*model.TeamMember, *model.AppError)
   109  
   110  	// CreateChannel creates a channel.
   111  	CreateChannel(channel *model.Channel) (*model.Channel, *model.AppError)
   112  
   113  	// DeleteChannel deletes a channel.
   114  	DeleteChannel(channelId string) *model.AppError
   115  
   116  	// GetPublicChannelsForTeam gets a list of all channels.
   117  	GetPublicChannelsForTeam(teamId string, offset, limit int) (*model.ChannelList, *model.AppError)
   118  
   119  	// GetChannel gets a channel.
   120  	GetChannel(channelId string) (*model.Channel, *model.AppError)
   121  
   122  	// GetChannelByName gets a channel by its name, given a team id.
   123  	GetChannelByName(teamId, name string, includeDeleted bool) (*model.Channel, *model.AppError)
   124  
   125  	// GetChannelByNameForTeamName gets a channel by its name, given a team name.
   126  	GetChannelByNameForTeamName(teamName, channelName string, includeDeleted bool) (*model.Channel, *model.AppError)
   127  
   128  	// GetDirectChannel gets a direct message channel.
   129  	GetDirectChannel(userId1, userId2 string) (*model.Channel, *model.AppError)
   130  
   131  	// GetGroupChannel gets a group message channel.
   132  	GetGroupChannel(userIds []string) (*model.Channel, *model.AppError)
   133  
   134  	// UpdateChannel updates a channel.
   135  	UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError)
   136  
   137  	// AddChannelMember creates a channel membership for a user.
   138  	AddChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError)
   139  
   140  	// GetChannelMember gets a channel membership for a user.
   141  	GetChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError)
   142  
   143  	// UpdateChannelMemberRoles updates a user's roles for a channel.
   144  	UpdateChannelMemberRoles(channelId, userId, newRoles string) (*model.ChannelMember, *model.AppError)
   145  
   146  	// UpdateChannelMemberNotifications updates a user's notification properties for a channel.
   147  	UpdateChannelMemberNotifications(channelId, userId string, notifications map[string]string) (*model.ChannelMember, *model.AppError)
   148  
   149  	// DeleteChannelMember deletes a channel membership for a user.
   150  	DeleteChannelMember(channelId, userId string) *model.AppError
   151  
   152  	// CreatePost creates a post.
   153  	CreatePost(post *model.Post) (*model.Post, *model.AppError)
   154  
   155  	// AddReaction add a reaction to a post.
   156  	AddReaction(reaction *model.Reaction) (*model.Reaction, *model.AppError)
   157  
   158  	// RemoveReaction remove a reaction from a post.
   159  	RemoveReaction(reaction *model.Reaction) *model.AppError
   160  
   161  	// GetReaction get the reactions of a post.
   162  	GetReactions(postId string) ([]*model.Reaction, *model.AppError)
   163  
   164  	// SendEphemeralPost creates an ephemeral post.
   165  	SendEphemeralPost(userId string, post *model.Post) *model.Post
   166  
   167  	// DeletePost deletes a post.
   168  	DeletePost(postId string) *model.AppError
   169  
   170  	// GetPost gets a post.
   171  	GetPost(postId string) (*model.Post, *model.AppError)
   172  
   173  	// UpdatePost updates a post.
   174  	UpdatePost(post *model.Post) (*model.Post, *model.AppError)
   175  
   176  	// CopyFileInfos duplicates the FileInfo objects referenced by the given file ids,
   177  	// recording the given user id as the new creator and returning the new set of file ids.
   178  	//
   179  	// The duplicate FileInfo objects are not initially linked to a post, but may now be passed
   180  	// to CreatePost. Use this API to duplicate a post and its file attachments without
   181  	// actually duplicating the uploaded files.
   182  	CopyFileInfos(userId string, fileIds []string) ([]string, *model.AppError)
   183  
   184  	// GetFileInfo gets a File Info for a specific fileId
   185  	GetFileInfo(fileId string) (*model.FileInfo, *model.AppError)
   186  
   187  	// ReadFileAtPath reads the file from the backend for a specific path
   188  	ReadFile(path string) ([]byte, *model.AppError)
   189  
   190  	// KVSet will store a key-value pair, unique per plugin.
   191  	KVSet(key string, value []byte) *model.AppError
   192  
   193  	// KVGet will retrieve a value based on the key. Returns nil for non-existent keys.
   194  	KVGet(key string) ([]byte, *model.AppError)
   195  
   196  	// KVDelete will remove a key-value pair. Returns nil for non-existent keys.
   197  	KVDelete(key string) *model.AppError
   198  
   199  	// PublishWebSocketEvent sends an event to WebSocket connections.
   200  	// event is the type and will be prepended with "custom_<pluginid>_"
   201  	// payload is the data sent with the event. Interface values must be primitive Go types or mattermost-server/model types
   202  	// broadcast determines to which users to send the event
   203  	PublishWebSocketEvent(event string, payload map[string]interface{}, broadcast *model.WebsocketBroadcast)
   204  
   205  	// HasPermissionTo check if the user has the permission at system scope.
   206  	HasPermissionTo(userId string, permission *model.Permission) bool
   207  
   208  	// HasPermissionToTeam check if the user has the permission at team scope.
   209  	HasPermissionToTeam(userId, teamId string, permission *model.Permission) bool
   210  
   211  	// HasPermissionToChannel check if the user has the permission at channel scope.
   212  	HasPermissionToChannel(userId, channelId string, permission *model.Permission) bool
   213  
   214  	// LogDebug writes a log message to the Mattermost server log file.
   215  	// Appropriate context such as the plugin name will already be added as fields so plugins
   216  	// do not need to add that info.
   217  	// keyValuePairs should be primitive go types or other values that can be encoded by encoding/gob
   218  	LogDebug(msg string, keyValuePairs ...interface{})
   219  
   220  	// LogInfo writes a log message to the Mattermost server log file.
   221  	// Appropriate context such as the plugin name will already be added as fields so plugins
   222  	// do not need to add that info.
   223  	// keyValuePairs should be primitive go types or other values that can be encoded by encoding/gob
   224  	LogInfo(msg string, keyValuePairs ...interface{})
   225  
   226  	// LogError writes a log message to the Mattermost server log file.
   227  	// Appropriate context such as the plugin name will already be added as fields so plugins
   228  	// do not need to add that info.
   229  	// keyValuePairs should be primitive go types or other values that can be encoded by encoding/gob
   230  	LogError(msg string, keyValuePairs ...interface{})
   231  
   232  	// LogWarn writes a log message to the Mattermost server log file.
   233  	// Appropriate context such as the plugin name will already be added as fields so plugins
   234  	// do not need to add that info.
   235  	// keyValuePairs should be primitive go types or other values that can be encoded by encoding/gob
   236  	LogWarn(msg string, keyValuePairs ...interface{})
   237  }
   238  
   239  var handshake = plugin.HandshakeConfig{
   240  	ProtocolVersion:  1,
   241  	MagicCookieKey:   "MATTERMOST_PLUGIN",
   242  	MagicCookieValue: "Securely message teams, anywhere.",
   243  }