Skip to content

Commit

Permalink
Merge branch 'master' into config-in-sysconsole
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzei authored Jan 4, 2024
2 parents d5637cc + 344cddf commit 85e4615
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 97 deletions.
63 changes: 0 additions & 63 deletions .circleci/config.yml

This file was deleted.

18 changes: 18 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: cd
on:
workflow_run:
workflows: ["ci"]
branches-ignore: ["*"]
types:
- completed
push:
tags:
- "v*"

permissions:
contents: read

jobs:
plugin-cd:
uses: mattermost/actions-workflows/.github/workflows/plugin-cd.yml@main
secrets: inherit
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: ci
on:
schedule:
- cron: "0 0 * * *"
push:
branches:
- master
tags:
- "v*"
pull_request:

permissions:
contents: read

jobs:
plugin-ci:
uses: mattermost/actions-workflows/.github/workflows/plugin-ci.yml@main
secrets: inherit
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
14.21.1
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @jfrerich
* @mickmister
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
[![Release](https://img.shields.io/github/v/release/mattermost/mattermost-plugin-welcomebot)](https://github.com/mattermost/mattermost-plugin-welcomebot/releases/latest)
[![HW](https://img.shields.io/github/issues/mattermost/mattermost-plugin-welcomebot/Up%20For%20Grabs?color=dark%20green&label=Help%20Wanted)](https://github.com/mattermost/mattermost-plugin-welcomebot/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22Up+For+Grabs%22+label%3A%22Help+Wanted%22)

**Maintainer:** [@jfrerich](https://github.com/jfrerich)
**Co-Maintainer:** [@iomodo](https://github.com/iomodo)
**Maintainer:** [@mickmister](https://github.com/mickmister)

Use this plugin to improve onboarding and HR processes. It adds a Welcome Bot that helps welcome users to teams and/or channels as well as easily join channels based on selections.

Expand Down Expand Up @@ -36,8 +35,9 @@ Edit your `config.json` file with a message you want to send to a user in the fo
"com.mattermost.welcomebot": {
"WelcomeMessages": [
{
"TeamName": "your-team-name, your-second-team-name",
"TeamName": "your-team-name",
"DelayInSeconds": 3,
"IncludeGuests": false,
"Message": [
"Your welcome message here. Each list item specifies one line in the message text."
],
Expand Down Expand Up @@ -105,7 +105,7 @@ If you see `[Object object]` in the text field, that's because the configuration

### Reference

- **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. 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) **IncludeGuests**: Whether or not to include guest users.
Expand Down Expand Up @@ -143,7 +143,7 @@ To accomplish the above, you can specify the following configuration in your `co
"com.mattermost.welcomebot": {
"WelcomeMessages": [
{
"TeamName": "staff, management",
"TeamName": "staff",
"DelayInSeconds": 5,
"Message": [
"### Welcome {{.UserDisplayName}} to the Staff {{.Team.DisplayName}} team!",
Expand Down
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "This plugin adds a WelcomeBot that helps add new users to channels.",
"homepage_url": "https://github.com/mattermost/mattermost-plugin-welcomebot",
"support_url": "https://github.com/mattermost/mattermost-plugin-welcomebot/issues",
"release_notes_url": "https://github.com/mattermost/mattermost-plugin-welcomebot/releases/tag/v1.2.0",
"version": "1.2.0",
"release_notes_url": "https://github.com/mattermost/mattermost-plugin-welcomebot/releases/tag/v1.3.0",
"version": "1.3.0",
"min_server_version": "5.37.0",
"server": {
"executables": {
Expand Down
18 changes: 7 additions & 11 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,13 @@ 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() {
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
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
}

found = true
}
}

Expand Down Expand Up @@ -134,7 +130,7 @@ func (p *Plugin) executeCommandSetWelcome(args *model.CommandArgs) {
return
}

if channelInfo.Type == model.ChannelTypeDirect {
if channelInfo.Type == model.ChannelTypePrivate {
p.postCommandResponse(args, "welcome messages are not supported for direct channels")
return
}
Expand Down
16 changes: 6 additions & 10 deletions server/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"strings"
"time"

"github.com/mattermost/mattermost-server/v6/model"
Expand All @@ -19,15 +18,12 @@ 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 {
if data.User.IsGuest() && !message.IncludeGuests {
continue
}
go p.processWelcomeMessage(*data, *message)
}
if data.User.IsGuest() && !message.IncludeGuests {
continue
}

if message.TeamName == data.Team.Name {
go p.processWelcomeMessage(*data, *message)
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions server/http_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
var action *Action
if err := json.NewDecoder(r.Body).Decode(&action); err != nil || action == nil {
p.API.LogDebug("failed to decode action from request body", "error", err.Error())
p.encodeEphemeralMessage(w, "WelcomeBot Error: We could not decode the action")
return
}
Expand All @@ -28,19 +29,19 @@ func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Req
var err *model.AppError

if data.User, err = p.API.GetUser(action.Context.UserID); err != nil {
p.API.LogError("failed to query user", "user_id", action.Context.UserID)
p.API.LogError("failed to query user", "user_id", action.Context.UserID, "error", err.Error())
p.encodeEphemeralMessage(w, "WelcomeBot Error: We could not find the supplied user")
return
}

if data.Team, err = p.API.GetTeam(action.Context.TeamID); err != nil {
p.API.LogError("failed to query team", "team_id", action.Context.TeamID)
p.API.LogError("failed to query team", "team_id", action.Context.TeamID, "error", err.Error())
p.encodeEphemeralMessage(w, "WelcomeBot Error: We could not find the supplied team")
return
}

if data.DirectMessage, err = p.API.GetDirectChannel(action.Context.UserID, p.botUserID); err != nil {
p.API.LogError("failed to query direct message channel", "user_id", action.Context.UserID)
p.API.LogError("failed to query direct message channel", "user_id", action.Context.UserID, "error", err.Error())
p.encodeEphemeralMessage(w, "WelcomeBot Error: We could not find the welcome bot direct message channel")
return
}
Expand All @@ -49,7 +50,7 @@ func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Req

// Check to make sure you're still in the team
if teamMember, err := p.API.GetTeamMember(action.Context.TeamID, action.Context.UserID); err != nil || teamMember == nil || teamMember.DeleteAt > 0 {
p.API.LogError("Didn't have access to team", "user_id", action.Context.UserID, "team_id", action.Context.TeamID)
p.API.LogError("Didn't have access to team", "user_id", action.Context.UserID, "team_id", action.Context.TeamID, "error", err.Error())
p.encodeEphemeralMessage(w, "WelcomeBot Error: You do not appear to have access to this team")
return
}
Expand Down
2 changes: 1 addition & 1 deletion server/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ var manifest = struct {
Version string
}{
ID: "com.mattermost.welcomebot",
Version: "1.2.0",
Version: "1.3.0",
}

0 comments on commit 85e4615

Please sign in to comment.