Microsoft Teams中私人消息的传入Webhook

我可以从C#app或PS Script创建一个传入的webhook,向MSFT doc解释的频道发送JSON消息。

但是,我想使用我的传入webhook从我的应用程序向用户发送JSON消息(如私人消息),如Slack允许。

据我所知,MSFT团队无法做到这一点: https : //dev.outlook.com/Connectors/Reference

但也许你知道任何解决方法或类似的东西来解决它。

提前致谢 :)

[EDITED]用于通过C#App将消息发布到MSFT团队的代码:

//Post a message using simple strings public void PostMessage(string text, string title) { Payload payload = new Payload() { Title = title Text = test }; PostMessage(payload); } //Post a message using a Payload object public async void PostMessage(Payload payload) { string payloadJson = JsonConvert.SerializeObject(payload); var content = new StringContent(payloadJson); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var client = new HttpClient(); uri = new Uri(GeneralConstants.TeamsURI); await client.PostAsync(uri, content); } 

此时实现目标的最佳方法是创建一个Bot并实现它以暴露您的应用或服务可以发布到的webhook端点,以及机器人将这些消息发布到与用户聊天。

首先,根据机器人收到的传入活动,捕获成功发布到用户机器人对话所需的信息。

 var callBackInfo = new CallbackInfo() { ConversationId = activity.Conversation.Id, ServiceUrl = activity.ServiceUrl }; 

然后将callBackInfo打包成一个令牌,该令牌稍后将用作webhook的参数。

  var token = Convert.ToBase64String( Encoding.Default.GetBytes( JsonConvert.SerializeObject(callBackInfo))); var webhookUrl = host + "/v1/hook/" + token; 

最后,实现webhook处理程序来解压缩callBackInfo:

 var jsonString = Encoding.Default.GetString(Convert.FromBase64String(token)); var callbackInfo = JsonConvert.DeserializeObject(jsonString); 

并向用户发布机器人的对话:

 ConnectorClient connector = new ConnectorClient(new Uri(callbackInfo.ServiceUrl)); var newMessage = Activity.CreateMessageActivity(); newMessage.Type = ActivityTypes.Message; newMessage.Conversation = new ConversationAccount(id: callbackInfo.ConversationId); newMessage.TextFormat = "xml"; newMessage.Text = message.Text; await connector.Conversations.SendToConversationAsync(newMessage as Activity); 

看看我在这个主题上的博客文章。 如果您之前从未编写过Microsoft Teams bot,请在此处查看我的其他博客文章,并附带分步说明。