News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Can I get DeviceId in Telephony subscription events?
Tags: pubnub, developer sandbox, sdk
Feb 14, 2022 at 2:32am   •   3 replies  •  0 likes
Alex Rogers

I'm using the RingCentral.net SDK. I use basically this code to monitor for my extension's calls:
=================
string s1 = "/restapi/v1.0/account/{0}/extension/~/presence?detailedTelephonyState=true&sipData=true";

string s2 = "/restapi/v1.0/account/{0}/telephony/sessions";

// replace the IDs in the above strings (not shown)

await r.PubNubExtension.Subscribe(new[] {s1, s2}, Device.ParseSubscription);

=================
When I receive the events for the calls, I would like to know which actual device (handset) the call is happening on. I've seen in the traces for outbound calls that "DeviceId" appears in the "body.parties[0].from" field but this value doesn't come through the SDK. Also the value doesn't appear to be present (ie in ".to") for inbound calls.

Also, when making a call, then the deviceid is required to make the call (using CallOut)

So my question is:
Is it possible to get the actual device id for the handset involved in calls?

3 Answers
answered on Feb 17, 2022 at 3:37pm  

Unfortunately, there is no device id in any call stage for inbound call. However, I found a workaround solution below for you.

As soon as you get the "Answered" event of an inbound call, call the endpoint to read active calls for that extension. Set the "view" = Detailed to get the call detailed info. The device id is inside the call legs array at the leg with the direction = "Outbound". Some code snippet in Node JS here

...
subscription.on(subscription.events.notification, function(msg) {
    console.log(JSON.stringify(msg));
    console.log("======");
    if (msg.body.parties[0].status.code == "Answered"){
      readActiveCall(msg.body.telephonySessionId)
    }
});

async function readActiveCall(telSessionId){
  console.log("readActiveCall")
  try {
    var endpoint = `/restapi/v1.0/account/~/extension/~/active-calls`
    console.log(endpoint)
    var resp = await platform.get(endpoint, { view: "Detailed" })
    var jsonObj = await resp.json()
    for (var record of jsonObj.records){
      if (telSessionId == record.telephonySessionId){
        console.log(JSON.stringify(record))
        console.log("=====")
      }
    }
    console.log("+++++++++");
  }catch(e){
    console.log(e.message)
  }
}
// sample response
{
  "uri": "https://platform.ringcentral.com/restapi/v1.0/account/80964xxx/extension/6228832xxx/call-log/QE3d-cD9VKkHzUA?view=Detailed",
  "id": "QE3d-cD9VKkHzUA",
  "sessionId": "777389694016",
  "startTime": "2022-02-17T23:16:51.000Z",
  "duration": 86,
  "type": "Voice",
  "internalType": "LocalNumber",
  "direction": "Inbound",
  "action": "Phone Call",
  "result": "Accepted",
  "to": {
    ...
  },
  "from": {
    ...
  },
  "reason": "Accepted",
  "telephonySessionId": "s-a0d17932e8d6bz17f09f959f4z73533f0000",
  "legs": [
    {
      "startTime": "2022-02-17T23:16:51.000Z",
      "duration": 86,
      "type": "Voice",
      "internalType": "LocalNumber",
      "direction": "Inbound",
      "action": "Phone Call",
      "result": "Accepted",
      "to": {
        ...
      },
      "from": {
        ...
      },
      ...
    },
    {
      "startTime": "2022-02-17T23:16:51.000Z",
      "duration": 86,
      "type": "Voice",
      "internalType": "Sip",
      "direction": "Outbound",
      "action": "VoIP Call",
      "result": "Accepted",
      "to": {
        ...
      },
      "from": {
        "name": "Paco Vu",
        "extensionNumber": "11119",
        "device": {
          "uri": "...",
          "id": "802636634016"
        }
      },
      ...

 0
on Feb 17, 2022 at 3:39pm   •  0 likes

Thank you very much for your help with this.

answered on Feb 15, 2022 at 8:28am  

The device id is reported in the telephony session event payload only for outbound calls. It is included in the event through the .NET SDK. Here is what I got in my test using the .NET SDK

// code snippet
...
var eventFilters = new[]
   {
       "/restapi/v1.0/account/~/extension/~/telephony/sessions"
   };
var subscription = await pubNubExtension.Subscribe(eventFilters, message =>
   {
      Console.WriteLine(message);
      ...
   }

// console 

{....,"parties":[{"accountId":"xxxxx","extensionId":"yyyyy","id":"p-a0d7bfa00bcb8z17efe18a620zabb6420000-1","direction":"Outbound","to":{"phoneNumber":"+1650224xxxx"},"from":{"phoneNumber":"+1720386xxxx","extensionId":"yyyy","deviceId":"802404926016"},"status":{"code":"Setup","rcc":false},"park":{},"missedCall":false,"standAlone":false,"muted":false}],"origin":{"type":"Call"}}}
----
{....,"parties":[{"accountId":"xxxx","extensionId":"yyyy","id":"p-a0d7bfa00bcb8z17efe18a620zabb6420000-1","direction":"Outbound","to":{"phoneNumber":"+1650224xxxx"},"from":{"phoneNumber":"+172038xxxx","extensionId":"yyyy","deviceId":"802404926016"},"status":{"code":"Proceeding","rcc":false},"park":{},"missedCall":false,"standAlone":false,"muted":false}],"origin":{"type":"Call"}}}
----
{...,"parties":[{"accountId":"xxxx","extensionId":"yyyy","id":"p-a0d7bfa00bcb8z17efe18a620zabb6420000-1","direction":"Outbound","to":{"phoneNumber":"+1650224xxxx"},"from":{"phoneNumber":"+1720386xxxx","extensionId":"yyyy","deviceId":"802404926016"},"status":{"code":"Answered","rcc":false},"park":{},"missedCall":false,"standAlone":false,"muted":false}],"origin":{"type":"Call"}}}
----
{....,"parties":[{"accountId":"xxxx","extensionId":"yyyy","id":"p-a0d7bfa00bcb8z17efe18a620zabb6420000-1","direction":"Outbound","to":{"phoneNumber":"+1650224xxxx"},"from":{"phoneNumber":"+1720386xxxx","extensionId":"yyyy","deviceId":"802404926016"},"status":{"code":"Disconnected","rcc":false},"park":{},"missedCall":false,"standAlone":false,"muted":false}],"origin":{"type":"Call"}}}

 0
on Feb 15, 2022 at 3:06pm   •  0 likes

Thank you, Phong Vu, for your answer.

So, the deviceId is only present for outbound calls.

Will it ever likely be presented for inbound calls too?

on Feb 17, 2022 at 12:57pm   •  0 likes

For inbound calls, I am not sure if it would be included for a call to a digital line (e.g. a desk phone). If you have one, please try to call that number and see if the device id is included. However, I doubt that it would be there because an incoming call will ring all the devices that a user is currently login.

on Feb 17, 2022 at 2:31pm   •  0 likes

Thank you, Phong Vu.

I have a variety of devices and none of them receive the deviceId on incoming calls.

However, I should point out that I don't need the deviceId on "Ringing". As you say several devices are ringing. I want to know the deviceId on "Connected". That is, I want to know which of the devices actually answered the call. But still I don't get the deviceId at this point either.

answered on Feb 14, 2022 at 1:54pm  

What type of device are you using? Today you can only get device IDs for Softphone , Hard Phone devices via Device endpoint https://developers.ringcentral.com/api-reference/Devices/listExtensionDevices


Unfortunately , you will not be able to get deviceIDs for RC App or Web-phone apps .


 0
on Feb 14, 2022 at 2:24pm   •  0 likes

Thanks, vyshakhbabji. For this scenario, I am using a variety of devices, hence why I'd like to identify which one is used in the call. I'm using RC Phone, WebPhone, HardPhone and Softphone. However, for me, I don't see any deviceIds in the events, except for Outbound calls as indicated and even then it doesn't come through the .Net SDK.



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us