From 517c73ef776bac891c2053c77f7bc52b39bca950 Mon Sep 17 00:00:00 2001 From: Maisnam Raju Singh <85172229+maisnamrajusingh@users.noreply.github.com> Date: Tue, 29 Jun 2021 04:11:02 +0700 Subject: [PATCH 1/3] solves Gh 72 - Welcome bot will not let me add a message to private channels (#79) Co-authored-by: maisnamrajusingh --- server/command.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/command.go b/server/command.go index 6a807d1ba..15c270a7e 100644 --- a/server/command.go +++ b/server/command.go @@ -131,7 +131,7 @@ func (p *Plugin) executeCommandSetWelcome(args *model.CommandArgs) { return } - if channelInfo.Type == model.CHANNEL_PRIVATE { + if channelInfo.Type == model.CHANNEL_DIRECT { p.postCommandResponse(args, "welcome messages are not supported for direct channels") return } From 77bd89a5ed3fc868fd886e5be7f509bc50349f9c Mon Sep 17 00:00:00 2001 From: Maisnam Raju Singh <85172229+maisnamrajusingh@users.noreply.github.com> Date: Thu, 19 Aug 2021 15:34:34 +0700 Subject: [PATCH 2/3] Fixes /welcomebot preview teamname command not working. (#74) --- server/welcomebot.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/welcomebot.go b/server/welcomebot.go index 6deb0eadd..172ace265 100644 --- a/server/welcomebot.go +++ b/server/welcomebot.go @@ -57,7 +57,7 @@ func (p *Plugin) getSiteURL() string { return *config.ServiceSettings.SiteURL } -func (p *Plugin) newSampleMessageTemplate(teamName, userID string) (*MessageTemplate, error) { +func (p *Plugin) newSampleMessageTemplate(teamName string, userID string) (*MessageTemplate, error) { data := &MessageTemplate{} var err *model.AppError @@ -66,14 +66,14 @@ 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) } if data.Townsquare, err = p.API.GetChannelByName(data.Team.Id, "town-square", false); err != nil { - p.API.LogError("failed to query town-square", "team_name", teamName) - return nil, fmt.Errorf("failed to query town-square %s: %w", teamName, err) + p.API.LogError("failed to query town-square", "team_name", data.Team.Name) + return nil, fmt.Errorf("failed to query town-square %s: %w", data.Team.Name, err) } if data.DirectMessage, err = p.API.GetDirectChannel(data.User.Id, p.botUserID); err != nil { From 03ea7221a9a3976de876f8c8801c3ebb0fa9509f Mon Sep 17 00:00:00 2001 From: Maisnam Raju Singh <85172229+maisnamrajusingh@users.noreply.github.com> Date: Wed, 1 Sep 2021 03:00:52 +0700 Subject: [PATCH 3/3] [mm-65] Allows users to add multiple teams to the messages using `team-a,team-b` in the messages (#82) Co-authored-by: Jason Frerich --- README.md | 6 +++--- server/command.go | 16 ++++++++++------ server/hooks.go | 9 +++++++-- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 033f2d31a..f771239f0 100644 --- a/README.md +++ b/README.md @@ -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." @@ -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. @@ -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!", diff --git a/server/command.go b/server/command.go index 15c270a7e..8832a594b 100644 --- a/server/command.go +++ b/server/command.go @@ -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 } } diff --git a/server/hooks.go b/server/hooks.go index 981d2d541..91f9528ad 100644 --- a/server/hooks.go +++ b/server/hooks.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "strings" "time" "github.com/mattermost/mattermost-server/v5/mlog" @@ -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) + } } } }