diff --git a/README.md b/README.md index fbdf38627..d2cd8f14f 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ To configure the Welcome Bot, edit your `config.json` file with a message you wa "com.mattermost.welcomebot": { "WelcomeMessages": [ { - "TeamName": "your-team-name, your-second-team-name", + "TeamName": "your-team-name", "DelayInSeconds": 3, "Message": [ "Your welcome message here. Each list item specifies one line in the message text." @@ -62,7 +62,7 @@ To configure the Welcome Bot, edit your `config.json` file with a message you wa where -- **TeamName**: The teams for which the Welcome Bot sends a message. Must be the team handle used in the URL, in lowercase. For example, in the following URL, the **TeamName** value is `my-team`: https://example.com/my-team/channels/my-channel . In the case of multiple teams, use comma separated fields. For example `"my-team, my-team-2"` to display the same messages for both `my-team` and `my-team-2` +- **TeamName**: The team for which the Welcome Bot sends a message for. Must be the team handle used in the URL, in lowercase. For example, in the following URL the **TeamName** value is `my-team`: https://example.com/my-team/channels/my-channel - **DelayInSeconds**: The number of seconds after joining a team that the user receives a welcome message. - **Message**: The message posted to the user. - (Optional) **IncludeGuests**: Whether or not to include guest users. @@ -100,7 +100,7 @@ To accomplish the above, you can specify the following configuration in your `co "com.mattermost.welcomebot": { "WelcomeMessages": [ { - "TeamName": "staff, management", + "TeamName": "staff", "DelayInSeconds": 5, "Message": [ "### Welcome {{.UserDisplayName}} to the Staff {{.Team.DisplayName}} team!", diff --git a/server/command.go b/server/command.go index 9ce161756..281fce0e0 100644 --- a/server/command.go +++ b/server/command.go @@ -86,17 +86,13 @@ func (p *Plugin) validateCommand(action string, parameters []string) string { func (p *Plugin) executeCommandPreview(teamName string, args *model.CommandArgs) { found := false for _, message := range p.getWelcomeMessages() { - var teamNamesArr = strings.Split(message.TeamName, ",") - for _, name := range teamNamesArr { - tn := strings.TrimSpace(name) - if tn == teamName { - p.postCommandResponse(args, "%s", teamName) - if err := p.previewWelcomeMessage(teamName, args, *message); err != nil { - p.postCommandResponse(args, "error occurred while processing greeting for team `%s`: `%s`", teamName, err) - return - } - found = true + if message.TeamName == teamName { + if err := p.previewWelcomeMessage(teamName, args, *message); err != nil { + p.postCommandResponse(args, "error occurred while processing greeting for team `%s`: `%s`", teamName, err) + return } + + found = true } } @@ -134,7 +130,7 @@ func (p *Plugin) executeCommandSetWelcome(args *model.CommandArgs) { return } - if channelInfo.Type == model.ChannelTypeDirect { + if channelInfo.Type == model.ChannelTypePrivate { p.postCommandResponse(args, "welcome messages are not supported for direct channels") return } diff --git a/server/hooks.go b/server/hooks.go index e1f7efe1c..25b1b744e 100644 --- a/server/hooks.go +++ b/server/hooks.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "strings" "time" "github.com/mattermost/mattermost-server/v6/model" @@ -19,15 +18,12 @@ func (p *Plugin) UserHasJoinedTeam(c *plugin.Context, teamMember *model.TeamMemb } for _, message := range p.getWelcomeMessages() { - var teamNamesArr = strings.Split(message.TeamName, ",") - for _, name := range teamNamesArr { - tn := strings.TrimSpace(name) - if tn == data.Team.Name { - if data.User.IsGuest() && !message.IncludeGuests { - continue - } - go p.processWelcomeMessage(*data, *message) - } + if data.User.IsGuest() && !message.IncludeGuests { + continue + } + + if message.TeamName == data.Team.Name { + go p.processWelcomeMessage(*data, *message) } } }