Invite people to Slack using AWS Lambda and the Serverless framework.
- Create a new Serverless project using this repository
- Generate AWS tokens for Serverless to deploying Lambda functions
- Generate API token for controlling Slack
- Add Slack API token and domain to your Serverless environment
- Deploy API to AWS Lambda
- (usually) Add a HTML form to your website for requesting automatic invites
You need Node.JS and NPM installed. Newer serverless versions might work too, but this is what I have tested:
$ npm install -g [email protected]
$ sls install -u https://github.com/amv/serverless-slack-invite-api -n my-slack-api
$ cd my-slack-api
$ npm install
Go to the Serverless.com Quick start guide and set up your Access Key ID and Secret Access Key as instructed.
Visit OAuth Tokens for Testing -page to generate yourself a test token for Slack.
Edit your serverless.yml
and replace the following variables with your data: slack_domain
, slack_token
. There is a # NOTE
comment above the variables so that you can find them easier.
$ serverless deploy
Note the output of the last command, where you can get the URL for your API.
To invite a new user, send a POST request with 'Content-Type: application/json' to the invite endpoint that you got from the previous section.
The content of the POST request should be a JSON object that contains an "email" attribute. Here is an example with curl:
$ curl -X POST -H 'Content-Type: application/json' -d '{ "email" : "[email protected]" }' https://fav7ffggds.execute-api.us-east-1.amazonaws.com/production/invite
Under the "examples" directory you can find an example index.html file that showcases how to build a simple public subscription page using jQuery.
The endpoint has permissive CORS headers, so once you edit the index.html to contain the correct execute-api domain in the "settings" -object, you can open if locally with a browser and test the API out.
In OS X:
$ open examples/index.html
In Windows:
$ start examples/index.html
In Linux:
$ xdg-open examples/index.html