Match the Ringout Call in Call-log records

Vyshakh Babji
RingCentral Developers

--

When you initiate a Ringout via Softphone or Click To Call using /ring-out API endpoint, it initiates 2 legs of the call. One of them is an inbound call to the “from” number and then a second leg to the “to” number. For more details on what Ringout is and how to start using it go here.

For you to associate the Ringout calls to the call-log records, you will need to run Subscription with /presence event filter with query parameter detailedTelephonyState=true. To learn how to set up a subscription make sure to read these two articles: Article on Presence API and Article on WebHooks

Below are the steps for matching Ringout calls in CallLog records:

  1. Initiate Subscription:

Run Subscription using WebHooks or Pubnub by subscribing to Presence Event Filter. This is how the response looks like when you do a post to subscription for Pubnub:

Request:

POST https://platform.ringcentral.com/restapi/v1.0/subscription{
"eventFilters": [
"/restapi/v1.0/account/~/extension/~/presence?detailedTelephonyState=true"
],
"deliveryMode": {
"transportType": "PubNub",
"encryption": "true"
}
}

Response:

{
"uri": "https://platform.ringcentral.com/restapi/v1.0/subscription/fddc8b91-2a16-49da-97e8-e2334a8fe61f",
"id": "fddc8b91-2a16-49da-97e8-e2334a8fe61f",
"creationTime": "2019-06-26T20:39:27.024Z",
"status": "Active",
"eventFilters": [
"/restapi/v1.0/account/809646016/extension/809646016/presence?detailedTelephonyState=true"
],
"expirationTime": "2019-06-26T20:54:27.024Z",
"expiresIn": 899,
"deliveryMode": {
"transportType": "PubNub",
"encryption": true,
"address": "1087876542488493_abec10bc",
"subscriberKey": "sub-c-b8b9cd8c-e906-11e2-b383-02ee2ddab7fe",
"encryptionAlgorithm": "AES",
"encryptionKey": "4NVeN/AxLM0/HQL5zFzYJQ=="
}
}

2. Initiate a Ringout:

As I mentioned earlier in this post, Ringout is a 2 legged call. The first leg is an inbound call to “from” number and the second leg is an outbound call to “to” number.

Request:

POST /restapi/v1.0/account/1133926004/extension/1133926004/ring-out  {
"from": {
"phoneNumber": "+17203861294*101"
},
"to": {
"phoneNumber": "+16505154891"
},
"playPrompt": true
}

Response:

{
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/809646016/extension/809646016/ring-out/s-a931a3de3db64089ab075b6358074d30",
"id": "s-a931a3de3db64089ab075b6358074d30",
"status": {
"callStatus": "InProgress",
"callerStatus": "InProgress",
"calleeStatus": "InProgress"
}
}

3. Listen and Pick event notification that suits your use-case:

For this example I decided to pick “telephonyStatus”: “CallConnected” for the notification method. You could also have picked “telephonyStatus”: “NoCall” as the notification method as well. You will find the sessionID for this Ringout call in this notification. You can add the sessionID to your database or a table to maintain all the necessary information from these notifications, which could be useful for call matching. As a best practice I suggest that you also keep track of “extensionId”, “timestamp”, “sessionId”, and “startTime” for each active call records from the notification.

*************** SUBSCRIPTION NOTIFICATION: ****************
{
"uuid": "2155205627849528355",
"event": "/restapi/v1.0/account/809646016/extension/809646016/presence?detailedTelephonyState=true",
"timestamp": "2019-06-26T20:49:15.035Z",
"subscriptionId": "04b96d0a-bc80-4245-9fde-4017e7510a55",
"ownerId": "809646016",
"body": {
"extensionId": 809646016,
"telephonyStatus": "CallConnected",
"activeCalls": [
{
"id": "49fa405fc2b34fd2935cfdbad3db43c1",
"direction": "Outbound",
"from": "+16505154891",
"to": "+17203861294",
"telephonyStatus": "CallConnected",
"sessionId": "235163626016",
"startTime": "2019-06-26T20:49:04.715Z",
"partyId": "p-7f23706e161647d3a6a36249b8772a2c-1",
"telephonySessionId": "s-7f23706e161647d3a6a36249b8772a2c"
},
{
"id": "e3977faeb67f45dfa7be71f0196b73a3",
"direction": "Inbound",
"fromName": "Anonymous",
"from": "anonymous",
"toName": "TESTER Babji",
"to": "101",
"telephonyStatus": "CallConnected",
"sessionId": "235163639016",
"startTime": "2019-06-26T20:49:09.819Z",
"partyId": "p-b39c26323c964190aea973a948ff5798-3",
"telephonySessionId": "s-b39c26323c964190aea973a948ff5798"
}
],
"sequence": 1252,
"presenceStatus": "Busy",
"userStatus": "Available",
"dndStatus": "TakeAllCalls",
"meetingStatus": "Disconnected",
"message": "This is s Test",
"allowSeeMyPresence": true,
"ringOnMonitoredCall": true,
"pickUpCallsOnHold": true,
"totalActiveCalls": 2
}
}

4. Pull call-log and match the records:

When you pull the call-records with detailed view, the records show the exact details of the call flow along with information on each leg of the call. You could match the active call records of the subscription notification to call-log records by matching the sessionIDs of the call. However, if you need all the information on each leg of the call, I would suggest you use the account-level call log.

Request:

GET /restapi/v1.0/account/~/extension/~/call-log 

Response:

{
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/809646016/extension/809646016/call-log?view=Detailed&page=1&perPage=100",
"records": [
{
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/809646016/extension/809646016/call-log/E3PIkjJolHk_zUA?view=Detailed",
"id": "E3PIkjJolHk_zUA",
"sessionId": "235163626016",
"startTime": "2019-06-26T20:49:04.907Z",
"duration": 20,
"type": "Voice",
"direction": "Outbound",
"action": "RingOut PC",
"result": "Call connected",
"to": {
"phoneNumber": "+17203861294",
"extensionNumber": "101",
"location": "Georgetown, CO"
},
"from": {
"extensionId": "809646016",
"name": "TESTER Babji"
},
"extension": {
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/809646016/extension/809646016",
"id": 809646016
},
"transport": "PSTN",
"lastModifiedTime": "2019-06-26T20:49:46.209Z",
"billing": {
"costIncluded": 0,
"costPurchased": 0
},
"legs": [
{
"startTime": "2019-06-26T20:49:04.715Z",
"duration": 20,
"type": "Voice",
"direction": "Outbound",
"action": "RingOut PC",
"result": "Accepted",
"to": {
"phoneNumber": "+16505154891",
"location": "South San Francisco, CA"
},
"from": {
"phoneNumber": "+17203861294",
"extensionNumber": "101",
"extensionId": "809646016",
"name": "TESTER Babji"
},
"extension": {
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/809646016/extension/809646016",
"id": 809646016
},
"reason": "Accepted",
"reasonDescription": "The call connected to and was accepted by this number.",
"transport": "PSTN",
"billing": {
"costIncluded": 0,
"costPurchased": 0
},
"legType": "RingOutClientToSubscriber"
},
{
"startTime": "2019-06-26T20:49:04.907Z",
"duration": 20,
"type": "Voice",
"direction": "Outbound",
"action": "RingOut PC",
"result": "Call connected",
"to": {
"phoneNumber": "+17203861294",
"extensionNumber": "101",
"location": "Georgetown, CO"
},
"from": {
"extensionId": "809646016",
"name": "TESTER Babji"
},
"extension": {
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/809646016/extension/809646016",
"id": 809646016
},
"transport": "PSTN",
"legType": "RingOutClientToCaller",
"master": true
}
]
}
],
"paging": {
"page": 1,
"perPage": 100,
"pageStart": 0,
"pageEnd": 0
},
"navigation": {
"firstPage": {
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/809646016/extension/809646016/call-log?view=Detailed&page=1&perPage=100"
},
"lastPage": {
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/809646016/extension/809646016/call-log?view=Detailed&page=1&perPage=100"
}
}
}

That's it. Now you are ready to rock and roll :)

For more awesome tutorials checkout our blog, or to learn more about the RingCentral Developers Program and start building cool integrations with voice, SMS, team messaging, meetings fax, and more — visit https://developers.ringcentral.com/

--

--