Send Message to Slack via PowerShell
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
<# | |
.SYNOPSIS | |
Method to send webhook into Slack. | |
.DESCRIPTION | |
Method to set message into Slack. | |
.PARAMETER webhookUrl | |
Url of the webhook | |
.PARAMETER text | |
Text to be sent | |
.PARAMETER channel | |
Name of the channel | |
.PARAMETER botName | |
Name of the bot, default "webhookbot" | |
.PARAMETER emoji | |
Emoji icon, default ":ghost:" | |
.EXAMPLE | |
Send message to general channel: SendMesssageToSlack "https://hooks.slack.com/services/*" "Hi!" "#general" | |
Send message to general channel with botname: SendMesssageToSlack "https://hooks.slack.com/services/*" "Build failed!" "#general" "Build watcher" | |
Send message to general channel with botname and its emoji: SendMesssageToSlack "https://hooks.slack.com/services/*" "Build failed!" "#general" "Build watcher" ":rage:" | |
#> | |
Function SendMesssage ([string] $webhookUrl, [string] $text,[string] $channel, [string] $botName="webhookbot", [string] $emoji=":ghost:") { | |
$body = @{ | |
channel = $channel; | |
username = $botName; | |
text = $text; | |
icon_emoji = $emoji | |
} | |
$result = (Invoke-RestMethod -Method Post -Uri $webhookUrl -Body (ConvertTo-Json $body)) | |
Write-Host $result | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment