diff --git a/Private/Add-TeamsBody.ps1 b/Private/Add-TeamsBody.ps1 index 13cc078..97361bf 100644 --- a/Private/Add-TeamsBody.ps1 +++ b/Private/Add-TeamsBody.ps1 @@ -6,7 +6,8 @@ [string] $MessageText, [string] $MessageSummary, [System.Collections.IDictionary[]] $Sections, - [switch] $HideOriginalBody + [switch] $HideOriginalBody, + [switch] $DisableTextMarkdown ) $Body = [ordered] @{ @@ -33,5 +34,9 @@ if ($MessageText -ne '') { $Body.text = $MessageText } + if ($DisableTextMarkdown.IsPresent) { + $Body = Disable-TextMarkdown -InputObject $Body + } + return $Body | ConvertTo-Json -Depth 6 } \ No newline at end of file diff --git a/Private/Disable-TextMarkdown.ps1 b/Private/Disable-TextMarkdown.ps1 new file mode 100644 index 0000000..6506d34 --- /dev/null +++ b/Private/Disable-TextMarkdown.ps1 @@ -0,0 +1,34 @@ +function Disable-TextMarkdown() { + [CmdletBinding()] + Param( + $InputObject + ) + + $ReturnBody = [ordered] @{} + $InputObject | Foreach-Object { + $Object = $_ + $Keys = $Object.Keys + $Keys | Foreach-Object { + $Key = $_ + if ($Key -eq 'sections') { + $ReturnBody.sections = @( + $Object.$Key | Foreach-Object { + $Section = $_ + $SectionKeys = $Section.Keys + Foreach ($Item in $SectionKeys.Clone()) { + Switch($Item.ToLower().Contains('text')) { + $true { + $Section."$Item" = Invoke-EscapeMarkdownCharacter -InputString $Section."$Item" + } + } + } + $Section + } + ) + } else { + $ReturnBody.$Key = $Object.$Key + } + } + } + $ReturnBody +} \ No newline at end of file diff --git a/Private/Invoke-EscapeMarkdownCharacters.ps1 b/Private/Invoke-EscapeMarkdownCharacters.ps1 new file mode 100644 index 0000000..04ae271 --- /dev/null +++ b/Private/Invoke-EscapeMarkdownCharacters.ps1 @@ -0,0 +1,17 @@ +function Invoke-EscapeMarkdownCharacter() { + [CmdletBinding()] + Param( + [char[]]$MarkdownChar = @('`','*','_','{','}','[',']','(',')','#','+','-','.','!'), + + [Parameter(Mandatory)] + [System.String] $InputString + ) + + Process { + $MarkdownChar | Foreach-Object { + $EscapeMe = $_.ToString() + $InputString = $InputString.ToString().Replace($EscapeMe,"\$EscapeMe") + } + $InputString + } +} \ No newline at end of file diff --git a/Public/Send-TeamsMessage.ps1 b/Public/Send-TeamsMessage.ps1 index 0b1484b..4996258 100644 --- a/Public/Send-TeamsMessage.ps1 +++ b/Public/Send-TeamsMessage.ps1 @@ -10,7 +10,8 @@ function Send-TeamsMessage { [string]$Color, [switch]$HideOriginalBody, [System.Collections.IDictionary[]]$Sections, - [alias('Supress')][bool] $Suppress = $true + [alias('Supress')][bool] $Suppress = $true, + [switch]$DisableTextMarkdown ) if ($SectionsInput) { $Output = & $SectionsInput @@ -32,7 +33,8 @@ function Send-TeamsMessage { -ThemeColor $ThemeColor ` -Sections $Output ` -MessageSummary $MessageSummary ` - -HideOriginalBody:$HideOriginalBody.IsPresent + -HideOriginalBody:$HideOriginalBody.IsPresent ` + -DisableTextMarkdown:$DisableTextMarkdown.IsPresent Write-Verbose "Send-TeamsMessage - Body $Body" try { $Execute = Invoke-RestMethod -Uri $Uri -Method Post -Body $Body -ContentType 'application/json; charset=UTF-8' -ErrorAction Stop