DO NOT USE IN PRODUCTION. THIS IS FOR LEARNING ONLY, OKAY?
In Slack, I want to know the timezone of a city right now.
Type:
timezone Sydney, Australia
or more generically
timezone {city, state, country}
git clone https://github.com/joemccann/timezone-slack-bot-aws-lambda.git && cd timezone-slack-bot-aws-lambda
npm i
zip -r timezone-lambda.zip timezone-lambda.js timezone-search.js node_modules
aws lambda create-function \
--region us-west-2 \
--function-name timezone-lambda \
--zip-file fileb://timezone-lambda.zip \
--role arn:aws:iam::500402104533:role/APIGatewayLambdaExecRole \
--handler timezone-lambda.handler \
--runtime nodejs \
--memory-size 512 \
--timeout 10 \
--description "Lambda function to get the timezone of a location."
If you make changes to the code, run this to update and deploy to AWS.
zip -r timezone-lambda.zip timezone-lambda.js timezone-search.js node_modules && aws lambda update-function-code --function-name timezone-lambda --zip-file fileb://timezone-lambda.zip
curl -H "Content-Type: application/json" -X POST -d "{\"text\": \"timezone new york city\"}" https://xuq8c563mi.execute-api.us-west-2.amazonaws.com/test/get-timezone-time
Create a New API
Create a New Resource (get-timezone-time
)
Create a New Method (POST
)
NOTE: We need to setup a mapping template because Slack sends application/x-www-form-urlencoded
not json
:
https://gist.github.com/joemccann/e5957762ff2515daab27eea1b7d10e81
In API Gateway ( Method Execution/get-timezone-time - POST - Integration Request )
Deploy your API. Copy the URL that appears and save for later.
Need to add custom Slash command:
https://nodesource.slack.com/apps/
Follow the process for adding the new Slash command including the URL from your API gateway.
MIT (see LICENSE file)