Skip to content

Node.js based AWS Lambda & DynamoDB based serverless app to schedule your Slack messages.

License

Notifications You must be signed in to change notification settings

khilnani/slack-send-app.serverless

Repository files navigation

slack-send-app.serverless

Schedule your Slack messages.

Usage

  • /send Message When - The app will parse out the last date mentioned as the schedule date using natural language processing.
    • e.g. /send Hey Jason, don't forget to send me that cool website at 4pm
    • e.g. /send Hey Jason, don't forget to send me that cool website link in 6 hours
  • /slist [inline] or /send list [inline] - List scheduled messages. Appending inline allows you to view the list of scheduled messages across devices in the Slack channel the command is run. Each message includes a message ID and deletion button.
  • /sdelete ID or /send delete ID - Delete a specific message via its ID

Screenshots

Below is a screenshot from Slack once the API is deployed and added as a Slack app.

Setup

OK, lets get started. There are quite a few steps here and you may need 30 mins to 1 hour depending on your familiarity with AWS.

Note

  • The default setup will create a public API endpoint. Take a look at the Private API Setup section to make the API private.
  • The project has been tested on Ubuntu, macOS as well as Bash on Windows 10, with and without Docker.

AWS Setup

Since we're working with DynamoDB, AWS Lambda and AWS API Gateway, we need to setup AWS credentials. We are going to use the Serverless framework to manage the AWS tech stack.

  • The role Serverless needs requires a lot of privilages.
  • The role used to setup and deploy is different from the permissions set on the lambda code that runs.
  • If this concerns you, create a new AWS account to play around with.

Serverless AWS Credentials Setup

Manual AWS IAM Setup

  • Create an IAM Group with:
    • Attach Managed Policies:
      • AmazonEC2FullAccess - Start and stop EC2 instances
      • AWSLambdaFullAccess - Create and manage Lambda functions
      • AmazonS3FullAccess - Create a bucket to store the lambda function code
      • AmazonDynamoDBFullAccess - Manage DynamoDB
      • CloudWatchLogsFullAccess - Create and manage Cloudwatch logs
      • CloudWatchEventsFullAccess - Manage Cloudwatch events
      • AmazonSESFullAccess - Send Emails for alerts
      • AmazonSQSFullAccess - Send and subscribe to queues for alerts
      • AmazonAPIGatewayAdministrator - Create and manage API endpoints
      • IAMFullAccess - Create new role for the Lambda to work with EC2 instances
    • Create Custom Group Policy > Custom Policy:
      • Custom CloudFormation policy (below)- Create and manage CloudFormation stacks
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1499009146000",
            "Effect": "Allow",
            "Action": [
                "cloudformation:*"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
  • Create an IAM User and assign the User the newly created Group
  • Setup AWS credentials with this user's security credentials. Check the above link since it has a good overview.

Private API Setup

In most cases you will want to secure access to this API. We'll do this using an AWS API Key using the steps below:

curl -H "x-api-key: AWS_API_KEY" https://API_ID.execute-api.us-east-1.amazonaws.com/dev/ec2/status/INSTANCE_NAME

Slack Setup

We will need to add the app to you Slack Workspace

  • Create a Slack app - https://api.slack.com/apps?new_app=1
  • Navigate to: Slash Commands
    • Use the URL below for each command
      • URL: /dev/slack/send/command
    • Command: /send
      • Description: Schedule a message to be sent in the future
      • Usage hint: message [when] OR help
    • Command: /slist
      • Description: List iunsent scheduled messages
      • Usage hint: [inline]
    • Command: /sdelete
      • Description: Delete a scheduled message
      • Usage hint: ID
  • Navigate to: OAuth & Permissions
    • Add Permission Scopes
      • bot - Call the bot for help
      • commands - To view, edit and delete scheduled messages
      • chat:write:user - To send your messages as scheduled
      • users.profile:read - Timezone specific message scheduling and formatting
    • Add a Redirect URL:
      • URL: /dev/slack/send/redirect
  • Navigate to: Interactive Components
    • Interactivity
      • URL: /dev/slack/send/actions
    • Message Menus
      • URL: /dev/slack/send/options
  • Navigate to: Event Subscriptions
    • Enable: Enable Events
    • Request URL: /dev/slack/send/event
    • Subscribe to Workspace Events
      • app_uninstalled
      • tokens_revoked
    • Subscribe to Bot Events:
      • app_mention
  • Navigate to: Bot User
    • Display Name: /send-app
    • Username: send-app
    • Always Show My Bot as Online: Yes

Links

Slack

Node.js

AWS

About

Node.js based AWS Lambda & DynamoDB based serverless app to schedule your Slack messages.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published