I have a devops pipeline which scans the KeyVaults and send notification in a Teams Channel if there are any Secrets/Certificates have expired/about to expire. Since I am using the new Workflows to send notifications via Webhook Request, my Notifications are getting distorted.
This my Power Automate workflow:
Update 18.09.2024:
@Alvin I made changes like your sample but now I am not able 'text' or 'title' und dynamic contents. Do you know what is the reason for that?
this is the Powershell Function that I am using to Send notification using Webhook:
function Send-Notification {
param(
[string]$keyVault,
[string]$WebhookURL,
[array]$messageParts
)
if ($null -ne $messageParts.Count -and $messageParts.Count -gt 0) {
$message = @{
'text' = ($messageParts -join "<br /><br />")
'title' = "Key Vault: $keyVault"
}
$messageJson = $message | ConvertTo-Json -Depth 2
try {
Invoke-RestMethod -Method Post -Uri $WebhookURL -Body $messageJson -ContentType 'application/json'
Write-Output "Notification sent for Key Vault: $keyVault"
}
catch {
Write-Error "Failed to send Teams notification for Key Vault: $keyVault. Error: $_"
}
}
}
and this the Output (Teams Notification) that I am getting:
I need to remove the text and title value in the card, my Notification should look like this:
I guess I have to extract the Message part I need and then output the value again. I did saw some blogs for it but they dont exactly match my problem. Could you please help me to fix this or have an alternative/better solution?
Update 18.09.2024:
@Alvin I made the changes from your suggestion and I am getting the required Notification without the extra stuff. However, Now I am get the links (of the secrets) as a Text instead of clickable links eventhough I enabled the Code view in the message:
and this is how I am getting the notification now:
Do you know how to solve this?
when I save it in code view and refresh it and check it again, it shows me in normal mode:
Please try and configure Post as parameter to be User -> In the code view of the Message section, select Expressions tab, input triggerBody()['text']
then click OK
To resolve this issue, you need to reveal the hidden Subject parameter in the Post message in a chat or channel action. Afterward, set its value to the title
field from your incoming webhook payload. Additionally, assign the Message parameter to the text
node of the payload.
For reference, please follow the steps shown in the screenshots below:
triggerBody()?['text']
.triggerBody()?['title']
.
These settings will correctly post the webhook content into your Microsoft Teams channel, as demonstrated.
Here's an example of how the message will appear in my Teams channel: