ps/Modules/Alkami.DevOps.Common/Public/Get-SlackMessage.ps1

59 lines
1.4 KiB
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
function Get-SlackMessage {
<#
.SYNOPSIS
Create a Slack Message.
.PARAMETER Username
To specify the username for the published message.
.PARAMETER IconEmoji
To specify an emoji (using colon shortcodes, eg. :white_check_mark:) to use as the profile photo alongside the message.
.PARAMETER Text
The main body text of the message.
.PARAMETER Channel
Channel, private group, or IM channel to send message to.
.PARAMETER Attachments
One of these arguments is required to describe the content of the message. See the function 'Get-SlackAttachment' for more information.
#>
[CmdletBinding()]
[OutputType([object])]
param (
[Parameter(Mandatory = $true)]
[string]$Username,
[Parameter(Mandatory = $true)]
[string]$IconEmoji,
[Parameter(Mandatory = $true)]
[string]$Text,
[Parameter(Mandatory = $true)]
[string]$Channel,
[Parameter(Mandatory = $false)]
[object[]]$Attachments = $null
)
$IconEmoji = $IconEmoji.replace(':', '')
$normalizedIconEmoji = ":$($IconEmoji):"
$message = @{
username = $Username
icon_emoji = $normalizedIconEmoji
text = $Text
channel = $Channel
}
if (![string]::IsNullOrWhiteSpace($Channel)) {
$message.channel = $Channel
}
if ($null -ne $Attachments) {
$message.attachments = @($Attachments)
}
return $message
}