配置团队通过MS Graph API呼叫转发策略

发布于 2025-02-08 06:11:54 字数 7064 浏览 2 评论 0 原文

TL; dr:

设置团队呼叫用户的转发策略的MS图API是什么?

背景:

目前,我正在尝试将基于Lync/Skype的.NET应用程序迁移到团队。 团队相关的部分是关于设置一些特定用户的呼叫转发偏好。 这些用户可以启用直接路由,即您可以调用固定的PSTN/后缀号码,并且用户将在其手机上接收电话。该手机号码取决于轮班,因此该程序将其调整为当时有班次职责的人。

到目前为止,我尝试过什么?

计划B?

Update 2022-06-20

更新2022-06-30

可以改进的POC将看起来像这样(...如果我已经打包到通常的AccearireTokenOkeNonBehalfof中,那么我会添加它作为答案... )

Imports System.IO
Imports Microsoft.Identity.Client
Imports System.Globalization
Imports System.Net.Http
Imports System.Text
Imports System.Net.Http.Headers
Imports System.Net
Imports Newtonsoft.Json
Imports System.IdentityModel.Tokens.Jwt

Public Class LyncTest

    Public Shared Sub Test()
        Dim InstanceId As String = "https://login.microsoftonline.com/"
        Dim RedirectURI As String = "https://login.microsoftonline.com/common/oauth2/nativeclient"

        ' Ids / Secrets and can be found on your Azure application page
        Dim TenantId As String = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
        Dim AppId As String = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
        Dim secretVal As String = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        Dim username As String = "[email protected]"
        Dim password As String = "xxxxxxxxxxxx"
        ' Teams scope
        Dim scope As String = "48ac35b8-9aa8-4d74-927d-1f4a14a0b239/.default"

        Dim httpClient = New HttpClient()

        ' start resource owner password credential flow
        ' see https://learn.microsoft.com/en-us/powershell/module/teams/connect-microsoftteams?view=teams-ps#example-4-connect-to-microsoftteams-using-accesstokens
        Dim baseParam As String =
            $"client_id={AppId}" &
            $"&username={WebUtility.UrlEncode(username)}" &
            $"&password={WebUtility.UrlEncode(password)}" &
            $"&grant_type=password" &
            $"&client_secret={WebUtility.UrlEncode(secretVal)}" &
            $"&scope={scope}"

        ' get user_impersonation token
        Dim tokenReq As New HttpRequestMessage(HttpMethod.Post, $"https://login.microsoftonline.com/{TenantId}/oauth2/v2.0/token") With {
            .Content = New StringContent(baseParam, Encoding.UTF8, "application/x-www-form-urlencoded")
        }
        Dim TokenRes As HttpResponseMessage = httpClient.SendAsync(tokenReq).Result
        Dim TokenObj As GraphToken = JsonConvert.DeserializeObject(Of GraphToken)(TokenRes.Content.ReadAsStringAsync.Result())
        Dim JwtReader As New JwtSecurityTokenHandler
        Dim JwtToken As JwtSecurityToken = JwtReader.ReadToken(TokenObj.AccessToken)
        Dim UserOid As String = JwtToken.Payload("oid")

        ' set user calling routing
        Dim RoutingURL As String = $"https://api.interfaces.records.teams.microsoft.com/Skype.VoiceGroup/userRoutingSettings/{UserOid}"

        httpClient.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("Bearer", TokenObj.AccessToken)

        Dim RoutingJSON As String =
            "{""sipUri"":""sip:[email protected]""," &
            """forwardingSettings"":{""isEnabled"":false,""forwardingType"":""Simultaneous"",""targetType"":""Unknown"",""target"":""""}," &
            """unansweredSettings"":{""isEnabled"":true,""targetType"":""SingleTarget"",""target"":""+491701234567"",""delay"":""00:00:20""}," &
            """callGroupDetails"":{""targets"":[],""order"":""Simultaneous""},""callGroupMembershipSettings"":{""callGroupMembershipDetails"":[]}}"

        Dim RoutingReq As New HttpRequestMessage(HttpMethod.Post, RoutingURL) With {
            .Content = New StringContent(RoutingJSON, Encoding.UTF8, "application/json")
        }
        Dim RoutingRes As HttpResponseMessage = httpClient.SendAsync(RoutingReq).Result

        Console.WriteLine(If(RoutingRes.IsSuccessStatusCode, "success", "failed"))
    End Sub

    Public Class GraphToken
        <JsonProperty(PropertyName:="access_token")>
        Public Property AccessToken As String
        <JsonProperty(PropertyName:="expires_in")>
        Public Property ExpiresIn As Integer
        <JsonProperty(PropertyName:="ext_expires_in")>
        Public Property ExpiresInExt As Integer
        <JsonProperty(PropertyName:="scope")>
        Public Property Scope As String
        <JsonProperty(PropertyName:="token_type")>
        Public Property TokenType As String

    End Class
End Class

TL;DR:

what's the MS Graph API for setting the teams call forwarding policy of an user?

Background:

Currently I'm trying to migrate a Lync/Skype-based .NET application to Teams.
The Teams related part is about setting the call forwarding preferences of a few specific users.
Those users have direct routing enabled, i.e. you can call a fixed PSTN/suffix number and the user will receive the call on his mobile. That mobile number is depending on the shift, so the programm is adapting it to whoever has the shift duty at that time.

What I've tried so far?

  • I can authenticate with the MS Graph API.
  • I know that there's TAC extension for this purpose ([1] and [2])
  • There's also a Powershell extension [3]
  • I'm not the first one to ask the question, but other threads usually got stuck [4]
  • The Call-Redirect is not what I want, as I'm not actively listening on those instances.
  • There's a github for Teams related scripts, but unfortunately without sources ...
  • I haven't yet reflected the Powershell extension
  • There is a promising user settings entry, where you can change shifts but not the call forwarding

Plan B?

Update 2022-06-20

  • I'm starting to reflect the ps module. So API seems to be something like https://api.interfaces.records.teams.microsoft.com/Skype.VoiceGroup/userRoutingSettings/ + userId
  • The teams user id can be retrieved
  • Some parts of teams rely still on an older REST API (german only, sorry)

Update 2022-06-30

a POC which can be improved would look like this (... if I've packed into the usual AcquireTokenOnBehalfOf, then I'll add it as an answer ...)

Imports System.IO
Imports Microsoft.Identity.Client
Imports System.Globalization
Imports System.Net.Http
Imports System.Text
Imports System.Net.Http.Headers
Imports System.Net
Imports Newtonsoft.Json
Imports System.IdentityModel.Tokens.Jwt

Public Class LyncTest

    Public Shared Sub Test()
        Dim InstanceId As String = "https://login.microsoftonline.com/"
        Dim RedirectURI As String = "https://login.microsoftonline.com/common/oauth2/nativeclient"

        ' Ids / Secrets and can be found on your Azure application page
        Dim TenantId As String = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
        Dim AppId As String = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
        Dim secretVal As String = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        Dim username As String = "[email protected]"
        Dim password As String = "xxxxxxxxxxxx"
        ' Teams scope
        Dim scope As String = "48ac35b8-9aa8-4d74-927d-1f4a14a0b239/.default"

        Dim httpClient = New HttpClient()

        ' start resource owner password credential flow
        ' see https://learn.microsoft.com/en-us/powershell/module/teams/connect-microsoftteams?view=teams-ps#example-4-connect-to-microsoftteams-using-accesstokens
        Dim baseParam As String =
            
quot;client_id={AppId}" &
            
quot;&username={WebUtility.UrlEncode(username)}" &
            
quot;&password={WebUtility.UrlEncode(password)}" &
            
quot;&grant_type=password" &
            
quot;&client_secret={WebUtility.UrlEncode(secretVal)}" &
            
quot;&scope={scope}"

        ' get user_impersonation token
        Dim tokenReq As New HttpRequestMessage(HttpMethod.Post, 
quot;https://login.microsoftonline.com/{TenantId}/oauth2/v2.0/token") With {
            .Content = New StringContent(baseParam, Encoding.UTF8, "application/x-www-form-urlencoded")
        }
        Dim TokenRes As HttpResponseMessage = httpClient.SendAsync(tokenReq).Result
        Dim TokenObj As GraphToken = JsonConvert.DeserializeObject(Of GraphToken)(TokenRes.Content.ReadAsStringAsync.Result())
        Dim JwtReader As New JwtSecurityTokenHandler
        Dim JwtToken As JwtSecurityToken = JwtReader.ReadToken(TokenObj.AccessToken)
        Dim UserOid As String = JwtToken.Payload("oid")

        ' set user calling routing
        Dim RoutingURL As String = 
quot;https://api.interfaces.records.teams.microsoft.com/Skype.VoiceGroup/userRoutingSettings/{UserOid}"

        httpClient.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("Bearer", TokenObj.AccessToken)

        Dim RoutingJSON As String =
            "{""sipUri"":""sip:[email protected]""," &
            """forwardingSettings"":{""isEnabled"":false,""forwardingType"":""Simultaneous"",""targetType"":""Unknown"",""target"":""""}," &
            """unansweredSettings"":{""isEnabled"":true,""targetType"":""SingleTarget"",""target"":""+491701234567"",""delay"":""00:00:20""}," &
            """callGroupDetails"":{""targets"":[],""order"":""Simultaneous""},""callGroupMembershipSettings"":{""callGroupMembershipDetails"":[]}}"

        Dim RoutingReq As New HttpRequestMessage(HttpMethod.Post, RoutingURL) With {
            .Content = New StringContent(RoutingJSON, Encoding.UTF8, "application/json")
        }
        Dim RoutingRes As HttpResponseMessage = httpClient.SendAsync(RoutingReq).Result

        Console.WriteLine(If(RoutingRes.IsSuccessStatusCode, "success", "failed"))
    End Sub

    Public Class GraphToken
        <JsonProperty(PropertyName:="access_token")>
        Public Property AccessToken As String
        <JsonProperty(PropertyName:="expires_in")>
        Public Property ExpiresIn As Integer
        <JsonProperty(PropertyName:="ext_expires_in")>
        Public Property ExpiresInExt As Integer
        <JsonProperty(PropertyName:="scope")>
        Public Property Scope As String
        <JsonProperty(PropertyName:="token_type")>
        Public Property TokenType As String

    End Class
End Class

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拍不死你 2025-02-15 06:11:54

没有可用于设置用户的团队转发策略的图形API。

任何用户策略/租户配置仅通过PowerShell或Admin Portal公开。

There is no Graph API available for setting the teams call forwarding policy of an user.

Any user policy/tenant configuration are only exposed through PowerShell or admin portal now.

趴在窗边数星星i 2025-02-15 06:11:54

如果您只想在不接听CallID并传输单个呼叫的情况下更改团队中的转发状态,那么使用PowerShell可以使用PowerShell:

  1. 安装M $ Teams的PowerShell模块。
    https://www.powershellgallery.com/ppackages/ppackages/packages/microsoftteams 使用

    install -module -name microsoftteams -requiredversion 4.6.0 -allowClobber

  2. 假设您使用 set-csuserCallingSettings命令,例如

    set-csusercallingsettings-identity IsunansweredEnabled $ false


    set-csusercallingsettings-identity


“如果启用语音邮件,则会引发错误,

这将更改输送到所选身份的所有调用的转发状态。请注意,用户可以将其更改为GUI团队。

If you just want to change the forwarding status in Teams without catching callId and transferring individual calls, there is a simpler way by using PowerShell:

  1. Install PowerShell module for M$Teams
    https://www.powershellgallery.com/packages/MicrosoftTeams straight to PowerShell, for example by using

    Install-Module -Name MicrosoftTeams -RequiredVersion 4.6.0 -AllowClobber

  2. Assuming that you have permission set up forwarding by using Set-CsUserCallingSettings command, for example

    Set-CsUserCallingSettings -Identity [email protected] -IsUnansweredEnabled $FALSE

    Set-CsUserCallingSettings -Identity [email protected] -IsForwardingEnabled $true -ForwardingType Immediate -ForwardingTargetType SingleTarget -ForwardingTarget "+123456789"

In theory, only the second line is necessary, but I've noticed that PowerShell throws an error if Voicemail is enabled

This will change the forwarding status for all calls incoming to the selected identity. Note, that the user can change it still in Teams GUI.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文