From 53feffc38cbc54c5db684d4a85fd6464628aad37 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Mon, 13 Jun 2022 16:17:18 -0400 Subject: [PATCH 1/3] Add configuration via system console --- README.md | 50 +++++++++++++++++++++++++++++++++++++---- plugin.json | 11 +++++++-- server/configuration.go | 39 ++++++++++++++++++++++++++++++++ server/manifest.go | 2 +- 4 files changed, 95 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 33b0dfacb..353b9d053 100644 --- a/README.md +++ b/README.md @@ -18,14 +18,18 @@ Use this plugin to improve onboarding and HR processes. It adds a Welcome Bot th ## Configuration -1. Go to **System Console > Plugins > Management** and click **Enable** to enable the Welcome Bot plugin. +1. Go to **System Console > Plugin Management** and click **Enable** to enable the Welcome Bot plugin. - If you are running Mattermost v5.11 or earlier, you must first go to the [releases page of this GitHub repository](https://github.com/mattermost/mattermost-plugin-welcomebot/releases), download the latest release, and upload it to your Mattermost instance [following this documentation](https://docs.mattermost.com/administration/plugins.html#plugin-uploads). -2. Modify your `config.json` file to include your Welcome Bot's messages and actions, under the `PluginSettings`. See below for an example of what this should look like. +2. Modify your configuration to include your Welcome Bot's messages and actions. See below for examples. ## Usage -To configure the Welcome Bot, edit your `config.json` file with a message you want to send to a user in the following format: +To configure the Welcome Bot, choose one of the below options: + +### config.json + +Edit your `config.json` file with a message you want to send to a user in the following format: ``` "Plugins": { @@ -61,7 +65,45 @@ To configure the Welcome Bot, edit your `config.json` file with a message you wa }, ``` -where +This field can be JSON or a string containing JSON. + +### System Console + +In the UI, go to **System Console -> Plugins -> Welcome Bot** and edit the **Welcome Messages** text field to include the JSON array for messages you want to send. Use the following format: + +``` +[ + { + "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." + ], + "AttachmentMessage": [ + "Attachment message containing user actions" + ], + "Actions" : [ + { + "ActionType": "button", + "ActionDisplayName": "User Action", + "ActionName": "action-name", + "ActionSuccessfulMessage": [ + "Message posted after the user takes this action and joins channels specified by 'ChannelsAddedTo'." + ], + "ChannelsAddedTo": ["channel-1", "channel-2"] + }, + { + "ActionType": "automatic", + "ChannelsAddedTo": ["channel-3", "channel-4"] + } + ] + } +] +``` + +If you see `[Object object]` in the text field, that's because the configuration was configured as JSON directly in your `config.json` instead of as a string. + +### 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` - **DelayInSeconds**: The number of seconds after joining a team that the user receives a welcome message. diff --git a/plugin.json b/plugin.json index a5e87f27e..84c7a1f65 100644 --- a/plugin.json +++ b/plugin.json @@ -5,7 +5,7 @@ "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", + "version": "1.3.0", "min_server_version": "5.37.0", "server": { "executables": { @@ -17,6 +17,13 @@ } }, "settings_schema": { - "header": "Configure this plugin directly in the config.json file. Learn more [in our documentation](https://github.com/mattermost/mattermost-plugin-welcomebot/blob/master/README.md).\n\n To report an issue, make a suggestion, or submit a contribution, [check the plugin repository](https://github.com/mattermost/mattermost-plugin-welcomebot)." + "settings": [ + { + "key": "WelcomeMessages", + "type": "longtext", + "display_name": "Welcome Messages:", + "help_text": "JSON formatted configuration for the welcome messages. See [usage here](https://github.com/mattermost/mattermost-plugin-welcomebot#usage)." + } + ] } } diff --git a/server/configuration.go b/server/configuration.go index 2b8123323..9f4dce758 100644 --- a/server/configuration.go +++ b/server/configuration.go @@ -1,5 +1,9 @@ package main +import ( + "encoding/json" +) + const ( actionTypeAutomatic = "automatic" actionTypeButton = "button" @@ -54,6 +58,41 @@ func (p *Plugin) getWelcomeMessages() []*ConfigMessage { return p.welcomeMessages.Load().([]*ConfigMessage) } +// Custom JSON unmarshal function for Configuration. +// To allow for configuration in the System Console we need to support Configuration.WelcomeMessages +// being either a string or slice of *ConfigMessage. +func (c *Configuration) UnmarshalJSON(b []byte) error { + var s struct { + WelcomeMessages string + } + + err := json.Unmarshal(b, &s) + if err == nil { + var configMessages []*ConfigMessage + err = json.Unmarshal([]byte(s.WelcomeMessages), &configMessages) + if err != nil { + return err + } + + c.WelcomeMessages = configMessages + + return nil + } + + var tc struct { + WelcomeMessages []*ConfigMessage + } + + err = json.Unmarshal(b, &tc) + if err != nil { + return err + } + + c.WelcomeMessages = tc.WelcomeMessages + + return nil +} + // OnConfigurationChange is invoked when configuration changes may have been made. func (p *Plugin) OnConfigurationChange() error { var c Configuration diff --git a/server/manifest.go b/server/manifest.go index 38e43ab9c..99642bdb0 100644 --- a/server/manifest.go +++ b/server/manifest.go @@ -7,5 +7,5 @@ var manifest = struct { Version string }{ ID: "com.mattermost.welcomebot", - Version: "1.2.0", + Version: "1.3.0", } From bcf956665fe01072f8fa8e6f6da30c9e6a8d3968 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Tue, 21 Jun 2022 08:45:49 -0400 Subject: [PATCH 2/3] Revert plugin version --- plugin.json | 2 +- server/manifest.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.json b/plugin.json index 84c7a1f65..0360346bf 100644 --- a/plugin.json +++ b/plugin.json @@ -5,7 +5,7 @@ "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.3.0", + "version": "1.2.0", "min_server_version": "5.37.0", "server": { "executables": { diff --git a/server/manifest.go b/server/manifest.go index 99642bdb0..38e43ab9c 100644 --- a/server/manifest.go +++ b/server/manifest.go @@ -7,5 +7,5 @@ var manifest = struct { Version string }{ ID: "com.mattermost.welcomebot", - Version: "1.3.0", + Version: "1.2.0", } From d5637ccb257e373c6e7ad52263a7a8f3229095a9 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Sat, 24 Sep 2022 18:11:54 -0400 Subject: [PATCH 3/3] Update README.md Co-authored-by: Jason Frerich --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 353b9d053..79eb20d6b 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Use this plugin to improve onboarding and HR processes. It adds a Welcome Bot th ## Configuration -1. Go to **System Console > Plugin Management** and click **Enable** to enable the Welcome Bot plugin. +1. Go to **System Console > Plugins > Plugin Management** and click **Enable** to enable the Welcome Bot plugin. - If you are running Mattermost v5.11 or earlier, you must first go to the [releases page of this GitHub repository](https://github.com/mattermost/mattermost-plugin-welcomebot/releases), download the latest release, and upload it to your Mattermost instance [following this documentation](https://docs.mattermost.com/administration/plugins.html#plugin-uploads). 2. Modify your configuration to include your Welcome Bot's messages and actions. See below for examples.