Skip to content

Commit

Permalink
[mm-65] Allows users to add multiple teams to the messages using `tea…
Browse files Browse the repository at this point in the history
…m-a,team-b` in the messages (#82)

Co-authored-by: Jason Frerich <jason.frerich@mattermost.com>
  • Loading branch information
maisnamrajusingh and jfrerich authored Aug 31, 2021
1 parent 77bd89a commit 03ea722
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ To configure the Welcome Bot, edit your `config.json` file with a message you wa
"com.mattermost.welcomebot": {
"WelcomeMessages": [
{
"TeamName": "your-team-name",
"TeamName": "your-team-name, your-second-team-name",
"DelayInSeconds": 3,
"Message": [
"Your welcome message here. Each list item specifies one line in the message text."
Expand Down Expand Up @@ -63,7 +63,7 @@ To configure the Welcome Bot, edit your `config.json` file with a message you wa

where

- **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
- **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`
- **DelayInSeconds**: The number of seconds after joining a team that the user receives a welcome message.
- **Message**: The message posted to the user.
- (Optional) **AttachmentMessage**: Message text in attachment containing user action buttons.
Expand Down Expand Up @@ -100,7 +100,7 @@ To accomplish the above, you can specify the following configuration in your `co
"com.mattermost.welcomebot": {
"WelcomeMessages": [
{
"TeamName": "staff",
"TeamName": "staff, management",
"DelayInSeconds": 5,
"Message": [
"### Welcome {{.UserDisplayName}} to the Staff {{.Team.DisplayName}} team!",
Expand Down
16 changes: 10 additions & 6 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,17 @@ 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() {
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
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
}

found = true
}
}

Expand Down
9 changes: 7 additions & 2 deletions server/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"strings"
"time"

"github.com/mattermost/mattermost-server/v5/mlog"
Expand All @@ -18,8 +19,12 @@ func (p *Plugin) UserHasJoinedTeam(c *plugin.Context, teamMember *model.TeamMemb
}

for _, message := range p.getWelcomeMessages() {
if message.TeamName == data.Team.Name {
go p.processWelcomeMessage(*data, *message)
var teamNamesArr = strings.Split(message.TeamName, ",")
for _, name := range teamNamesArr {
tn := strings.TrimSpace(name)
if tn == data.Team.Name {
go p.processWelcomeMessage(*data, *message)
}
}
}
}
Expand Down

0 comments on commit 03ea722

Please sign in to comment.