Skip to content

Commit d4771b3

Browse files
authored
Merge pull request #10 from Brightscout/MI-801
MI-801 Added confluence bot profile image
2 parents 7e5c42c + 46a5fba commit d4771b3

File tree

3 files changed

+53
-13
lines changed

3 files changed

+53
-13
lines changed

server/command/command.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,19 @@ const (
2222
specifyAlias = "Please specify alias."
2323
subscriptionDeleteSuccess = "Subscription with alias **%s** deleted successfully."
2424
noChannelSubscription = "No subscription found for this channel."
25+
helpText = "###### Mattermost Confluence Plugin - Slash Command Help\n" +
26+
"\n* `/confluence subscribe` - Subscribe the current channel to receive notifications from Confluence.\n" +
27+
"* `/confluence unsubscribe \"<alias>\"` - Unsubscribe notifications for the current channel for a given subscription alias.\n" +
28+
"* `/confluence list` - List all subscriptions configured for the current channel.\n" +
29+
"* `/confluence edit \"<alias>\"` - Edit the subscribed events for the given subscription alias for the current channel.\n"
2530
)
2631

2732
var ConfluenceCommandHandler = Handler{
2833
handlers: map[string]HandlerFunc{
2934
"list": listChannelSubscription,
3035
"unsubscribe": deleteSubscription,
3136
"edit": editSubscription,
37+
"help": confluenceHelp,
3238
},
3339
defaultHandler: executeConfluenceDefault,
3440
}
@@ -39,16 +45,15 @@ func GetCommand() *model.Command {
3945
DisplayName: "Confluence",
4046
Description: "Integration with Confluence.",
4147
AutoComplete: true,
42-
AutoCompleteDesc: "Available commands: subscribe, list, unsubscribe \"<alias>\"",
48+
AutoCompleteDesc: "Available commands: subscribe, list, unsubscribe \"<alias>\", edit \"<alias>\", help.",
4349
AutoCompleteHint: "[command]",
4450
}
4551
}
4652

47-
// TODO : Show help text instead of invalid command.
4853
func executeConfluenceDefault(context *model.CommandArgs, args ...string) *model.CommandResponse {
4954
return &model.CommandResponse{
5055
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,
51-
Text: "Invalid command",
56+
Text: "Invalid command parameters. Please use `/confluence help` for more information.",
5257
}
5358
}
5459

@@ -62,6 +67,9 @@ func postCommandResponse(context *model.CommandArgs, text string) {
6267
}
6368

6469
func (ch Handler) Handle(context *model.CommandArgs, args ...string) *model.CommandResponse {
70+
if len(args) == 0 {
71+
return ch.handlers["help"](context, "")
72+
}
6573
for n := len(args); n > 0; n-- {
6674
h := ch.handlers[strings.Join(args[:n], "/")]
6775
if h != nil {
@@ -112,3 +120,8 @@ func editSubscription(context *model.CommandArgs, args ...string) *model.Command
112120
}
113121
return &model.CommandResponse{}
114122
}
123+
124+
func confluenceHelp(context *model.CommandArgs, args ...string) *model.CommandResponse {
125+
postCommandResponse(context, helpText)
126+
return &model.CommandResponse{}
127+
}

server/plugin.go

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package main
22

33
import (
4+
"io/ioutil"
45
"net/http"
6+
"path/filepath"
7+
8+
"github.com/pkg/errors"
59

610
"github.com/Brightscout/mattermost-plugin-confluence/server/command"
711
"github.com/Brightscout/mattermost-plugin-confluence/server/util"
@@ -25,16 +29,10 @@ type Plugin struct {
2529

2630
func (p *Plugin) OnActivate() error {
2731
config.Mattermost = p.API
28-
botUserID, err := p.Helpers.EnsureBot(&model.Bot{
29-
Username: botUserName,
30-
DisplayName: botDisplayName,
31-
Description: botDescription,
32-
})
33-
if err != nil {
34-
config.Mattermost.LogError("Error in setting up bot user", "Error", err.Error())
35-
return err
32+
33+
if err := p.setUpBotUser(); err != nil {
34+
config.Mattermost.LogError("Failed to create a bot user", "Error", err.Error())
3635
}
37-
config.BotUserID = botUserID
3836

3937
if err := p.OnConfigurationChange(); err != nil {
4038
return err
@@ -73,6 +71,35 @@ func (p *Plugin) OnConfigurationChange() error {
7371
return nil
7472
}
7573

74+
func (p *Plugin) setUpBotUser() error {
75+
botUserID, err := p.Helpers.EnsureBot(&model.Bot{
76+
Username: botUserName,
77+
DisplayName: botDisplayName,
78+
Description: botDescription,
79+
})
80+
if err != nil {
81+
config.Mattermost.LogError("Error in setting up bot user", "Error", err.Error())
82+
return err
83+
}
84+
85+
bundlePath, err := p.API.GetBundlePath()
86+
if err != nil {
87+
return err
88+
}
89+
90+
profileImage, err := ioutil.ReadFile(filepath.Join(bundlePath, "assets", "logo.png"))
91+
if err != nil {
92+
return err
93+
}
94+
95+
if appErr := p.API.SetProfileImage(botUserID, profileImage); appErr != nil {
96+
return errors.Wrap(appErr, "couldn't set profile image")
97+
}
98+
99+
config.BotUserID = botUserID
100+
return nil
101+
}
102+
76103
func (p *Plugin) ExecuteCommand(context *plugin.Context, commandArgs *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
77104
args, argErr := util.SplitArgs(commandArgs.Command)
78105
if argErr != nil {

webapp/src/components/subscription_modal/subscription_modal.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const initialState = {
1414
alias: '',
1515
baseURL: '',
1616
spaceKey: '',
17-
events: [],
17+
events: Constants.CONFLUENCE_EVENTS,
1818
error: '',
1919
saving: false,
2020
};

0 commit comments

Comments
 (0)