Skip to content

Commit

Permalink
Merge branch 'master' into mattermost-communitygh-36
Browse files Browse the repository at this point in the history
  • Loading branch information
maisnamrajusingh authored Sep 2, 2021
2 parents 2d4c6bc + 03ea722 commit 5d69afd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
4 changes: 2 additions & 2 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 @@ -102,7 +102,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
18 changes: 11 additions & 7 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 Expand Up @@ -131,7 +135,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
}
Expand Down
8 changes: 7 additions & 1 deletion 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 @@ -20,7 +21,12 @@ func (p *Plugin) UserHasJoinedTeam(c *plugin.Context, teamMember *model.TeamMemb
for _, message := range p.getWelcomeMessages() {
switch message.TeamName {
case 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)
}
case "*":
go p.processWelcomeMessage(*data, *message)
default:
Expand Down
8 changes: 4 additions & 4 deletions server/welcomebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {
Expand Down

0 comments on commit 5d69afd

Please sign in to comment.