From b17d0cae2e60ca463c75a22ec0b5f5edc34559a5 Mon Sep 17 00:00:00 2001 From: maisnamrajusingh Date: Sun, 27 Jun 2021 07:55:35 +0000 Subject: [PATCH 1/5] fixes issue 36 --- server/hooks.go | 2 ++ server/welcomebot.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/server/hooks.go b/server/hooks.go index 981d2d541..cb022a8c5 100644 --- a/server/hooks.go +++ b/server/hooks.go @@ -20,6 +20,8 @@ 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) + } else if message.TeamName == "*" { + go p.processWelcomeMessage(*data, *message) } } } diff --git a/server/welcomebot.go b/server/welcomebot.go index 6deb0eadd..309395565 100644 --- a/server/welcomebot.go +++ b/server/welcomebot.go @@ -66,7 +66,7 @@ func (p *Plugin) newSampleMessageTemplate(teamName, userID string) (*MessageTemp return nil, fmt.Errorf("failed to query user %s: %w", userID, err) } - if data.Team, err = p.API.GetTeamByName(teamName); err != nil { + if data.Team, err = p.API.GetTeamByName(strings.ToLower(teamName)); err != nil { p.API.LogError("failed to query team", "team_name", teamName, "err", err) return nil, fmt.Errorf("failed to query team %s: %w", teamName, err) } From bcd11f08507c55aaa1d200fd6bb2ecc44dc7c15d Mon Sep 17 00:00:00 2001 From: maisnamrajusingh Date: Sun, 27 Jun 2021 11:23:09 +0000 Subject: [PATCH 2/5] edit Readme --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 033f2d31a..3bd92bf49 100644 --- a/README.md +++ b/README.md @@ -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 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. @@ -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. ``` @@ -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": "*" } ] } From 2d4c6bc36e51d310bf33c1c35ccbaf3f890e02b1 Mon Sep 17 00:00:00 2001 From: maisnamrajusingh Date: Thu, 8 Jul 2021 14:28:24 +0000 Subject: [PATCH 3/5] updated changes according to comments from ben --- server/hooks.go | 7 +++++-- server/welcomebot.go | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/server/hooks.go b/server/hooks.go index cb022a8c5..c1f2ee23e 100644 --- a/server/hooks.go +++ b/server/hooks.go @@ -18,10 +18,13 @@ func (p *Plugin) UserHasJoinedTeam(c *plugin.Context, teamMember *model.TeamMemb } for _, message := range p.getWelcomeMessages() { - if message.TeamName == data.Team.Name { + switch message.TeamName { + case data.Team.Name: go p.processWelcomeMessage(*data, *message) - } else if message.TeamName == "*" { + case "*": go p.processWelcomeMessage(*data, *message) + default: + p.API.LogError("Couldn't find the message for the team") } } } diff --git a/server/welcomebot.go b/server/welcomebot.go index 309395565..6deb0eadd 100644 --- a/server/welcomebot.go +++ b/server/welcomebot.go @@ -66,7 +66,7 @@ func (p *Plugin) newSampleMessageTemplate(teamName, userID string) (*MessageTemp return nil, fmt.Errorf("failed to query user %s: %w", userID, err) } - if data.Team, err = p.API.GetTeamByName(strings.ToLower(teamName)); err != nil { + if data.Team, err = p.API.GetTeamByName(teamName); err != nil { p.API.LogError("failed to query team", "team_name", teamName, "err", err) return nil, fmt.Errorf("failed to query team %s: %w", teamName, err) } From 1ed0ab6f376ccbaae40b547a8dce26d037d23c31 Mon Sep 17 00:00:00 2001 From: Maisnam Raju Singh <85172229+maisnamrajusingh@users.noreply.github.com> Date: Thu, 2 Sep 2021 10:47:25 +0700 Subject: [PATCH 4/5] Update hooks.go --- server/hooks.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/server/hooks.go b/server/hooks.go index 323f7905a..98ab638ee 100644 --- a/server/hooks.go +++ b/server/hooks.go @@ -20,13 +20,14 @@ func (p *Plugin) UserHasJoinedTeam(c *plugin.Context, teamMember *model.TeamMemb for _, message := range p.getWelcomeMessages() { 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 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: From 4760cd2b7e9ec6660d5a7310c6ea70be96d21745 Mon Sep 17 00:00:00 2001 From: maisnamrajusingh Date: Thu, 2 Sep 2021 03:50:56 +0000 Subject: [PATCH 5/5] formatted code --- server/hooks.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/hooks.go b/server/hooks.go index 98ab638ee..800e6bf21 100644 --- a/server/hooks.go +++ b/server/hooks.go @@ -20,13 +20,13 @@ func (p *Plugin) UserHasJoinedTeam(c *plugin.Context, teamMember *model.TeamMemb for _, message := range p.getWelcomeMessages() { switch message.TeamName { - case data.Team.Name: + 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) - } + go p.processWelcomeMessage(*data, *message) + } } case "*": go p.processWelcomeMessage(*data, *message)