Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code for Chat-with-slack-channel #1506

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions Chatbot-with-Slack-Channel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Creating Slack subscription in SNS topic via Chatbot

This project contains source code and supporting files for a serverless application that you can deploy with the AWS Cloudformation or SAM. It includes the following files and folders.
The project creates a chatbot slack channel configuration which will be automatically subscribed to the SNS topic of your selection.

## Pre-requisite:

--> Slack Channel ID (To get the ID, open Slack, right click on the channel name in the left pane, then choose Copy Link. The channel ID is the 9-character string at the end of the URL. For example, ABCBBLZZZ.)
--> Workspace ID (To get the workspace ID, you must perform the initial authorization flow with Slack in the AWS Chatbot console. Then you can copy and paste the workspace ID from the console.)
--> IAM role that needs to be used
--> Topic(s) ARN
--> Name of the ChatBot channel configured

For more details, check the following documention on Setting Up AWS Chatbot with Slack in the AWS Chatbot User Guide.

[+] https://docs.aws.amazon.com/chatbot/latest/adminguide/slack-setup.html

## Deployment Instructions

1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
```
git clone https://github.com/aws-samples/serverless-patterns
```
1. Change directory to the pattern directory:
```
cd Chat-with-slack-channel/
```
1. From the command line, use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yml file:
```
sam deploy --guided
```
1. During the prompts:

* Enter a stack name
* Enter the desired AWS Region
* Parameter ChannelName
* Parameter IamRole
* Parameter ChannelID
* Parameter WorkspaceID
* Parameter TopicARN

Once you have run sam deploy --guided mode once and saved arguments to a configuration file (samconfig.toml), you can use sam deploy in future to use these defaults.

1. Note the outputs from the SAM deployment process. These contain the resource names and/or ARNs which are used for testing.

## Cleanup

1. Delete the stack
```
aws cloudformation delete-stack --stack-name STACK_NAME
```
2. Confirm the stack has been deleted
```
aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus"
```
46 changes: 46 additions & 0 deletions Chatbot-with-Slack-Channel/example-pattern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"title": "SNS to Chatbot to Slack Integration via CFN",
"description": "Creating a Slack channel SNS subscription via AWS Chatbot",
"language": "YAML",
"level": "200",
"framework": "SAM",
"introBox": {
"headline": "How it works",
"text": [
"This is a sample project where the message will be published from SNS topic to slack channel subscription."
]
},
"gitHub": {
"template": {
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/Chatbot-with-Slack-Channel",
"templateURL": "serverless-patterns/Chatbot-with-Slack-Channel",
"projectFolder": "Chatbot-with-Slack-Channel",
"templateFile": "sns-lambda-slack-integration-SAM/SNS-Chatbot-Slack.yaml"
}
},

"deploy": {
"text": [
"CFN deploy"
]
},
"testing": {
"text": [
"See the GitHub repo for detailed testing instructions."
]
},
"cleanup": {
"text": [
"Delete the stack: <code>cdk delete</code>."
]
},
"authors": [
{
"name": "Tanya Gupta",
"image": "",
"bio": "AWS Cloud Support Engineer",
"linkedin": "",
"twitter": ""
}
]
}
32 changes: 32 additions & 0 deletions Chatbot-with-Slack-Channel/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
AWSTemplateFormatVersion: 2010-09-09
Parameters:
ChannelName:
Type: String
Description: Enter the channel name
IamRole:
Type: String
Description: Enter the IAM role ARN
ChannelID:
Type: String
Description: Enter the channel ID
WorkspaceID:
Type: String
Description: Enter the workspace ID
TopicARN:
Type: String
Description: Enter the Topic ARN

Resources:
Chatbot:
Type: 'AWS::Chatbot::SlackChannelConfiguration'
Properties:
ConfigurationName: !Ref ChannelName
IamRoleArn: !Ref IamRole
LoggingLevel: ERROR
SlackChannelId: !Ref ChannelID
SlackWorkspaceId: !Ref WorkspaceID
SnsTopicArns:
- !Ref TopicARN
Metadata:
'AWS::CloudFormation::Designer':
id: 089bf9d6-a2a9-4459-ae95-69eb19129961
Loading