![](/img/trans.png)
[英]Sending a message to users as a bot in bot channel of Microsoft Teams using the Graph API
[英]Sending an MS Teams message using the Microsoft Graph API or BOT API
我正在嘗試實施以下解決方案:訂閱所有 MS 團隊聊天消息的 web 應用程序。 如果消息包含禁止文本,應用程序應該以某種方式警告用戶(理想情況下通過回復相同的消息,或者,如果不可能,啟動與用戶的對話)。
我能夠接收所有聊天 webhook 並對其進行處理,但我找不到任何方法可以使用 Graph API( https://docs.microsoft.com/en-我們/graph/api/channel-post-messagereply?view=graph-rest-beta&tabs=http
應用程序權限不支持 - 僅支持不適合我們情況的委托)。
所以我正在嘗試使用 Bot 框架發送主動消息,但是,bot 框架需要一個我沒有的團隊對話 ID(圖表 API webhook 提供了團隊、頻道和用戶 ID,這些都不被機器人 API)。
有誰知道我可以使用圖表 API 提供的團隊 ID 和頻道 ID 來檢索團隊對話 ID 的方法?
謝謝,丹
頻道消息的 ConversationId 是 channelId 和 messageId 的組合,兩者都可以在您收到webhook 通知的有效負載中找到。 您可以通過如下方式構建 converstionId 來回復現有對話:
conversationId = $"{channelId};messageid={messageId}"
為了回復工作,您的 Bot 需要安裝在團隊中,並且應該在某個地方保存serviceURL以供參考。 以下是顯示如何回復現有消息的示例代碼。
var serviceURL = "YOUR Service URL- You get this in each bot payload";
MicrosoftAppCredentials.TrustServiceUrl(serviceURL, DateTime.MaxValue);
using var connector = new ConnectorClient(new Uri(serviceURL, MicrosoftAppId, MicrosoftAppPassword);
var conversationId = $"{channelId};messageid={messageId}";
var replyActivity = MessageFactory.Text($"This is simple reply to existing conversation.");
replyActivity.Conversation = new ConversationAccount(id: conversationId);
var response = await connector.Conversations.SendToConversationAsync(conversationId, replyActivity);
如需 1:1 回復 - 請查看Sending Proactive Message文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.