Skip to content

Instantly share code, notes, and snippets.

@tylerlong
Created December 6, 2018 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylerlong/9eb01cd96a907ae7afe4f1952178165d to your computer and use it in GitHub Desktop.
Save tylerlong/9eb01cd96a907ae7afe4f1952178165d to your computer and use it in GitHub Desktop.
PubNub incoming call demo
import RingCentral from 'ringcentral-js-concise'
import PubNub from 'ringcentral-js-concise/src/pubnub.es5'
import delay from 'timeout-as-promise'
const rc = new RingCentral(
process.env.RINGCENTRAL_CLIENT_ID,
process.env.RINGCENTRAL_CLIENT_SECRET,
process.env.RINGCENTRAL_SERVER_URL
)
;(async () => {
try {
await rc.authorize({
username: process.env.RINGCENTRAL_USERNAME,
extension: process.env.RINGCENTRAL_EXTENSION,
password: process.env.RINGCENTRAL_PASSWORD
})
console.log(rc.token())
const pubnub = new PubNub(rc, ['/restapi/v1.0/account/~/extension/~/presence?detailedTelephonyState=true'], async message => {
console.log(JSON.stringify(message.body.activeCalls, null, 2))
})
await pubnub.subscribe()
console.log(pubnub.subscription())
await delay(36000000)
} catch (e) {
console.log(e.response.data)
} finally {
await rc.revoke()
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment