Home > Blockchain >  How to put a hyperlink in a MS Teams message sent from a Powershell script in a TeamCity build proje
How to put a hyperlink in a MS Teams message sent from a Powershell script in a TeamCity build proje

Time:06-16

I'm using TeamCity to build my project. In one of my build steps, I put a Powershell script, which uses Webhook to send a message to a MS Teams channel.

$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

As a result of the script above, a message is sent to the Teams channel as expected, but the URL (the string after Visit:) is shown as a plain text.
How is it possible to make it a clickable hyperlink?
Should I use a MessageCard as shown in the link below?
Get Build Job URL in TeamCity Build Step

CodePudding user response:

You can create a link in teams like that:

[HereText](hereLink)

Code would look somthing like that:

$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
  • Related