0

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

user4134476
  • 385
  • 4
  • 22

1 Answers1

2

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
guiwhatsthat
  • 2,349
  • 1
  • 12
  • 24