Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows using * to configure the welcome message for all teams #80

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,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. Can be set to "*" if the message is meant for each team which user joined. 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) **AttachmentMessage**: Message text in attachment containing user action buttons.
Expand Down Expand Up @@ -93,6 +93,8 @@ Those who join the Staff team should be added to a set of channels based on thei

Moreover, those who join the DevSecOps team should automatically be added to Escalation Process and Incidents channels.

And user will received a welcome message for joining each team

To accomplish the above, you can specify the following configuration in your `config.json` file.

```
Expand Down Expand Up @@ -174,6 +176,15 @@ To accomplish the above, you can specify the following configuration in your `co
"ChannelsAddedTo": ["escalation-process", "incidents"]
}
]
},
{
"DelayInSeconds": 5,
"Message": [
"### Welcome {{.UserDisplayName}} to the {{.Team.DisplayName}} team!",
"",
"Feel free to discuss off-topic things, but please use the ~off-topic channel for this"
],
"TeamName": "*"
}
]
}
Expand Down
17 changes: 12 additions & 5 deletions server/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ 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 {
go p.processWelcomeMessage(*data, *message)
switch message.TeamName {
case data.Team.Name:
var teamNamesArr = strings.Split(message.TeamName, ",")
for _, name := range teamNamesArr {
tn := strings.TrimSpace(name)
if tn == data.Team.Name {
go p.processWelcomeMessage(*data, *message)
}
}
case "*":
go p.processWelcomeMessage(*data, *message)
default:
p.API.LogError("Couldn't find the message for the team")
}
}
}
Expand Down