Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Adding -DisableTextMarkdown switch to Send-TeamsMessage. #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Private/Add-TeamsBody.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
[string] $MessageText,
[string] $MessageSummary,
[System.Collections.IDictionary[]] $Sections,
[switch] $HideOriginalBody
[switch] $HideOriginalBody,
[switch] $DisableTextMarkdown
)

$Body = [ordered] @{
Expand All @@ -33,5 +34,9 @@
if ($MessageText -ne '') {
$Body.text = $MessageText
}
if ($DisableTextMarkdown.IsPresent) {
$Body = Disable-TextMarkdown -InputObject $Body
}

return $Body | ConvertTo-Json -Depth 6
}
34 changes: 34 additions & 0 deletions Private/Disable-TextMarkdown.ps1
Original file line number Diff line number Diff line change
@@ -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
}
17 changes: 17 additions & 0 deletions Private/Invoke-EscapeMarkdownCharacters.ps1
Original file line number Diff line number Diff line change
@@ -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
}
}
6 changes: 4 additions & 2 deletions Public/Send-TeamsMessage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down