-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added mentions for Adaptive Cards #17
- Loading branch information
1 parent
d8bc648
commit d1fa61f
Showing
3 changed files
with
115 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,11 @@ New-AdaptiveCard -Uri $Env:TEAMSPESTERID -VerticalContentAlignment center { | |
New-AdaptiveTextBlock -Size 'Medium' -Text 'Test Card Title 1' -Color Warning | ||
New-AdaptiveTextBlock -Size 'Medium' -Text 'Test Card Title 1' -Color Good | ||
} | ||
New-AdaptiveColumn { | ||
New-AdaptiveTextBlock -Size 'Medium' -Text 'Test Card Title 1 <at>Name</at>' -Color Warning | ||
New-AdaptiveTextBlock -Size 'Medium' -Text 'Test Card Title 1 <at>Zenon Jaskuła</at>' -Color Warning | ||
} | ||
} | ||
} -SelectAction Action.OpenUrl -SelectActionUrl 'https://evotec.xyz' -Verbose | ||
New-AdaptiveMention -Text 'Zenon Jaskuła' -UserPrincipalName '[email protected]' | ||
New-AdaptiveMention -Text 'Name' -UserPrincipalName '[email protected]' | ||
} -Verbose #-SelectAction Action.OpenUrl -SelectActionUrl 'https://evotec.xyz' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,7 @@ | |
[switch] $FullWidth, | ||
[switch] $AllowImageExpand | ||
) | ||
$Mentions = [System.Collections.Generic.List[System.Collections.Specialized.OrderedDictionary]]::new() | ||
$Wrapper = [ordered]@{ | ||
"type" = "message" | ||
"attachments" = @( | ||
|
@@ -114,7 +115,14 @@ | |
version = "1.2" # Currently maximum supported is 1.2 for Teams, available is 1.3 | ||
body = @( | ||
if ($Body) { | ||
& $Body | ||
$OutputBody = & $Body | ||
foreach ($B in $OutputBody) { | ||
if ($B.type -eq 'mention') { | ||
$Mentions.Add($B) | ||
} else { | ||
$B | ||
} | ||
} | ||
} | ||
) | ||
actions = @( | ||
|
@@ -168,25 +176,37 @@ | |
title = $SelectActionTitle | ||
url = $SelectActionUrl | ||
} | ||
<# | ||
# this somewhat works, except it doesn't | ||
$Wrapper['attachments'][0]['content']["msteams"] = @{ | ||
"entities" = @( | ||
@{ | ||
"type" = "mention" | ||
"text" = "<at>przemyslaw.klys</at>" | ||
"mentioned" = @{ | ||
#"id" = "8:orgid:49f7e27a-ce6c-45ef-9936-6ef3e940583d" | ||
#"id" = '29:49f7e27a-ce6c-45ef-9936-6ef3e940583d' | ||
#"id" = '29:orgid:49f7e27a-ce6c-45ef-9936-6ef3e940583d' | ||
"id" = '19:b6b525a2187848ddb257f59e374363bd' | ||
#"id" = 'orgid:49f7e27a-ce6c-45ef-9936-6ef3e940583d' | ||
#"id" = '49f7e27a-ce6c-45ef-9936-6ef3e940583d' | ||
"name" = "przemyslaw.klys" | ||
|
||
if ($Mentions.Count -gt 0) { | ||
# this somewhat works, except it doesn't | ||
$Wrapper['attachments'][0]['content']["msteams"] = @{ | ||
"entities" = @( | ||
foreach ($Mention in $Mentions) { | ||
$Mention | ||
} | ||
} | ||
) | ||
<# | ||
@{ | ||
"type" = "mention" | ||
"text" = "<at>przemyslaw.klys</at>" | ||
"mentioned" = @{ | ||
#"id" = "8:orgid:49f7e27a-ce6c-45ef-9936-6ef3e940583d" | ||
#"id" = '29:49f7e27a-ce6c-45ef-9936-6ef3e940583d' | ||
#"id" = '29:orgid:49f7e27a-ce6c-45ef-9936-6ef3e940583d' | ||
#"id" = '19:b6b525a2187848ddb257f59e374363bd' | ||
#"id" = 'orgid:49f7e27a-ce6c-45ef-9936-6ef3e940583d' | ||
#"id" = '49f7e27a-ce6c-45ef-9936-6ef3e940583d' | ||
#"name" = "przemyslaw.klys" | ||
id = '[email protected]' | ||
name = 'Przemysław Kłys' | ||
} | ||
} | ||
#> | ||
) | ||
} | ||
} | ||
<# | ||
#> | ||
<# this doesn't work, but tested | ||
$Wrapper["msteams"] = @{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
function New-AdaptiveMention { | ||
<# | ||
.SYNOPSIS | ||
Allows Adaptive Card to mention specific person in the notification. | ||
.DESCRIPTION | ||
Allows Adaptive Card to mention specific person in the notification. | ||
Currently Adaptive Card in incoming webhook notifications allows you to define a mention property, but it doesn't notify the user on notification. | ||
It's supposed to be enabled in future by Microsoft. | ||
.PARAMETER Text | ||
Provide the text to be mentioned by using <at>person</at> tag. You can provide tags or skip them. Should work either way. | ||
.PARAMETER UserPrincipalName | ||
Provide the user principal name of the person to be mentioned. | ||
.PARAMETER Name | ||
Provide the name of the person to be mentioned. This is optional. | ||
.EXAMPLE | ||
New-AdaptiveMention -Text '<at>przemyslaw.klys</at>' -UserPrincipalName '[email protected]' | ||
.EXAMPLE | ||
New-AdaptiveMention -Text 'przemyslaw.klys' -UserPrincipalName '[email protected]' -Name 'Przemysław Kłys' | ||
.EXAMPLE | ||
New-AdaptiveCard -Uri $URI -VerticalContentAlignment center { | ||
New-AdaptiveTextBlock -Size ExtraLarge -Weight Bolder -Text 'Test' -Color Attention -HorizontalAlignment Center | ||
New-AdaptiveColumnSet { | ||
New-AdaptiveColumn { | ||
New-AdaptiveTextBlock -Size 'Medium' -Text 'Test Card Title 1' -Color Dark | ||
New-AdaptiveTextBlock -Size 'Medium' -Text 'Test Card Title 1' -Color Light | ||
} | ||
New-AdaptiveColumn { | ||
New-AdaptiveTextBlock -Size 'Medium' -Text 'Test Card Title 1' -Color Warning | ||
New-AdaptiveTextBlock -Size 'Medium' -Text 'Test Card Title 1' -Color Good | ||
} | ||
New-AdaptiveColumn { | ||
New-AdaptiveTextBlock -Size 'Medium' -Text 'Test Card Title 1 <at>Name</at>' -Color Warning | ||
New-AdaptiveTextBlock -Size 'Medium' -Text 'Test Card Title 1 <at>Zenon Jaskuła</at>' -Color Warning | ||
} | ||
} | ||
New-AdaptiveMention -Text 'Zenon Jaskuła' -UserPrincipalName '[email protected]' | ||
New-AdaptiveMention -Text 'Name' -UserPrincipalName '[email protected]' | ||
} -Verbose | ||
.NOTES | ||
More information here: https://github.com/EvotecIT/PSTeams/issues/17 | ||
#> | ||
[cmdletBinding()] | ||
param( | ||
[parameter(Mandatory)][string] $Text, | ||
[parameter(Mandatory)][string] $UserPrincipalName, | ||
[string] $Name | ||
) | ||
|
||
$Mention = [ordered] @{ | ||
"type" = "mention" | ||
"text" = if ($Text -like "*<at>*") { $Text } else { "<at>$Text</at>" } | ||
"mentioned" = @{ | ||
id = $UserPrincipalName | ||
name = $Name | ||
} | ||
} | ||
if ($Name) { | ||
$Mention.mentioned.name = $Name | ||
} | ||
$Mention | ||
} |