diff --git a/server/command/command.go b/server/command/command.go index 24364d2..a6d2ba0 100644 --- a/server/command/command.go +++ b/server/command/command.go @@ -22,6 +22,11 @@ const ( specifyAlias = "Please specify alias." subscriptionDeleteSuccess = "Subscription with alias **%s** deleted successfully." noChannelSubscription = "No subscription found for this channel." + helpText = "###### Mattermost Confluence Plugin - Slash Command Help\n" + + "\n* `/confluence subscribe` - Subscribe the current channel to receive notifications from Confluence.\n" + + "* `/confluence unsubscribe \"\"` - Unsubscribe notifications for the current channel for a given subscription alias.\n" + + "* `/confluence list` - List all subscriptions configured for the current channel.\n" + + "* `/confluence edit \"\"` - Edit the subscribed events for the given subscription alias for the current channel.\n" ) var ConfluenceCommandHandler = Handler{ @@ -29,6 +34,7 @@ var ConfluenceCommandHandler = Handler{ "list": listChannelSubscription, "unsubscribe": deleteSubscription, "edit": editSubscription, + "help": confluenceHelp, }, defaultHandler: executeConfluenceDefault, } @@ -39,16 +45,15 @@ func GetCommand() *model.Command { DisplayName: "Confluence", Description: "Integration with Confluence.", AutoComplete: true, - AutoCompleteDesc: "Available commands: subscribe, list, unsubscribe \"\"", + AutoCompleteDesc: "Available commands: subscribe, list, unsubscribe \"\", edit \"\", help.", AutoCompleteHint: "[command]", } } -// TODO : Show help text instead of invalid command. func executeConfluenceDefault(context *model.CommandArgs, args ...string) *model.CommandResponse { return &model.CommandResponse{ ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, - Text: "Invalid command", + Text: "Invalid command parameters. Please use `/confluence help` for more information.", } } @@ -62,6 +67,9 @@ func postCommandResponse(context *model.CommandArgs, text string) { } func (ch Handler) Handle(context *model.CommandArgs, args ...string) *model.CommandResponse { + if len(args) == 0 { + return ch.handlers["help"](context, "") + } for n := len(args); n > 0; n-- { h := ch.handlers[strings.Join(args[:n], "/")] if h != nil { @@ -112,3 +120,8 @@ func editSubscription(context *model.CommandArgs, args ...string) *model.Command } return &model.CommandResponse{} } + +func confluenceHelp(context *model.CommandArgs, args ...string) *model.CommandResponse { + postCommandResponse(context, helpText) + return &model.CommandResponse{} +} diff --git a/server/plugin.go b/server/plugin.go index 599a7d6..552ae30 100644 --- a/server/plugin.go +++ b/server/plugin.go @@ -1,7 +1,11 @@ package main import ( + "io/ioutil" "net/http" + "path/filepath" + + "github.com/pkg/errors" "github.com/Brightscout/mattermost-plugin-confluence/server/command" "github.com/Brightscout/mattermost-plugin-confluence/server/util" @@ -25,16 +29,10 @@ type Plugin struct { func (p *Plugin) OnActivate() error { config.Mattermost = p.API - botUserID, err := p.Helpers.EnsureBot(&model.Bot{ - Username: botUserName, - DisplayName: botDisplayName, - Description: botDescription, - }) - if err != nil { - config.Mattermost.LogError("Error in setting up bot user", "Error", err.Error()) - return err + + if err := p.setUpBotUser(); err != nil { + config.Mattermost.LogError("Failed to create a bot user", "Error", err.Error()) } - config.BotUserID = botUserID if err := p.OnConfigurationChange(); err != nil { return err @@ -73,6 +71,35 @@ func (p *Plugin) OnConfigurationChange() error { return nil } +func (p *Plugin) setUpBotUser() error { + botUserID, err := p.Helpers.EnsureBot(&model.Bot{ + Username: botUserName, + DisplayName: botDisplayName, + Description: botDescription, + }) + if err != nil { + config.Mattermost.LogError("Error in setting up bot user", "Error", err.Error()) + return err + } + + bundlePath, err := p.API.GetBundlePath() + if err != nil { + return err + } + + profileImage, err := ioutil.ReadFile(filepath.Join(bundlePath, "assets", "logo.png")) + if err != nil { + return err + } + + if appErr := p.API.SetProfileImage(botUserID, profileImage); appErr != nil { + return errors.Wrap(appErr, "couldn't set profile image") + } + + config.BotUserID = botUserID + return nil +} + func (p *Plugin) ExecuteCommand(context *plugin.Context, commandArgs *model.CommandArgs) (*model.CommandResponse, *model.AppError) { args, argErr := util.SplitArgs(commandArgs.Command) if argErr != nil { diff --git a/webapp/src/components/subscription_modal/subscription_modal.jsx b/webapp/src/components/subscription_modal/subscription_modal.jsx index 71de8d3..f6dd822 100644 --- a/webapp/src/components/subscription_modal/subscription_modal.jsx +++ b/webapp/src/components/subscription_modal/subscription_modal.jsx @@ -14,7 +14,7 @@ const initialState = { alias: '', baseURL: '', spaceKey: '', - events: [], + events: Constants.CONFLUENCE_EVENTS, error: '', saving: false, };