2 回答

TA貢獻(xiàn)1780條經(jīng)驗 獲得超5個贊
是的,可以從您的軟件/桌面應(yīng)用程序向 MS 團(tuán)隊發(fā)送通知。您可以使用適用于 MS 團(tuán)隊的 Microsoft Graph API 或 MS 團(tuán)隊傳入掛鉤功能。
我發(fā)現(xiàn)使用傳入鉤子要容易得多。
您可以按照 4 個步驟向您的頻道發(fā)送消息通知:
在您的團(tuán)隊中,右鍵單擊您的頻道。并搜索
Incoming Webhook
.
安裝/添加Incoming Webhook
(如果尚未添加)。
Incoming Webhook
通過提供 webhook 名稱來配置。單擊創(chuàng)建
它將生成一個具有唯一 GUID 的鏈接,復(fù)制該鏈接
最后一步,在 PowerShell 中使用此命令行
curl.exe -H "Content-Type:application/json" -d "{'text':'Servers x is started.'}" https://example.webhook.office.com/webhookb2/4dee1c26-036c-4bd2-af75-eb1abd901d18@3c69a296-d747-4ef3-9cc5-e94ee78db030/IncomingWebhook/87557542b42d8d3b04453c4a606f2b92/b852b3d0-84b6-4d98-a547-ae5f53452235
注意:命令行中的 URL 包含一些偽造的 GUID 唯一 ID 引用,但您需要將其替換為從 Webhooks 獲取的引用。
您可以在命令行、PowerShell 或任何其他可以發(fā)出發(fā)布請求并將其合并到代碼中的編程語言中調(diào)用此行。在這種情況下,為了回答這個問題,我在 C# 中實現(xiàn)了帖子要求:
using (var httpClient = new HttpClient())
{
using (var request = new HttpRequestMessage(new HttpMethod("POST"), "https://example.webhook.office.com/webhookb2/4dee1c26-036c-4bd2-af75-eb1abd901d18@3c69a296-d747-4ef3-9cc5-e94ee78db030/IncomingWebhook/87557542b42d8d3b04453c4a606f2b92/b852b3d0-84b6-4d98-a547-ae5f53452235"))
{
request.Content = new StringContent("{'text':'Servers x is started.'}");
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
var response = await httpClient.SendAsync(request);
}
}
現(xiàn)在,當(dāng)我運行命令或 C# 代碼時,我會在該頻道中收到一條消息:
如果您需要刪除已添加的掛鉤,請單擊“已配置”,然后單擊“配置”。并管理 webhook:
并刪除
免責(zé)聲明:我在我的個人博客上寫了一篇涵蓋該主題的文章。

TA貢獻(xiàn)2039條經(jīng)驗 獲得超8個贊
我們在圖形 API 的幫助下實現(xiàn)了同樣的目標(biāo)
注意:向通道發(fā)送消息目前處于測試階段,但很快就會轉(zhuǎn)移到圖 V1 端點。
使用 HTTP:
POST https://graph.microsoft.com/beta/teams/{id}/channels/{id}/messages
Content-type: application/json
{
"body": {
"content": "Hello World"
}
}
使用 C#:
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var chatMessage = new ChatMessage
{
Subject = null,
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "<attachment id=\"74d20c7f34aa4a7fb74e2b30004247c5\"></attachment>"
},
Attachments = new List<ChatMessageAttachment>()
{
new ChatMessageAttachment
{
Id = "74d20c7f34aa4a7fb74e2b30004247c5",
ContentType = "application/vnd.microsoft.card.thumbnail",
ContentUrl = null,
Content = "{\r\n \"title\": \"This is an example of posting a card\",\r\n \"subtitle\": \"<h3>This is the subtitle</h3>\",\r\n \"text\": \"Here is some body text. <br>\\r\\nAnd a <a href=\\\"http://microsoft.com/\\\">hyperlink</a>. <br>\\r\\nAnd below that is some buttons:\",\r\n \"buttons\": [\r\n {\r\n \"type\": \"messageBack\",\r\n \"title\": \"Login to FakeBot\",\r\n \"text\": \"login\",\r\n \"displayText\": \"login\",\r\n \"value\": \"login\"\r\n }\r\n ]\r\n}",
Name = null,
ThumbnailUrl = null
}
}
};
await graphClient.Teams["{id}"].Channels["{id}"].Messages
.Request()
.AddAsync(chatMessage);
您可能需要查看官方文檔以獲得更清晰的信息。這是下面的鏈接
https://learn.microsoft.com/en-us/graph/api/channel-post-messages?view=graph-rest-beta&tabs=csharp
就我而言,我使用 Angular 并調(diào)用端點。
希望它能提供一些想法。

TA貢獻(xiàn)1776條經(jīng)驗 獲得超12個贊
在連接器的幫助下可以在團(tuán)隊中發(fā)布消息。按照文檔創(chuàng)建傳入 Webhook 并使用消息卡發(fā)布消息。
- 2 回答
- 0 關(guān)注
- 204 瀏覽
添加回答
舉報