github.com/trigonella/mattermost-server@v5.11.1+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 plugin "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 // GetPluginConfig fetches the currently persisted config of plugin 38 // 39 // Minimum server version: 5.6 40 GetPluginConfig() map[string]interface{} 41 42 // SavePluginConfig sets the given config for plugin and persists the changes 43 // 44 // Minimum server version: 5.6 45 SavePluginConfig(config map[string]interface{}) *model.AppError 46 47 // GetBundlePath returns the absolute path where the plugin's bundle was unpacked. 48 // 49 // Minimum server version: 5.10 50 GetBundlePath() (string, error) 51 52 // GetLicense returns the current license used by the Mattermost server. Returns nil if the 53 // the server does not have a license. 54 // 55 // Minimum server version: 5.10 56 GetLicense() *model.License 57 58 // GetServerVersion return the current Mattermost server version 59 // 60 // Minimum server version: 5.4 61 GetServerVersion() string 62 63 // GetSystemInstallDate returns the time that Mattermost was first installed and ran. 64 // 65 // Minimum server version: 5.10 66 GetSystemInstallDate() (int64, *model.AppError) 67 68 // GetDiagnosticId returns a unique identifier used by the server for diagnostic reports. 69 // 70 // Minimum server version: 5.10 71 GetDiagnosticId() string 72 73 // CreateUser creates a user. 74 CreateUser(user *model.User) (*model.User, *model.AppError) 75 76 // DeleteUser deletes a user. 77 DeleteUser(userId string) *model.AppError 78 79 // GetUsers a list of users based on search options. 80 // 81 // Minimum server version: 5.10 82 GetUsers(options *model.UserGetOptions) ([]*model.User, *model.AppError) 83 84 // GetUser gets a user. 85 GetUser(userId string) (*model.User, *model.AppError) 86 87 // GetUserByEmail gets a user by their email address. 88 GetUserByEmail(email string) (*model.User, *model.AppError) 89 90 // GetUserByUsername gets a user by their username. 91 GetUserByUsername(name string) (*model.User, *model.AppError) 92 93 // GetUsersByUsernames gets users by their usernames. 94 // 95 // Minimum server version: 5.6 96 GetUsersByUsernames(usernames []string) ([]*model.User, *model.AppError) 97 98 // GetUsersInTeam gets users in team. 99 // 100 // Minimum server version: 5.6 101 GetUsersInTeam(teamId string, page int, perPage int) ([]*model.User, *model.AppError) 102 103 // GetTeamIcon gets the team icon. 104 // 105 // Minimum server version: 5.6 106 GetTeamIcon(teamId string) ([]byte, *model.AppError) 107 108 // SetTeamIcon sets the team icon. 109 // 110 // Minimum server version: 5.6 111 SetTeamIcon(teamId string, data []byte) *model.AppError 112 113 // RemoveTeamIcon removes the team icon. 114 // 115 // Minimum server version: 5.6 116 RemoveTeamIcon(teamId string) *model.AppError 117 118 // UpdateUser updates a user. 119 UpdateUser(user *model.User) (*model.User, *model.AppError) 120 121 // GetUserStatus will get a user's status. 122 GetUserStatus(userId string) (*model.Status, *model.AppError) 123 124 // GetUserStatusesByIds will return a list of user statuses based on the provided slice of user IDs. 125 GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.AppError) 126 127 // UpdateUserStatus will set a user's status until the user, or another integration/plugin, sets it back to online. 128 // The status parameter can be: "online", "away", "dnd", or "offline". 129 UpdateUserStatus(userId, status string) (*model.Status, *model.AppError) 130 131 // UpdateUserActive deactivates or reactivates an user. 132 // 133 // Minimum server version: 5.8 134 UpdateUserActive(userId string, active bool) *model.AppError 135 136 // GetUsersInChannel returns a page of users in a channel. Page counting starts at 0. 137 // The sortBy parameter can be: "username" or "status". 138 // 139 // Minimum server version: 5.6 140 GetUsersInChannel(channelId, sortBy string, page, perPage int) ([]*model.User, *model.AppError) 141 142 // GetLDAPUserAttributes will return LDAP attributes for a user. 143 // The attributes parameter should be a list of attributes to pull. 144 // Returns a map with attribute names as keys and the user's attributes as values. 145 // Requires an enterprise license, LDAP to be configured and for the user to use LDAP as an authentication method. 146 // 147 // Minimum server version: 5.3 148 GetLDAPUserAttributes(userId string, attributes []string) (map[string]string, *model.AppError) 149 150 // CreateTeam creates a team. 151 CreateTeam(team *model.Team) (*model.Team, *model.AppError) 152 153 // DeleteTeam deletes a team. 154 DeleteTeam(teamId string) *model.AppError 155 156 // GetTeam gets all teams. 157 GetTeams() ([]*model.Team, *model.AppError) 158 159 // GetTeam gets a team. 160 GetTeam(teamId string) (*model.Team, *model.AppError) 161 162 // GetTeamByName gets a team by its name. 163 GetTeamByName(name string) (*model.Team, *model.AppError) 164 165 // GetTeamsUnreadForUser gets the unread message and mention counts for each team to which the given user belongs. 166 // 167 // Minimum server version: 5.6 168 GetTeamsUnreadForUser(userId string) ([]*model.TeamUnread, *model.AppError) 169 170 // UpdateTeam updates a team. 171 UpdateTeam(team *model.Team) (*model.Team, *model.AppError) 172 173 // SearchTeams search a team. 174 // 175 // Minimum server version: 5.8 176 SearchTeams(term string) ([]*model.Team, *model.AppError) 177 178 // GetTeamsForUser returns list of teams of given user ID. 179 // 180 // Minimum server version: 5.6 181 GetTeamsForUser(userId string) ([]*model.Team, *model.AppError) 182 183 // CreateTeamMember creates a team membership. 184 CreateTeamMember(teamId, userId string) (*model.TeamMember, *model.AppError) 185 186 // CreateTeamMember creates a team membership for all provided user ids. 187 CreateTeamMembers(teamId string, userIds []string, requestorId string) ([]*model.TeamMember, *model.AppError) 188 189 // DeleteTeamMember deletes a team membership. 190 DeleteTeamMember(teamId, userId, requestorId string) *model.AppError 191 192 // GetTeamMembers returns the memberships of a specific team. 193 GetTeamMembers(teamId string, page, perPage int) ([]*model.TeamMember, *model.AppError) 194 195 // GetTeamMember returns a specific membership. 196 GetTeamMember(teamId, userId string) (*model.TeamMember, *model.AppError) 197 198 // GetTeamMembersForUser returns all team memberships for a user. 199 // 200 // Minimum server version: 5.10 201 GetTeamMembersForUser(userId string, page int, perPage int) ([]*model.TeamMember, *model.AppError) 202 203 // UpdateTeamMemberRoles updates the role for a team membership. 204 UpdateTeamMemberRoles(teamId, userId, newRoles string) (*model.TeamMember, *model.AppError) 205 206 // CreateChannel creates a channel. 207 CreateChannel(channel *model.Channel) (*model.Channel, *model.AppError) 208 209 // DeleteChannel deletes a channel. 210 DeleteChannel(channelId string) *model.AppError 211 212 // GetPublicChannelsForTeam gets a list of all channels. 213 GetPublicChannelsForTeam(teamId string, page, perPage int) ([]*model.Channel, *model.AppError) 214 215 // GetChannel gets a channel. 216 GetChannel(channelId string) (*model.Channel, *model.AppError) 217 218 // GetChannelByName gets a channel by its name, given a team id. 219 GetChannelByName(teamId, name string, includeDeleted bool) (*model.Channel, *model.AppError) 220 221 // GetChannelByNameForTeamName gets a channel by its name, given a team name. 222 GetChannelByNameForTeamName(teamName, channelName string, includeDeleted bool) (*model.Channel, *model.AppError) 223 224 // GetChannelsForTeamForUser gets a list of channels for given user ID in given team ID. 225 // 226 // Minimum server version: 5.6 227 GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) ([]*model.Channel, *model.AppError) 228 229 // GetChannelStats gets statistics for a channel. 230 // 231 // Minimum server version: 5.6 232 GetChannelStats(channelId string) (*model.ChannelStats, *model.AppError) 233 234 // GetDirectChannel gets a direct message channel. 235 // If the channel does not exist it will create it. 236 GetDirectChannel(userId1, userId2 string) (*model.Channel, *model.AppError) 237 238 // GetGroupChannel gets a group message channel. 239 // If the channel does not exist it will create it. 240 GetGroupChannel(userIds []string) (*model.Channel, *model.AppError) 241 242 // UpdateChannel updates a channel. 243 UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError) 244 245 // SearchChannels returns the channels on a team matching the provided search term. 246 // 247 // Minimum server version: 5.6 248 SearchChannels(teamId string, term string) ([]*model.Channel, *model.AppError) 249 250 // SearchUsers returns a list of users based on some search criteria. 251 // 252 // Minimum server version: 5.6 253 SearchUsers(search *model.UserSearch) ([]*model.User, *model.AppError) 254 255 // SearchPostsInTeam returns a list of posts in a specific team that match the given params. 256 // 257 // Minimum server version: 5.10 258 SearchPostsInTeam(teamId string, paramsList []*model.SearchParams) ([]*model.Post, *model.AppError) 259 260 // AddChannelMember creates a channel membership for a user. 261 AddChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError) 262 263 // GetChannelMember gets a channel membership for a user. 264 GetChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError) 265 266 // GetChannelMembers gets a channel membership for all users. 267 // 268 // Minimum server version: 5.6 269 GetChannelMembers(channelId string, page, perPage int) (*model.ChannelMembers, *model.AppError) 270 271 // GetChannelMembersByIds gets a channel membership for a particular User 272 // 273 // Minimum server version: 5.6 274 GetChannelMembersByIds(channelId string, userIds []string) (*model.ChannelMembers, *model.AppError) 275 276 // GetChannelMembersForUser returns all channel memberships on a team for a user. 277 // 278 // Minimum server version: 5.10 279 GetChannelMembersForUser(teamId, userId string, page, perPage int) ([]*model.ChannelMember, *model.AppError) 280 281 // UpdateChannelMemberRoles updates a user's roles for a channel. 282 UpdateChannelMemberRoles(channelId, userId, newRoles string) (*model.ChannelMember, *model.AppError) 283 284 // UpdateChannelMemberNotifications updates a user's notification properties for a channel. 285 UpdateChannelMemberNotifications(channelId, userId string, notifications map[string]string) (*model.ChannelMember, *model.AppError) 286 287 // DeleteChannelMember deletes a channel membership for a user. 288 DeleteChannelMember(channelId, userId string) *model.AppError 289 290 // CreatePost creates a post. 291 CreatePost(post *model.Post) (*model.Post, *model.AppError) 292 293 // AddReaction add a reaction to a post. 294 // 295 // Minimum server version: 5.3 296 AddReaction(reaction *model.Reaction) (*model.Reaction, *model.AppError) 297 298 // RemoveReaction remove a reaction from a post. 299 // 300 // Minimum server version: 5.3 301 RemoveReaction(reaction *model.Reaction) *model.AppError 302 303 // GetReaction get the reactions of a post. 304 // 305 // Minimum server version: 5.3 306 GetReactions(postId string) ([]*model.Reaction, *model.AppError) 307 308 // SendEphemeralPost creates an ephemeral post. 309 SendEphemeralPost(userId string, post *model.Post) *model.Post 310 311 // UpdateEphemeralPost updates an ephemeral message previously sent to the user. 312 // EXPERIMENTAL: This API is experimental and can be changed without advance notice. 313 UpdateEphemeralPost(userId string, post *model.Post) *model.Post 314 315 // DeleteEphemeralPost deletes an ephemeral message previously sent to the user. 316 // EXPERIMENTAL: This API is experimental and can be changed without advance notice. 317 DeleteEphemeralPost(userId string, post *model.Post) 318 319 // DeletePost deletes a post. 320 DeletePost(postId string) *model.AppError 321 322 // GetPostThread gets a post with all the other posts in the same thread. 323 // 324 // Minimum server version: 5.6 325 GetPostThread(postId string) (*model.PostList, *model.AppError) 326 327 // GetPost gets a post. 328 GetPost(postId string) (*model.Post, *model.AppError) 329 330 // GetPostsSince gets posts created after a specified time as Unix time in milliseconds. 331 // 332 // Minimum server version: 5.6 333 GetPostsSince(channelId string, time int64) (*model.PostList, *model.AppError) 334 335 // GetPostsAfter gets a page of posts that were posted after the post provided. 336 // 337 // Minimum server version: 5.6 338 GetPostsAfter(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError) 339 340 // GetPostsBefore gets a page of posts that were posted before the post provided. 341 // 342 // Minimum server version: 5.6 343 GetPostsBefore(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError) 344 345 // GetPostsForChannel gets a list of posts for a channel. 346 // 347 // Minimum server version: 5.6 348 GetPostsForChannel(channelId string, page, perPage int) (*model.PostList, *model.AppError) 349 350 // GetTeamStats gets a team's statistics 351 // 352 // Minimum server version: 5.8 353 GetTeamStats(teamId string) (*model.TeamStats, *model.AppError) 354 355 // UpdatePost updates a post. 356 UpdatePost(post *model.Post) (*model.Post, *model.AppError) 357 358 // GetProfileImage gets user's profile image. 359 // 360 // Minimum server version: 5.6 361 GetProfileImage(userId string) ([]byte, *model.AppError) 362 363 // SetProfileImage sets a user's profile image. 364 // 365 // Minimum server version: 5.6 366 SetProfileImage(userId string, data []byte) *model.AppError 367 368 // GetEmojiList returns a page of custom emoji on the system. 369 // 370 // The sortBy parameter can be: "name". 371 // 372 // Minimum server version: 5.6 373 GetEmojiList(sortBy string, page, perPage int) ([]*model.Emoji, *model.AppError) 374 375 // GetEmojiByName gets an emoji by it's name. 376 // 377 // Minimum server version: 5.6 378 GetEmojiByName(name string) (*model.Emoji, *model.AppError) 379 380 // GetEmoji returns a custom emoji based on the emojiId string. 381 // 382 // Minimum server version: 5.6 383 GetEmoji(emojiId string) (*model.Emoji, *model.AppError) 384 385 // CopyFileInfos duplicates the FileInfo objects referenced by the given file ids, 386 // recording the given user id as the new creator and returning the new set of file ids. 387 // 388 // The duplicate FileInfo objects are not initially linked to a post, but may now be passed 389 // to CreatePost. Use this API to duplicate a post and its file attachments without 390 // actually duplicating the uploaded files. 391 CopyFileInfos(userId string, fileIds []string) ([]string, *model.AppError) 392 393 // GetFileInfo gets a File Info for a specific fileId 394 // 395 // Minimum server version: 5.3 396 GetFileInfo(fileId string) (*model.FileInfo, *model.AppError) 397 398 // GetFile gets content of a file by it's ID 399 // 400 // Minimum Server version: 5.8 401 GetFile(fileId string) ([]byte, *model.AppError) 402 403 // GetFileLink gets the public link to a file by fileId. 404 // 405 // Minimum server version: 5.6 406 GetFileLink(fileId string) (string, *model.AppError) 407 408 // ReadFileAtPath reads the file from the backend for a specific path 409 // 410 // Minimum server version: 5.3 411 ReadFile(path string) ([]byte, *model.AppError) 412 413 // GetEmojiImage returns the emoji image. 414 // 415 // Minimum server version: 5.6 416 GetEmojiImage(emojiId string) ([]byte, string, *model.AppError) 417 418 // UploadFile will upload a file to a channel using a multipart request, to be later attached to a post. 419 // 420 // Minimum server version: 5.6 421 UploadFile(data []byte, channelId string, filename string) (*model.FileInfo, *model.AppError) 422 423 // OpenInteractiveDialog will open an interactive dialog on a user's client that 424 // generated the trigger ID. Used with interactive message buttons, menus 425 // and slash commands. 426 // 427 // Minimum server version: 5.6 428 OpenInteractiveDialog(dialog model.OpenDialogRequest) *model.AppError 429 430 // Plugin Section 431 432 // GetPlugins will return a list of plugin manifests for currently active plugins. 433 // 434 // Minimum server version: 5.6 435 GetPlugins() ([]*model.Manifest, *model.AppError) 436 437 // EnablePlugin will enable an plugin installed. 438 // 439 // Minimum server version: 5.6 440 EnablePlugin(id string) *model.AppError 441 442 // DisablePlugin will disable an enabled plugin. 443 // 444 // Minimum server version: 5.6 445 DisablePlugin(id string) *model.AppError 446 447 // RemovePlugin will disable and delete a plugin. 448 // 449 // Minimum server version: 5.6 450 RemovePlugin(id string) *model.AppError 451 452 // GetPluginStatus will return the status of a plugin. 453 // 454 // Minimum server version: 5.6 455 GetPluginStatus(id string) (*model.PluginStatus, *model.AppError) 456 457 // KV Store Section 458 459 // KVSet will store a key-value pair, unique per plugin. 460 KVSet(key string, value []byte) *model.AppError 461 462 // KVSet will store a key-value pair, unique per plugin with an expiry time 463 // 464 // Minimum server version: 5.6 465 KVSetWithExpiry(key string, value []byte, expireInSeconds int64) *model.AppError 466 467 // KVGet will retrieve a value based on the key. Returns nil for non-existent keys. 468 KVGet(key string) ([]byte, *model.AppError) 469 470 // KVDelete will remove a key-value pair. Returns nil for non-existent keys. 471 KVDelete(key string) *model.AppError 472 473 // KVDeleteAll will remove all key-value pairs for a plugin. 474 // 475 // Minimum server version: 5.6 476 KVDeleteAll() *model.AppError 477 478 // KVList will list all keys for a plugin. 479 // 480 // Minimum server version: 5.6 481 KVList(page, perPage int) ([]string, *model.AppError) 482 483 // PublishWebSocketEvent sends an event to WebSocket connections. 484 // event is the type and will be prepended with "custom_<pluginid>_". 485 // payload is the data sent with the event. Interface values must be primitive Go types or mattermost-server/model types. 486 // broadcast determines to which users to send the event. 487 PublishWebSocketEvent(event string, payload map[string]interface{}, broadcast *model.WebsocketBroadcast) 488 489 // HasPermissionTo check if the user has the permission at system scope. 490 // 491 // Minimum server version: 5.3 492 HasPermissionTo(userId string, permission *model.Permission) bool 493 494 // HasPermissionToTeam check if the user has the permission at team scope. 495 // 496 // Minimum server version: 5.3 497 HasPermissionToTeam(userId, teamId string, permission *model.Permission) bool 498 499 // HasPermissionToChannel check if the user has the permission at channel scope. 500 // 501 // Minimum server version: 5.3 502 HasPermissionToChannel(userId, channelId string, permission *model.Permission) bool 503 504 // LogDebug writes a log message to the Mattermost server log file. 505 // Appropriate context such as the plugin name will already be added as fields so plugins 506 // do not need to add that info. 507 // keyValuePairs should be primitive go types or other values that can be encoded by encoding/gob 508 LogDebug(msg string, keyValuePairs ...interface{}) 509 510 // LogInfo writes a log message to the Mattermost server log file. 511 // Appropriate context such as the plugin name will already be added as fields so plugins 512 // do not need to add that info. 513 // keyValuePairs should be primitive go types or other values that can be encoded by encoding/gob 514 LogInfo(msg string, keyValuePairs ...interface{}) 515 516 // LogError writes a log message to the Mattermost server log file. 517 // Appropriate context such as the plugin name will already be added as fields so plugins 518 // do not need to add that info. 519 // keyValuePairs should be primitive go types or other values that can be encoded by encoding/gob 520 LogError(msg string, keyValuePairs ...interface{}) 521 522 // LogWarn writes a log message to the Mattermost server log file. 523 // Appropriate context such as the plugin name will already be added as fields so plugins 524 // do not need to add that info. 525 // keyValuePairs should be primitive go types or other values that can be encoded by encoding/gob 526 LogWarn(msg string, keyValuePairs ...interface{}) 527 528 // SendMail sends an email to a specific address 529 // 530 // Minimum server version: 5.7 531 SendMail(to, subject, htmlBody string) *model.AppError 532 533 // CreateBot creates the given bot and corresponding user. 534 // 535 // Minimum server version: 5.10 536 CreateBot(bot *model.Bot) (*model.Bot, *model.AppError) 537 538 // PatchBot applies the given patch to the bot and corresponding user. 539 // 540 // Minimum server version: 5.10 541 PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot, *model.AppError) 542 543 // GetBot returns the given bot. 544 // 545 // Minimum server version: 5.10 546 GetBot(botUserId string, includeDeleted bool) (*model.Bot, *model.AppError) 547 548 // GetBots returns the requested page of bots. 549 // 550 // Minimum server version: 5.10 551 GetBots(options *model.BotGetOptions) ([]*model.Bot, *model.AppError) 552 553 // UpdateBotActive marks a bot as active or inactive, along with its corresponding user. 554 // 555 // Minimum server version: 5.10 556 UpdateBotActive(botUserId string, active bool) (*model.Bot, *model.AppError) 557 558 // PermanentDeleteBot permanently deletes a bot and its corresponding user. 559 // 560 // Minimum server version: 5.10 561 PermanentDeleteBot(botUserId string) *model.AppError 562 } 563 564 var handshake = plugin.HandshakeConfig{ 565 ProtocolVersion: 1, 566 MagicCookieKey: "MATTERMOST_PLUGIN", 567 MagicCookieValue: "Securely message teams, anywhere.", 568 }