因此,我正在为Microsoft Teams建立一个新的(私人)机器人,该机器人应该能够按需在频道中发布消息。我已经有一个针对Google Hangouts聊天编写的机器人,但是Microsoft Teams给我带来了很大的困难。
我已经在整个网络上搜索了10多个小时,我感到非常困惑。
现在,我要做的就是向Microsoft Teams Channel发送明信片。因此,我创建了connectorclient,我使用了漫游器通过MSAppID和MSAppPassword加入通道(以Class.forName("com.mysql.cj.jdbc.Driver")
开头)时提供的baseuri。然后,我尽可能地填写信息(也许太多了?),然后使用连接器的Class.forName
提交信息。
使用的命名空间:smba.trafficmanager.net
,.conversations.createconversation
代码如下:
Microsoft.bot.connector
这是API返回的内容:
Microsoft.bot.connector.teams.models
请记住,我什至没有100%地确定我使用的是正确的方法来创建频道消息,我认为它是Dim Connector As New ConnectorClient(New Uri("https://smba.trafficmanager.net/amer/"), "MSAPPID", "MSAPPPASSWORD")
Dim conversation As New ConversationParameters
Dim activity2 = Activity.CreateMessageActivity
Dim bot As New ChannelAccount
bot.Id = "BOTID"
bot.Name = "EDD Bot Test"
conversation.Bot = bot
Dim chaninfo As New ChannelInfo
chaninfo.Id = "CHANID"
chaninfo.Name = "General"
Dim teaminfo As New TeamInfo
teaminfo.Id = "TEAMID"
teaminfo.Name = "EDD"
activity2.Text = "Test"
activity2.ServiceUrl = "https://smba.trafficmanager.net/amer/"
activity2.Type = ActivityTypes.Message
activity2.From = bot
activity2.ChannelId = "msteams"
Dim tenantdata As New TenantInfo
tenantdata.Id = "TENANTID"
Dim teamschanneldata As New TeamsChannelData
teamschanneldata.Channel = chaninfo
teamschanneldata.Team = teaminfo
teamschanneldata.Tenant = tenantdata
activity2.ChannelData = teamschanneldata
conversation.Activity = activity2
Response.Write(JsonConvert.SerializeObject(conversation))
Try
Dim reqresp As ConversationResourceResponse = Connector.Conversations.CreateConversation(conversation)
Response.Write("ActivityID: " & reqresp.ActivityId & ", ServiceURL: " & reqresp.ServiceUrl & ", ID: " & reqresp.ServiceUrl)
Catch ex As ErrorResponseException
Response.Write(ex.Response.Content & " " & ex.Response.ReasonPhrase)
End Try
或{"message":"Authorization has been denied for this request."} Unauthorized
。
我也授予了应用CreateConversation
的权限,所以我缺少什么吗?该错误使我认为与ConversationParameters有效负载无关,而与身份验证有关。
答案 0 :(得分:0)
通过对serviceUrl和端点消息使用MicrosoftAppCredentials.TrustserviceUrl
解决了问题。