How to Get a New Call Recording Notification?

Phong Vu
Phong Vu
Aug 2, 2018 · 6 min read
Image for post
Image for post

RingCentral push notification is an event listener service which allows RingCentral customers to subscribe for getting notification of an event when something happens to their RingCentral account. Those events such as when there is an incoming SMS message, when a user receives an incoming call, or when a user status has changed, etcetera.

However, there is no push notification for the event of a new call recording has been created. In this blog, I am going to show you how to use the Account Presence Push Notification to detect when there is a new call recording then download the audio file to a local folder.

First of all, we need a RingCentral app with the ReadAccounts permission and get the clientID and clientSecret ready for platform access authentication. If you don’t know how to create a RingCentral app, please read this tutorial.

The Account Presence Event provides us with different user statuses. In this application, we are interested only at the telephonyStatus which has the following value:

‘NoCall’ | ‘CallConnected’ | ‘Ringing’ | ‘OnHold’ | ‘ParkedCall’

When an extension (a user) under an account has no active call, its telephonyStatus is ‘NoCall’. When there is an incoming or outgoing call on an extension, the telephonyStatus is changed from ‘NoCall’ to ‘Ringing’. Then, if the incoming/outgoing call is accepted, the telephonyStatus is changed again from ‘Ringing’ to ‘CallConnected’. Now, when the call is terminated, the telephonyStatus will be changed from ‘CallConnected’ to ‘NoCall’.

With these statuses change sequence, we can implement our application to detect and follow the status change to determine when an active call is terminated. During the call, if the user enabled the call recording, then it takes around 20 seconds after the call ended, for the system to finalize the call record and save it to the call logs database. At that point in time, we can call the call-log API to check if there is a call recording logged for that extension during the period of time of that call.

Let’s see how we implement that in our code using the Node JS SDK.

First, we create the SDK instance and retrieve the platform and the subscription objects.

Then, we implement a login function to login our RingCentral account

Please note that we want to get events of all extensions (users) under the same company account. Therefore, the username and password we used for logging in the account must be from a user who has the admin role or the main company user.

Subscribe for push notification

After logged in successfully, we call the subscribeForNotification() function to register for the account presence event push notification.

Within the subscribeForNotification() function, we register for the account presence event.

Then we set a callback function to receive notification message.

Detect presence event

Whenever there is a presence event notification, the callback function is called and we parse the msg.body to access the presence event payload. There are many data fields from the payload, but in this particular application, we are interested at only the extensionId which will be used to identify a user, and the telephonyStatus which will be used to detect the current telephone status of the user.

Now, we implement the checkTelephonyStatusChange() function to determine an incoming call, an active call and finally, the call termination. Remember that we are getting notification for all users under the same account, that is why we will need a list of users to keep track of each user statuses.

When there is no telephone call, the telephony status of a user is ‘NoCall’. So when there is an incoming call to a phone number of that user, the telephony status is changed from ‘NoCall’ to ‘Ringing’. If there is no answer to the incoming call, the telephony status will be changed from ‘Ringing’ to ‘NoCall’. If the user accepts an incoming call, the telephony status will be changed from ‘Ringing’ to ‘CallConnected’.

Inside the checkTelephonyStatusChange() function above, we examine the telephony status of a user. We also check if that user has been added to the users list. If the user is found from the list, we check the following status sequence:

1. If the old telephony status of that user is ‘NoCall’ and the new telephony status is ‘Ringing’, then we create a timestamp and add it to the user object. At this point in time, the user object would have the user extension id, the current telephony status as ‘Ringing’ and the timestamp when it starts ringing.

2. If the old telephony status of that user is ‘Ringing’ and the new telephony status is ‘CallConnected’, then we replace the old telephony status with the new value ‘CallConnected’ and wait for the telephony status changed again. At this point in time, the user object would have the user extension id, the current telephony status as ‘CallConnected’ and the timestamp when it starts ringing.

3. If the old telephony status of that user is ‘CallConnected’ and the new telephony status is ‘NoCall’, then we replace the old telephony status with the new value of ‘NoCall’, and we assume that the call has been terminated. Now, we create the stopTime timestamp and we wait for about 20 seconds before calling the readExtensionCallLogs(extensionId, startTime, stopTime) function, where we will call the call-log API to detect a call recording.

If the user is not found from the list, we assume that the old telephony status is ‘NoCall’ and we detect if the current telephony status of that user is ‘Ringing’ then we create the timestamp and add it to the user object then add the user object to the users list. At this point in time, the user object would have the user extensionId, the current telephony status as ‘Ringing’ and the timestamp when it starts ringing.

Read extension call logs

When calling the readExtensionCallLogs() function, we passed the extensionId, the startTime when the call started ringing, and the stopTime when the call terminated. We use the extensionId to create an endpoint for reading the call log of that particular extension. We also specify the startTime and the stopTime for the dateFrom and dateTo query parameters respectively, to fetch call log information within that period of time. It is the period of time between the call started ringing and the call terminated.

We also want to read call log which has a call recording only. To do that, we set the value of the recordingType parameter to ‘All’.

Now, we read the call log and iterate through the records array to find a new call recording.

Finally, it’s up to us to process the call log information and the call recording content. In this application, we save the call recording binary file to a local folder.

You can follow the step by step tutorial or clone the full project from our Github repository.

Learn more about our Developer Program here: https://developer.ringcentral.com/

RingCentral Developers

Cloud Business Communications

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store