Schedule your Slack messages.
/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
- e.g.
/slist [inline]
or/send list [inline]
- List scheduled messages. Appendinginline
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
Below is a screenshot from Slack once the API is deployed and added as a Slack app.
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.
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.
- Follow the instructions at https://serverless.com/framework/docs/providers/aws/guide/credentials/ . They cover the setup pretty well.
- 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
- Attach Managed Policies:
{
"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.
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:
- Create an API Key - https://console.aws.amazon.com/apigateway/home?region=us-east-1#/api-keys
- Create a Usage Plan - https://console.aws.amazon.com/apigateway/home?region=us-east-1#/usage-plans
- Add the API (
ec2-remote-dev
) and API Key you created to the Usage Plan.
- Add the API (
- Update
private
totrue
in theserverless.yaml
method definition for theunread
function - Make API calls with the Request Header
x-api-key: APIKEY
. - Example:
curl -H "x-api-key: AWS_API_KEY" https://API_ID.execute-api.us-east-1.amazonaws.com/dev/ec2/status/INSTANCE_NAME
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
- Use the URL below for each command
- 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
- Add Permission Scopes
- Navigate to: Interactive Components
- Interactivity
- URL: /dev/slack/send/actions
- Message Menus
- URL: /dev/slack/send/options
- Interactivity
- 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
- SDK
- API
- NLP
- Dates
- Javascript
- Javascript
- Env Variables
- DynamoDB
- JS
- Guide
- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html
- https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html#WorkingWithItems.WritingData
- https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html
- API
- Web