A single serverless function using the Serverless framework to handle slack invites via POST.
- a single HTTP POST endpoint to invite new users
Install the serverless-cli.
$ npm i -g serverless
Set the config credentials. This will write a new AWS config file to ~/.aws/credentials
.
$ serverless config credentials --provider aws --key key_123 --secret secret_123
Clone the repo and navigate into it.
$ git clone git@github.com:stefanjudis/serverless-slack-invite.git
$ cd serverless-slack-invite
Install dependencies.
$ npm install
Deploy the serverless function with an access token and your organization sub domain for slack. 🎉
$ SLACK_TOKEN=slack_token SUB_DOMAIN=slack_subdomain serverless deploy
And you're done. The deployment will tell you where your new serverless endpoint will be located so that you can use it via Ajax.
Now that you have the endpoint running in the cloud you can write invite users via XHR.
// jQuery is available in this environment
$.post(
'#{slack_invite_url}',
{ email: this.email.value }
).done( function( data ) {
try {
var response = JSON.parse(data.body)
if ( response.ok ) {
showSuccess();
} else {
showError( response.error );
}
} catch( error ) {
showError();
}
}).fail( function() {
showError();
})