Deploy a Glip chatbot to AWS Lambda

Tyler Liu
RingCentral Developers
6 min readFeb 7, 2018

Glip bots

Several days ago, I wrote an article: Latest Glip bot provision flow. In that article, I described the latest process to provision a Glip bot. That article is mainly for beginners and it focuses on development only. And in that article I intentionally simplified the process, just to be more friendly to beginners. I will show you a more comprehensive process.

AWS Lambda

In this article, I will talk about deployment. We will use AWS Lambda because it is a popular platform for serverless computing.

AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume — there is no charge when your code is not running.

With Lambda, you can run code for virtually any type of application or backend service — all with zero administration. Just upload your code and Lambda takes care of everything required to run and scale your code with high availability. You can set up your code to automatically trigger from other AWS services or call it directly from any web or mobile app.

Serverless framework

In this article, we will take advantage of the Serverless Framework.

Serverless is your toolkit for deploying and operating serverless architectures. Focus on your application, not your infrastructure.

Develop, test and deploy in a single environment, to any cloud provider. You don’t have to provision infrastructure or worry about scale. Serverless teams cut time to market in half.

We are not going to cover the basics of the Serverless Framework. Please read the doc here to get started if you want a background: https://serverless.com/framework/docs/getting-started/

Kickstart

It’s tedious to setup a Node.js project from scratch. So we will use a scaffolding tool named kickstart: https://github.com/tylerlong/kickstart

Support projects in all programming languages.

Support any project to be used as template, even they are not created for scaffolding purpose.

Support templating, thanks to nunjucks.

Lots of projects look similar. For example, when I start a new JavaScript projects, I always created the following files: README.md, package.json, .gitignore, .editorconfig, .babelrc...etc.

I wanted a command line utility to create those files for me. I checked the popular Yeoman project but failed to comprehend its authoring workflow. I decided to create a new tool which is both flexible and straightforward.

And we are going to use this kickstart project: https://github.com/tylerlong/kickstart-node-glip-bot

Please get yourself familiar with kickstart tool.

More prerequisites

Before we continue, make sure you have read the content above carefully and you fully understand what they are.

If you have no previous experience with Glip bot development, please read Latest Glip bot provision flow.

If you haven’t created a RingCentral developer account, please sign up here: https://developer.ringcentral.com/ It is free.

Please use Serverless Framework to create a hello world style project and deploy it to AWS Lambda, just to make sure that you have Serverless Framework setup properly and you have a AWS account that you can deploy Lambda functions.

We cannot continue our experiments without the prerequisites above.

Let’s do it!

First of all, go to https://developer.ringcentral.com/ and sign in:

Create a new app:

Choose Server/Bot for Platform Type:

Finish the app creation:

Write some code

If you don’t want to do it yourself, you can simply get the result project here and skip the following steps: https://github.com/tylerlong/aws-lambda-glip-bot

Remember we talked about kickstart above? Please install it if you haven’t done so:

$ yarn global add kickstart-cli

Git clone this project https://github.com/tylerlong/kickstart-node-glip-bot

$ git clone https://github.com/tylerlong/kickstart-node-glip-bot

Cd into kickstart-node-glip-bot directory and edit kickstart.yml:

projectName: aws-lambda-glip-bot

version: 0.1.0

license: MIT

description: A demo Glip bot which will be deployed to AWS Lambda

Run the following command to generate a new project:

$ ks -k . -o ../aws-lambda-glip-bot
$ cd ../aws-lambda-glip-bot

Set up the project:

$ yarn install
$ cp env.sample.yml env.yml

Do the first deploy:

$ yarn deploy:full

And in the output, you will find an endpoint:

Please copy and save the endpoint, we will use it soon.

Now go back to https://developer.ringcentral.com, find the app we just created and switch to its “WebHooks” tab:

Enable the WebHooks and generate a verification token, then paste the endpoint url we just saved to the WebHook URI:

Copy verification token (#2 in the screenshot above). And paste it into the env.yml file of your project:

Please note that, in this tutorial, we only configure the dev part of the env.yml file. We won’t cover the prod stage because it deserves one more blog article.

Deploy again:

$ yarn deploy:full

Now go back to https://developer.ringcentral.com, navigate to the WebHooks tab of the app we created, click the “Verify” button. Make sure verification is successful. Then we are able to see the Subscribe to Events section:

Configure it like above with the Glip:Posts permission and don’t forget to click the Save button.

We need a token in order to make the chatbot work. And we will use the RingCentral token generator tool: https://github.com/tylerlong/ringcentral-token-generator

If you don’t know how to use it, please re-read Latest Glip bot provision flow. Please note that, When you click the “Add to Glip” button, name the bot “aws-lambda-glip-bot”, and we will use this name in the following content of this tutorial. (You can name it whatever but do remember it)

Once you get the token, configure it to the env.yml file:

And deploy again:

$ yarn run deploy:full

Now the chatbot should be up and running. Let’s test it. Go to https://glip.devtest.ringcentral.com/ and login with your sandbox account.

If you cannot find the bot in People list, logout then login again.

Start a conversation with the bot, and send “ping” to it:

The bot replies with the json message it received from you.

Let’s update the code of messages/index.js:

Run yarn run deploy to deploy to AWS Lambda again. And test again:

OK. now we have a Glip bot hosted on AWS Lambda. It could listen to the input and send message back!

That’s all for this tutorial. Now you should have enough knowledge to deploy your Glip bot to AWS Lambda!

--

--