RubyでSlackにメッセージ送る方法(slack-poster使う)
Refer
How To
$ gem install slack-poster
$ open https://TEAM-NAME.slack.com/services/new/incoming-webhook
- Click “Add Incoming WebHooks Integration”
- Copy “Webhook URL”
- “Webhook URL” looks like:
https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX
.
$ vi hello.rb
$ cat hello.rb
require 'slack_poster'
WEBHOOK_URL = 'https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX'
poster = Slack::Poster.new(WEBHOOK_URL)
poster.send_message('Hello world!')
$ ruby hello.rb
- Check your slack and see “Hello world!”.
Option
require 'slack_poster'
WEBHOOK_URL = 'https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX'
poster = Slack::Poster.new(WEBHOOK_URL)
poster.username = 'The Ghost'
poster.icon_emoji = ':ghost:'
puts poster.send_message('Hello there!')
メモ
- メールで保存するほどでもないcron嬢からの通知受け取りに利用したい。