Easier Private Glip Bots

Tyler Liu
RingCentral Developers
3 min readSep 4, 2018

We are always trying to make developing on RingCentral easier and we have just updated our Glip bot provisioning process for private bots so that you no longer need to implement OAuth or manage a redirect URL. When creating a private bot, you can generate an access token directly within the developer portal and use it in your bot.

This makes the development and deployment process easier for the following reasons:

  • No more need to redirect URI to your bot
  • No more need to add a custom redirect URI to your bot configuration
  • No more need to potentially open up a firewall route to your bot

Breaking change notice: While this approach is much easier to implement for private bots, the redirect URI now requires the use of the POST HTTP method while previously, the GET method was supported. Almost all previous bot tutorials will need to be updated, including this one from me: Latest Glip Bot Provisioning Flow.

Now I am going to show you the changes and the adjustment necessary to create a new Glip bot. I would like to divide the topic into three parts:

  • What has changed?
  • What is the solution?
  • Tutorials to create Glip bots

What has changed?

The way a bot get its access token has changed. Previously, all the bots follow the standard OAuth authorization code flow to get a token.

Nowadays, the access token retrieval flow is the same as before for public bots. But a private bot has a different flow. Since new bots are by default private (if you don’t change the default settings when creating a bot), this has a huge impact.

  • Private Bot: it’s no longer necessary to specify a custom redirect URI. A redirect URI is still required though. You can simply use the default one: https://www.ringcentral.com. After you add your bot to Glip, the token will be shown directly on the GUI. So that you can copy and use it. If you do specify a custom redirect URI, make sure that the URI could handle an HTTP POST request with content type form-data-url-encoded. Access token is included in the request.
  • Public Bot: you must specify a custom redirect URI. And when a bot is added to Glip successfully, the redirect URI will be invoked by a HTTP GET request with thecode parameter. And you can exchange the code for an access token. This process is the same as before.

This also explains why the Glip for Hubot adapter stopped working. For private bot, the redirect URI must handle a HTTP POST request instead of a HTTP GET request.

What is the solution?

It depends on what kind of bots you are writing. Public one or private one? As I explained above: they have different ways to retrieve an access token.

Private Bot

You can set the redirect uri to https://www.ringcentral.com and get the access token right from GUI. Then you can directly add the token to the bot in the code, an environment variable, or via some other method. No coding is needed to get an access token.

If you do want to get the access token programmatically, you can use the following code snippet:

app.post('/oauth', (req, res) => {
this.rc.token(req.body)
fs.writeFileSync('./token.json', JSON.stringify(this.rc.token(), null, 2))
res.send('')
})

Code snippet above is in JavaScript using Express and RingCentral Concise SDK. Here is how it works in the Glip for Hubot adapter: https://github.com/tylerlong/hubot-glip/blob/6691105353521be1e581a724e72b21b12492a800/src/index.js#L32-L37

Public Bot

Here is how you can get an access token:

app.get('/oauth', async (req, res) => {
await this.rc.authorize({
code: req.query.code,
redirectUri: `${process.env.RINGCENTRAL_BOT_SERVER}/oauth`
})
fs.writeFileSync('./token.json', JSON.stringify(this.rc.token(), null, 2))
res.send('')
})

Code snippet above is in JavaScript using Express and RingCentral Concise SDK. Here is how it works in the Glip for Hubot adapter: https://github.com/tylerlong/hubot-glip/blob/6691105353521be1e581a724e72b21b12492a800/src/index.js#L39-L48

Tutorials to create Glip bots

As I said earlier in this blog, most of the tutorials stopped working. I’ve created new tutorials for creating Glip bots using Hubot.

Text based tutorial is in this project’s README file: https://github.com/tylerlong/hubot-glip

There are also two video tutorials as well:

OK, That’s all that I want to cover. Thank you for reading!

--

--