MS Graph API创建Teams机器人PSTN呼叫立即终止故障排查
Microsoft Graph API实现MS Teams机器人PSTN通话故障排查
已完成前置配置
- 在Azure平台注册MS Teams应用与机器人,完成机器人服务注册
- 在Active Directory中为机器人创建对应用户,并为该用户分配电话号码
- 为应用与机器人授予所有通话相关权限
创建PSTN通话的请求体
{ "@odata.type": "#microsoft.graph.call", "callbackUri": "{my-callback-uri}", "source": { "@odata.type": "#microsoft.graph.participantInfo", "identity": { "@odata.type": "#microsoft.graph.identitySet", "applicationInstance": { "@odata.type": "#microsoft.graph.identity", "displayName": "Calling Bot", "id": "{id of bot user with phone number}" } }, "countryCode": null, "endpointType": null, "region": null, "languageId": null }, "targets": [ { "@odata.type": "#microsoft.graph.invitationParticipantInfo", "identity": { "@odata.type": "#microsoft.graph.identitySet", "phone": { "@odata.type": "#microsoft.graph.identity", "id": "+41xxxxxxxxx" } } } ], "requestedModalities": [ "audio" ], "mediaConfig": { "@odata.type": "#microsoft.graph.serviceHostedMediaConfig" }, "tenantId": "{tenant-id}" }
接口初始响应
请求发起后接口立即返回响应,呼叫状态为establishing:
{ "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#communications/calls/$entity", "id": "{call-id}", "state": "establishing", "transferState": null, "terminationReason": null, "direction": "outgoing", "ringingTimeoutInSeconds": null, "subject": null, "callbackUri": "{my-callback-uri}", "requestedModalities": [ "audio" ], "activeModalities": [], "routingPolicies": [], "tenantId": "{tenant-id}", "myParticipantId": "{participant-id}", "callChainId": "{callChain-Id}", "mediaHostedRegion": null, "mediaState": null, "resultInfo": null, "answeredBy": null, "chatInfo": null, "meetingInfo": null, "transcription": null, "callOptions": null, "meetingCapability": null, "breakoutDetails": null, "pstnDetails": null, "toneInfo": null, "incomingContext": null, "terminationSender": null, "meetingGroupDetails": null, "callRoutes": [], "source": { "endpointType": null, "region": null, "languageId": null, "countryCode": null, "participantId": null, "identity": { "user": null, "phone": null, "guest": null, "encrypted": null, "onPremises": null, "applicationInstance": { "id": "{bot-user-id}", "displayName": "Calling Bot", "tenantId": null, "registrantId": null }, "application": null, "device": null } }, "targets": [ { "endpointType": null, "replacesCallId": null, "hidden": null, "removeFromDefaultAudioRoutingGroup": null, "participantId": null, "identity": { "user": null, "phone": { "id": "+41xxxxxxxxx", "displayName": null, "tenantId": null, "registrantId": null }, "guest": null, "encrypted": null, "onPremises": null, "applicationInstance": null, "application": null, "device": null } } ], "mediaConfig": { "@odata.type": "#microsoft.graph.serviceHostedMediaConfig", "preFetchMedia": [] } }
回调通知结果
回调接口共收到2条通知,最终呼叫终止,返回错误码403、子错误码510559,提示Forbidden. DiagCode: 403#510559.@,呼叫建立后立即终止:
第一条通知(呼叫建立中):
{ "@odata.type": "#microsoft.graph.commsNotifications", "value": [ { "@odata.type": "#microsoft.graph.commsNotification", "changeType": "updated", "resource": "/app/calls/{call-id}", "resourceUrl": "/communications/calls/{call-id}", "resourceData": { "@odata.type": "#microsoft.graph.call", "state": "establishing", "callChainId": "{callChain-id}" } } ] }
第二条通知(呼叫终止):
{ "@odata.type": "#microsoft.graph.commsNotifications", "value": [ { "@odata.type": "#microsoft.graph.commsNotification", "changeType": "deleted", "resource": "/app/calls/{same-call-id}", "resourceUrl": "/communications/calls/{same-call-id}", "resourceData": { "@odata.type": "#microsoft.graph.call", "state": "terminated", "resultInfo": { "@odata.type": "#microsoft.graph.resultInfo", "code": 403, "subcode": 510559, "message": "Forbidden. DiagCode: 403#510559.@" }, "callChainId": "{same-callChain-id}", "terminationSender": { "@odata.type": "#microsoft.graph.identitySet", "phone": { "@odata.type": "#microsoft.graph.identity", "id": "+41xxxxxxxxx", "displayName": "4:+41xxxxxxxxx", "identityProvider": "None" } } } } ] }
对照测试结论
- 相同请求将目标号码替换为分配给MS Teams用户的号码时,呼叫可正常建立
- 同时指定Teams用户号码、PSTN号码为呼叫目标时,仅Teams用户可收到呼叫
- 直接通过MS Teams客户端呼叫该外部PSTN号码可正常接通
已尝试排查方案
已检索微软官方论坛、Microsoft Graph API官方文档及示例仓库GitHub讨论区,未找到该诊断码相关说明及同类问题解决方案,已尝试以下排查操作均未解决问题:
- 调整PSTN号码格式(如
4:+41xxxxxxxxx、071xxxxxxx等),返回结果一致 - 将呼叫源标识替换为机器人ID、应用ID,请求失败
- 尝试创建机器人与外部号码的1:1呼叫,请求失败
- 切换使用Microsoft Graph API Beta版本(
.../beta/communications/calls)发起请求,返回结果一致
补充异常说明
发起呼叫请求时,Visual Studio输出栏会出现如下异常:
Exception thrown: 'Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException' in Microsoft.AspNetCore.Antiforgery.dll Exception thrown: 'Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException' in System.Private.CoreLib.dll Exception thrown: 'Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException' in Microsoft.AspNetCore.Antiforgery.dll Exception thrown: 'Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException' in System.Private.CoreLib.dll
该异常在呼叫Teams用户的正常场景下也会出现,不影响正常呼叫流程。
待解答问题
- 该问题的根因是什么,当前配置存在哪些遗漏?
- DiagCode
403#510559的具体含义是什么? - 通过Microsoft Graph API使用机器人发起PSTN呼叫的支持状态与正确配置要求是什么?
内容的提问来源于stack exchange,提问作者Ascendise
相关产品推荐
相关产品推荐

