Skip to content

A serverless Slack Slash Commands to integrate Google Knowledge Graph API using AWS Lambda and AWS API Gateway.

License

Notifications You must be signed in to change notification settings

amowu/slack-lambda-google

Repository files navigation

slack-lambda-google

Google God

A serverless Slack Slash Commands to integrate Google Knowledge Graph API using AWS Lambda and AWS API Gateway.

screenshot

Getting Started

This project was built with Ryan Ray's repo slack-lambda-weather and his post.

sequence diagram

Prerequisites

  • Install AWS CLI
  • Create a config.json based on config.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 install

AWS Lambda

Lambda 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 start

AWS SNS

New: v0.4.0

  1. Goto AWS SNS
  2. Slect Topics, click Create new topic
  3. Input your Topic name, and create
  4. Create Subscription
  5. Select Protocol to AWS Lambda
  6. Select Endpoint to your Lambda function
  7. Click Create Subscription to complete
  8. Goto Lambda to create a function to send Slack event for SNS, to copy and modify sns.sample.js code

AWS API Gateway

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.

  1. Goto AWS API Gateway and Create new API - name it whatever you want - we'll do LambdaTest for now
  2. Create a new resource, name it whatever
  3. Create a POST method under your resource
  4. Select Integration type with Lambda Function, and select your Lambda region, and enter your Lambda function name from step SNS
  5. Save and give API Gateway permission to invoke your Lambda function
  6. Click on Integration Request > Mapping Templates
  7. Add mapping Template for application/x-www-form-urlencoded and click checkmark
  8. Change input passthrough to mapping template and paste this template gist that can help you to convert application/x-www-form-urlencoded POST from Slack to Lambda's application/json format
  9. Save and click Deploy API with a new stage, then you can see a public invoke URL

Slack

  1. Goto Slack App https://YOUR_TEAN_DOMAIN.slack.com/apps/manage
  2. Search Slash Commands and add a new configuration
  3. Choose a command, for this example enter /google in the command name input, click Add Slash Command Integration button.
  4. 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!).
  5. Copy and paste your API Gateway invoke URL to URL field.

Contributing

Improvements are welcome! Just fork, push your changes to a new branch, and create a pull request!

slack-lambda-google-ex

About

A serverless Slack Slash Commands to integrate Google Knowledge Graph API using AWS Lambda and AWS API Gateway.

Resources

License

Stars

Watchers

Forks

Packages

No packages published