Functions/Tracing/Write-CdsMessageToSlack.ps1

<#
    .SYNOPSIS
    Push message to slack
#>

function Write-CdsMessageToSlack {
    [CmdletBinding()]
    param
    (        
        [Parameter(Mandatory = $false)]
        [String]
        $SlackUrl = $env:SLACKURL,
          
        [Parameter(Mandatory=$false)]    
        [String]
        $BotName = "DevOps",

        [Parameter(Mandatory=$true)]    
        [String]
        $Message,

        [Parameter(Mandatory=$false)]
        [String]
        $Emoji
    )
    process {
        $BodyTemplate = ConvertTo-Json @{
            username = "$BotName"
            text = "$Message"
            icon_emoji = "$Emoji"
        }

        Invoke-RestMethod -uri $SlackUrl -Method Post -body $BodyTemplate -ContentType 'application/json' | Out-Null;
    }
}

Export-ModuleMember -Function Write-CdsMessageToSlack -Alias *;