The previous article introduced how to obtain the online status of users. In this article, we introduced how to count the call records of users.
First, for the sake of security, Teams requires the app to have {callrecords Read. All permissions. Then you can get call record through this api.
GET /communications/callRecords/{id}
This interface will return data similar to the following:
{ "@odata.context": "https://graph.microsoft.com/beta/$metadata#communications/callRecords/$entity", "version": 1, "type": "groupCall", "modalities": [ "audio" ], "lastModifiedDateTime": "2020-12-25T19:00:24.582757Z", "startDateTime": "2020-12-25T18:52:21.321Z", "endDateTime": "2020-12-25T19:52:46.123Z", "id": "e523d2ed-1111-4b6b-925b-754a88034cc5", "organizer": { "user": { "id": "821809f5-0000-0000-0000-3b5136c0e777", "displayName": "Abbie Wilkins", "tenantId": "dc368399-474c-4d40-900c-6265431fd81f" } }, "participants": [ { "user": { "id": "821809f5-0000-0000-0000-3b5136c0e777", "displayName": "Abbie Wilkins", "tenantId": "dc368399-474c-4d40-900c-6265431fd81f" } }, ... ] }
It can be seen that we can find the participants through "organizer" and "participants". We can record the user id of the user. At the same time, we can also get the start and end time of the call through "startDateTime" and "endDateTime".
In fact, the call record in Teams is much more complex than we thought. A call may consist of multiple session s. Let's take a look at an official data model diagram.
We can add parameters to the above api to get the session.
GET https://graph.microsoft.com/beta/communications/callRecords/{id}?$expand=sessions
{ "@odata.context": "https://graph.microsoft.com/beta/$metadata#communications/callRecords(sessions(segments()))/$entity", "startDateTime": "2020-02-25T18:52:21.2169889Z", "endDateTime": "2020-02-25T18:52:46.7640013Z", "organizer": { ... }, "participants": [ ... ], "sessions": [ { "modalities": [ "audio" ], "startDateTime": "2020-02-25T18:52:21.2169889Z", "endDateTime": "2020-02-25T18:52:46.7640013Z", "id": "e523d2ed-2966-4b6b-925b-754a88034cc5", "caller": { "@odata.type": "#microsoft.graph.callRecords.participantEndpoint", "userAgent": { "@odata.type": "#microsoft.graph.callRecords.clientUserAgent", "headerValue": "RTCC/7.0.0.0 UCWA/7.0.0.0 AndroidLync/6.25.0.27 (SM-G930U Android 8.0.0)", "platform": "android", "productFamily": "skypeForBusiness" }, "identity": { "@odata.type": "#microsoft.graph.identitySet", "user": { "id": "821809f5-0000-0000-0000-3b5136c0e777", "displayName": "Abbie Wilkins", "tenantId": "dc368399-474c-4d40-900c-6265431fd81f" } } }, "callee": { "@odata.type": "#microsoft.graph.callRecords.participantEndpoint", "userAgent": { "@odata.type": "#microsoft.graph.callRecords.clientUserAgent", "headerValue": "UCCAPI/16.0.12527.20122 OC/16.0.12527.20194 (Skype for Business)", "platform": "windows", "productFamily": "skypeForBusiness" }, "identity": { "user": { "id": "f69e2c00-0000-0000-0000-185e5f5f5d8a", "displayName": "Owen Franklin", "tenantId": "dc368399-474c-4d40-900c-6265431fd81f" } }, "feedback": { "rating": "poor", "tokens": { "NoSound": false, "OtherNoSound": false, "Echo": false, "Noisy": true, "LowVolume": false, "Stopped": false, "DistortedSound": false, "Interruptions": false } } } } ] }
From the json returned above, you can see that there are , startDateTime , and , endDateTime , in the session. There are also , caller , and , callee. We use these data for further in-depth statistics, and we can see the devices used by each user to participate in the call (userAgent.platform). What's more interesting is that there is , feedback , whether the sound quality of this user's call is good or bad, whether there is noise, etc. With this information, I believe you have a large number of statistical points in your mind.
When you see this, you may ask, the above interface is to obtain a call record. How can I obtain all records?
Here you need to use the subscription function of the graph api.
POST https://graph.microsoft.com/beta/subscriptions
{ "changeType": "created", "notificationUrl": "https://<<your api url>>", "resource": "/communications/callRecords", "expirationDateTime":"2016-11-20T18:23:45.9356913Z", "clientState": "secretClientValue", "latestSupportedTlsVersion": "v1_2" }
The above "resource" is / communications/callRecords, indicating that if any call occurs, the graph api will call back our interface. The above "notificationurl": "HTTPS: / / < < your API url > >" is the callback url of your service. We can get the corresponding call record id in this interface and record it. After a call is completed for a period of time, we can get the information of the whole call.