【问题标题】:How to put a hyperlink in a MS Teams message sent from a Powershell script in a TeamCity build project?如何在 TeamCity 构建项目中的 Powershell 脚本发送的 MS Teams 消息中放置超链接?
【发布时间】:2022-06-15 19:59:44
【问题描述】:

我正在使用 TeamCity 构建我的项目。 在我的一个构建步骤中,我放置了一个 Powershell 脚本,该脚本使用 Webhook 向 MS Teams 频道发送消息。

$url = "https://..."
$body = @{
    title = "MtTitle";
    text = "Visit: $url";
} | ConvertTo-Json
$postBody = [Text.Encoding]::UTF8.GetByres($body)
Invoke-WebRequest -Method Post -Uri "https://mycorp.webhook.office.com/..." -Body $postBody -ContentType "application/json" -UseBasicParsing

由于上述脚本,消息按预期发送到 Teams 频道,但 URL(Visit: 之后的字符串)显示为纯文本。
如何使它成为可点击的超链接?
我应该使用如下链接所示的 MessageCard 吗?
Get Build Job URL in TeamCity Build Step

【问题讨论】:

    标签: html json powershell teamcity microsoft-teams


    【解决方案1】:

    您可以在这样的团队中创建链接:

    [HereText](hereLink)
    

    代码看起来像这样:

    $url = "https://..."
    $urlText = "some"
    $body = @{
        title = "MtTitle";
        text = "Visit [$urlText]($url)";
    } | ConvertTo-Json
    Invoke-WebRequest -Method Post -Uri "https://mycorp.webhook.office.com/..." -Body $postBody -ContentType "application/json" -UseBasicParsing
    

    【讨论】:

      猜你喜欢
      • 2021-06-19
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 1970-01-01
      • 2019-02-09
      • 1970-01-01
      • 2020-11-14
      • 1970-01-01
      相关资源
      最近更新 更多