A serverless Slack Slash Commands to integrate Google Knowledge Graph API using AWS Lambda and AWS API Gateway.
This project was built with Ryan Ray's repo slack-lambda-weather and his post.
- Install AWS CLI
- Create a
config.jsonbased onconfig.sample.json. This file is gitignored by default because this is where you would put any API key's, AWS settings, and other secret info that your lambda may need. - Google Knowledge Graph Search API API key, and paste it to
config.json.
npm installLambda is based on EC2 and allows you to deploy and execute your code (Node.js, Java, Python) without having to provision servers.
Deploy and update your Lambda code:
npm startNew: v0.4.0
- Goto AWS SNS
- Slect Topics, click Create new topic
- Input your Topic name, and create
- Create Subscription
- Select Protocol to AWS Lambda
- Select Endpoint to your Lambda function
- Click Create Subscription to complete
- Goto Lambda to create a function to send Slack event for SNS, to copy and modify
sns.sample.jscode
Lambda responds to events, which can come from a variety of sources. By default Lambda isn't accessable from a URL, but API Gateway allows you to map a URL and an HTTP method to trigger your Lambda code. You can setup GET, POST, PUT, etc... and map the parameters/body into a JSON payload that Lambda understands.
- Goto AWS API Gateway and Create new API - name it whatever you want - we'll do LambdaTest for now
- Create a new resource, name it whatever
- Create a POST method under your resource
- Select Integration type with Lambda Function, and select your Lambda region, and enter your Lambda function name from step SNS
- Save and give API Gateway permission to invoke your Lambda function
- Click on Integration Request > Mapping Templates
- Add mapping Template for
application/x-www-form-urlencodedand click checkmark - Change input passthrough to mapping template and paste this template gist that can help you to convert
application/x-www-form-urlencodedPOST from Slack to Lambda'sapplication/jsonformat - Save and click Deploy API with a new stage, then you can see a public invoke URL
- Goto Slack App
https://YOUR_TEAN_DOMAIN.slack.com/apps/manage - Search
Slash Commandsand add a new configuration - Choose a command, for this example enter
/googlein the command name input, click Add Slash Command Integration button. - Now you should be on the settings page, scroll down and copy the token to your
config.json(NOTE: you don't want to expose the token to the public!). - Copy and paste your API Gateway invoke URL to URL field.
Improvements are welcome! Just fork, push your changes to a new branch, and create a pull request!



