Skip to content

Latest commit

 

History

History

aws-ts-slackbot

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Deploy

Slackbot for Posting Slack Mention Notifications

This is an example of a simple Slackbot (called '@mentionbot') that posts a notification to a specific channel any time you're @mentioned anywhere. This bot is useful for when you need a time-ordered list of @mentions to go through at a later point.

Slack users can subscribe/unsubscribe from notifications easily. To receive notifications, add @mentionbot to a channel you want to be notified in. Then send any message to @mentionbot to subscribe. To stop getting messages, send a message to @mentionbot containing the word unsubscribe.

The example contains a few useful patterns showing you how to build a good Slackbot while taking advantage of a lot of conveniences that Pulumi and the aws and awsx packages provide.

  1. We set up an ApiGateway API to receive push notifications from Slack whenever important events happen.
  2. Slack has strict requirements on how quickly the push endpoint must respond with 200 notifications before they consider the message as "not received", triggering back-off and resending of those same messages. For this reason, our example does not process Slack event messages as they come in. Instead, they are immediately added to an AWS SNS Topic to be processed at a later point in time. This allows the ApiGateway call to return quickly, satisfying Slack's requirements.
  3. Two AWS Lambdas are created naturally using simple JavaScript functions. One function is used to create the Lambda that is called when Slack pushes a notification. The other is used to specify the Lamdba that will process the messages added to the Topic. These JavaScript functions can easily access the other Pulumi resources created, avoiding the need to figure out ways to pass Resource ARNs/IDs/etc. to the Lambdas to ensure they can talk to the right resources. If these resources are swapped out in the future (for example, using RDS instead of DynamoDB, or SQS instead of SNS), Pulumi will make sure that the Lambdas were updated properly.
  4. Pulumi Secrets provides a simple way to pass important credentials (like your Slack tokens) without having to directly embed them in your application code.

First, we'll set up the Pulumi App. Then, we'll go create and configure a Slack App and Bot to interact with our Pulumi App.

Deploy the App

Note: Some values in this example will be different from run to run. These values are indicated with ***.

Step 1: Create a new stack

$ pulumi stack init mentionbot

Step 2: Set the AWS region

$ pulumi config set aws:region us-east-2

Step 3: Restore NPM modules