Slack に メッセージを飛ばす
▼前準備
・curl をインストールしておく (ex. yum install curl)
・Add Service Integrations から Incoming WebHooks を選択する。
メッセージをどのチャンネルに飛ばすかを選択する。
'Your Unique Webhook URL' の内容に注目
▼以下のプログラムでGO~
use strict; use warnings; use utf8; use JSON::XS; my $teamname = 'xxxxxxxxxx'; # Your Unique Webhook URL の一部に書いてある my $token = 'xxxxxxxxxx'; # Your Unique Webhook URL の一部に書いてある slack_notification( # Slack incoming-webhook API URL "https://$teamname.slack.com/services/hooks/incoming-webhook?token=$token", # チャンネル名 '#from_perl_test', # メッセージテキスト 'notification from perl program', # ユーザ名を偽装?できる 'user_name_', ); sub slack_notification { my ( $url, $channel, $text, $user_name ) = @_; my $json_text = JSON::XS->new->utf8->encode( { "channel" => $channel, "text" => $text, "username" => $user_name, } ); my $http_content = sprintf( "payload=%s", $json_text ); `curl -X POST --data-urlencode '$http_content' $url > /dev/null 2>&1`; }