mattermost/server/public/pluginapi/slashcommand.go

101 lines
3.6 KiB
Go
Raw Permalink Normal View History

[MM-53968] Includes mattermost-plugin-api into the mono repo (#24235) Include https://github.com/mattermost/mattermost-plugin-api into the mono repo Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com> Co-authored-by: Michael Kochell <mjkochell@gmail.com> Co-authored-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com> Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com> Co-authored-by: Alex Dovenmuehle <alex.dovenmuehle@mattermost.com> Co-authored-by: Michael Kochell <6913320+mickmister@users.noreply.github.com> Co-authored-by: Christopher Poile <cpoile@gmail.com> Co-authored-by: İlker Göktuğ Öztürk <ilkergoktugozturk@gmail.com> Co-authored-by: Shota Gvinepadze <wineson@gmail.com> Co-authored-by: Ali Farooq <ali.farooq0@pm.me> Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com> Co-authored-by: Daniel Espino García <larkox@gmail.com> Co-authored-by: Christopher Speller <crspeller@gmail.com> Co-authored-by: Alex Dovenmuehle <adovenmuehle@gmail.com> Co-authored-by: Szymon Gibała <szymongib@gmail.com> Co-authored-by: Lev <1187448+levb@users.noreply.github.com> Co-authored-by: Jason Frerich <jason.frerich@mattermost.com> Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in> Co-authored-by: Artur M. Wolff <artur.m.wolff@gmail.com> Co-authored-by: Madhav Hugar <16546715+madhavhugar@users.noreply.github.com> Co-authored-by: Joe <security.joe@pm.me> Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> Co-authored-by: José Peso <trilopin@users.noreply.github.com>
2023-08-21 03:50:30 -04:00
package pluginapi
import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/plugin"
)
// SlashCommandService exposes methods to manipulate slash commands.
type SlashCommandService struct {
api plugin.API
}
// 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 (c *SlashCommandService) Register(command *model.Command) error {
return c.api.RegisterCommand(command)
}
// Unregister unregisters a command previously registered via Register.
//
// Minimum server version: 5.2
func (c *SlashCommandService) Unregister(teamID, trigger string) error {
return c.api.UnregisterCommand(teamID, trigger)
}
// Execute executes a slash command.
//
// Minimum server version: 5.26
func (c *SlashCommandService) Execute(command *model.CommandArgs) (*model.CommandResponse, error) {
return c.api.ExecuteSlashCommand(command)
}
// 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 (c *SlashCommandService) Create(command *model.Command) (*model.Command, error) {
return c.api.CreateCommand(command)
}
// 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 (c *SlashCommandService) List(teamID string) ([]*model.Command, error) {
return c.api.ListCommands(teamID)
}
// 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 (c *SlashCommandService) ListCustom(teamID string) ([]*model.Command, error) {
return c.api.ListCustomCommands(teamID)
}
// ListPlugin returns the list of slash commands for teamID that were created
// with the plugin api RegisterCommand.
//
// Minimum server version: 5.28
func (c *SlashCommandService) ListPlugin(teamID string) ([]*model.Command, error) {
return c.api.ListPluginCommands(teamID)
}
// ListBuiltIn returns the list of slash commands that are builtin commands
// (those added internally through RegisterCommandProvider).
//
// Minimum server version: 5.28
func (c *SlashCommandService) ListBuiltIn() ([]*model.Command, error) {
return c.api.ListBuiltInCommands()
}
// Get returns the command definition based on a command id string.
//
// Minimum server version: 5.28
func (c *SlashCommandService) Get(commandID string) (*model.Command, error) {
return c.api.GetCommand(commandID)
}
// 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
func (c *SlashCommandService) Update(commandID string, updatedCmd *model.Command) (*model.Command, error) {
return c.api.UpdateCommand(commandID, updatedCmd)
}
// Delete deletes a slash command (identified by commandID).
//
// Minimum server version: 5.28
func (c *SlashCommandService) Delete(commandID string) error {
return c.api.DeleteCommand(commandID)
}