如何通过Graft API识别Microsoft Teams一对一通话的主叫与被叫参与者
识别Microsoft Teams一对一通话的主叫/被叫参与者
要确定一对一通话的发起方,你可以通过Microsoft Graph API的通话记录端点获取关键信息,具体操作如下:
调用
GET /communications/callRecords/{callRecordId}获取该通话的完整记录。返回的callRecord对象里,historyItems数组的第一条记录包含通话发起的核心细节:direction字段:标记通话为outgoing(呼出)或incoming(呼入)source字段:对应发起通话的参与者IDtargets数组:对应被叫的参与者ID
结合返回结果中的
participants数组,通过source里的ID匹配到具体的参与者身份信息(姓名、邮箱等),该参与者就是主叫方;targets中匹配到的对象则是被叫方。
示例代码(PowerShell)
# 替换为目标通话的记录ID $callRecordId = "12345678-1234-1234-1234-1234567890ab" # 调用Graph API拉取通话记录 $callRecord = Invoke-MgGraphRequest -Method Get -Uri "https://graph.microsoft.com/v1.0/communications/callRecords/$callRecordId" # 匹配主叫方信息 $initiator = $callRecord.participants | Where-Object { $_.id -eq $callRecord.historyItems[0].source.id } # 匹配被叫方信息 $recipient = $callRecord.participants | Where-Object { $_.id -ne $initiator.id } # 输出结果 Write-Host "主叫: $($initiator.identity.displayName) ($($initiator.identity.user.principalName))" Write-Host "被叫: $($recipient.identity.displayName) ($($recipient.identity.user.principalName))"
注意:一对一通话的historyItems通常仅包含一条核心发起记录,无需处理多条历史项的情况。如果依赖Teams客户端本地数据,目前没有公开接口直接暴露发起方信息,Graph API是最可靠的解决方案。
内容的提问来源于stack exchange,提问作者Antonio Navarro Ortin
相关产品推荐
相关产品推荐

