【Windows】incoming-webhookを利用してバッチファイル経由で投稿します
Windowsで特定のアプリを起動・終了するたびにslackにポスト。
curlとかnkfをダウンロードしなくてもいい方法を考えたけど、そっち使ったほうがバッチファイルのみで処理できます。
slack.ps1
Param(
[string]$username,
[string]$channel,
[string]$message
)
function Push-Notification($username,$channel,$message) {
$webhookuri = "https://hooks.slack.com/services/~~~"
$channel = "#" + $channel
$text = @{
text = $message
channel = $channel
username = $username
}| ConvertTo-Json -Compress
$payload = [Text.Encoding]::UTF8.GetBytes($text)
Invoke-RestMethod -Uri $webhookuri -Method Post -Body $payload
}
# >slack.ps1 "ユーザー名" "チャンネル名" "本文"
Push-Notification $username $channel $message
実行ポリシーを設定して実行
hoge.bat
powershell -WindowStyle Hidden -ExecutionPolicy Bypass -command .\slack.ps1 "わいです" "channel" "hogeが起動"
@echo off
call hoge.exe
powershell -WindowStyle Hidden -ExecutionPolicy Bypass -command .\slack.ps1 "わいです" "channel" "hogeが終了"
特定のアプリはバッチファイルから起ち上げるようにします