diff --git a/app/slashcommands/command_templates.go b/app/slashcommands/command_templates.go new file mode 100644 index 0000000000..6f758b79c9 --- /dev/null +++ b/app/slashcommands/command_templates.go @@ -0,0 +1,53 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +package slashcommands + +import ( + "github.com/mattermost/mattermost-server/v6/app" + "github.com/mattermost/mattermost-server/v6/app/request" + "github.com/mattermost/mattermost-server/v6/model" + "github.com/mattermost/mattermost-server/v6/shared/i18n" +) + +type TemplatesProvider struct { +} + +const ( + CmdTemplates = "templates" +) + +func init() { + app.RegisterCommandProvider(&TemplatesProvider{}) +} + +func (h *TemplatesProvider) GetTrigger() string { + return CmdTemplates +} + +func (h *TemplatesProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command { + workTemplateEnabled := a.Config().FeatureFlags.WorkTemplate + pbActive, err := a.IsPluginActive(model.PluginIdPlaybooks) + if err != nil { + pbActive = false + } + hasBoard, err := a.HasBoardProduct() + if err != nil { + hasBoard = false + } + + return &model.Command{ + Trigger: CmdTemplates, + AutoComplete: hasBoard && pbActive && workTemplateEnabled, + AutoCompleteDesc: T("api.command_templates.desc"), + DisplayName: T("api.command_templates.name"), + } +} + +func (h *TemplatesProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse { + // This command is handled client-side and shouldn't hit the server. + return &model.CommandResponse{ + Text: args.T("api.command_templates.unsupported.app_error"), + ResponseType: model.CommandResponseTypeEphemeral, + } +} diff --git a/i18n/en.json b/i18n/en.json index 818abc312d..d73c2a0a12 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -1494,6 +1494,18 @@ "id": "api.command_shrug.name", "translation": "shrug" }, + { + "id": "api.command_templates.desc", + "translation": "Open the create from template window" + }, + { + "id": "api.command_templates.name", + "translation": "templates" + }, + { + "id": "api.command_templates.unsupported.app_error", + "translation": "The templates command is not supported on your device." + }, { "id": "api.config.client.old_format.app_error", "translation": "New format for the client configuration is not supported yet. Please specify format=old in the query string."