Created
December 6, 2018 07:50
-
-
Save tylerlong/9eb01cd96a907ae7afe4f1952178165d to your computer and use it in GitHub Desktop.
PubNub incoming call demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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