Created
December 27, 2018 01:14
-
-
Save tylerlong/c26ea217302b2018d415ac93fe63fe63 to your computer and use it in GitHub Desktop.
RingCentral call control API PubNub to get sessionId and partyId
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)) | |
const activeCall = message.body.activeCalls[0] | |
if (activeCall.telephonyStatus !== 'Ringing') { | |
return | |
} | |
const telephonySessionId = activeCall.telephonySessionId | |
const partyId = activeCall.partyId | |
}) | |
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