Skip to content

Commit

Permalink
Support for multiple channels (#75)
Browse files Browse the repository at this point in the history
* Support for multiple channels

* MR feedback

* fix query param in readme instructions

Co-authored-by: kshitij katiyar <[email protected]>

---------

Co-authored-by: limod <[email protected]>
Co-authored-by: Michael Kochell <[email protected]>
Co-authored-by: kshitij katiyar <[email protected]>
  • Loading branch information
4 people authored Sep 27, 2023
1 parent 4bc6343 commit fbf9fef
Show file tree
Hide file tree
Showing 7 changed files with 335 additions and 61 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ golangci-lint:
server:
ifneq ($(HAS_SERVER),)
mkdir -p server/dist;
cd server && env GOOS=linux GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-linux-amd64;
cd server && env GOOS=linux GOARCH=arm64 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-linux-arm64;
cd server && env GOOS=darwin GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-darwin-amd64;
cd server && env GOOS=darwin GOARCH=arm64 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-darwin-arm64;
cd server && env GOOS=windows GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-windows-amd64.exe;
cd server && env GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-linux-amd64;
cd server && env GOOS=linux GOARCH=arm64 CGO_ENABLED=0 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-linux-arm64;
cd server && env GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-darwin-amd64;
cd server && env GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-darwin-arm64;
cd server && env GOOS=windows GOARCH=amd64 CGO_ENABLED=0 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-windows-amd64.exe;
endif

## Ensures NPM dependencies are installed without having to run this all the time.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Originally developed by [Carlos Tadeu Panato Junior](https://github.com/cpanato/

1. Go to **System Console > Plugins > AWS SNS**.

1. Set the channel to send notifications to, specified in the format `teamname,channelname`. If the specified channel does not exist, the plugin will create the channel for you.
1. Set the channel to send notifications to, specified in the format `teamname,channelname`. If the specified channel does not exist, the plugin will create the channel for you. If you want to specify more than one channel, you can append them separated by `;` e.g. `teamname,channelname;teamname-2,channelname-2`
- Note: Must be the team and channel handle used in the URL. For example, in the following URL, set the value to `myteam,mychannel`: https://example.com/myteam/channels/mychannel.

2. Set authorized users who can accept AWS SNS subscriptions. Must be a comma-separated list of user IDs.
Expand All @@ -34,7 +34,7 @@ Originally developed by [Carlos Tadeu Panato Junior](https://github.com/cpanato/
### Step 2: Configure plugin in Amazon AWS

1. Create an [AWS CloudWatch alarm for your instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-cloudwatch-createalarm.html).
2. Create an AWS SNS Topic with an HTTPS subscription to [https://your-mattermost-url/plugins/com.mattermost.aws-sns?token=your-mattermost-token](), where `your-mattermost-url` refers to your Mattermost URL, and `your-mattermost-token` was generated on a previous step. [Follow this documentation](https://docs.safe.com/fme/html/FME_Server_Documentation/ReferenceManual/Amazon_SNS_Publisher_Configure_AWS_Subscription.htm) for additional configuration options.
2. Create an AWS SNS Topic with an HTTPS subscription to [https://your-mattermost-url/plugins/com.mattermost.aws-sns?token=your-mattermost-token&channel=teamname,channelname](), where `your-mattermost-url` refers to your Mattermost URL, and `your-mattermost-token` was generated on a previous step. The `channel` query parameter specifies the channel that should receive the subscription/messages. If no `channel` parameter is passed, the first channel will be used as default. [Follow this documentation](https://docs.safe.com/fme/html/FME_Server_Documentation/ReferenceManual/Amazon_SNS_Publisher_Configure_AWS_Subscription.htm) for additional configuration options.
3. Switch to the Mattermost channel you configured to receive notifications.
4. Select **Confirm** to accept the subscription posted to the channel.
5. Configure your AWS CloudWatch Alarms to use the topic you created previously.
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ require (
github.com/mattermost/mattermost-server/v6 v6.0.3
github.com/mholt/archiver/v3 v3.5.0
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.0
)
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"settings": [
{
"key": "TeamChannel",
"display_name": "Channel to send notifications to:",
"display_name": "Channels to send notifications to:",
"type": "text",
"help_text": "The channel to send notifications to, specified in the format `teamname,channelname`. If the specified channel does not exist, the plugin will create the channel for you.\n \n Note: Must be the team and channel handle used in the URL. For example, in the following URL, set the value to `myteam,mychannel`: https://example.com/myteam/channels/mychannel.",
"help_text": "The channels to send notifications to. Multiple channels can be specified. Format `teamname,channelname;teamname-2,channelname-2`. If the specified channels do not exist, the plugin will create the channels for you.\n \n Note: Must be the team and channel handle used in the URL. For example, in the following URL, set the value to `myteam,mychannel`: https://example.com/myteam/channels/mychannel.",
"placeholder": "",
"default": null
},
Expand Down
6 changes: 3 additions & 3 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*mo

switch action {
case "list-topics":
return p.listTopicsToChannel(), nil
return p.listTopicsToChannel(args.ChannelId), nil
default:
return &model.CommandResponse{
ResponseType: model.CommandResponseTypeEphemeral,
Expand All @@ -66,9 +66,9 @@ func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*mo
}

// listTopicsToChannel Lists topics subscribed to the channel
func (p *Plugin) listTopicsToChannel() *model.CommandResponse {
func (p *Plugin) listTopicsToChannel(channelID string) *model.CommandResponse {
var topics SNSTopics
val, err := p.API.KVGet(topicsListPrefix + p.ChannelID)
val, err := p.API.KVGet(topicsListPrefix + channelID)
if err != nil {
p.API.LogError("Failed to Get from KV Store")
return &model.CommandResponse{
Expand Down
Loading

0 comments on commit fbf9fef

Please sign in to comment.