2018-08-19  slack  evernote  ruby 

Slackの指定したチャンネルで/clip yesterdayコマンドを実行するRubyスクリプト

背景

問題

解法

#! /usr/bin/env ruby
#
# clip-yesterday.rb - Script to send "/clip yesterday" to your channel.
#
# WARNING: This script uses Slack Legacy Tokens. Use at your own risk.
#
# Author: hyuki
# Based on:
# * https://github.com/wgkoro/lambda_slack_command
# * https://api.slack.com/custom-integrations/legacy-tokens
# * https://twitter.com/WG_koro/status/1029657575971741696

require 'uri'
require 'open-uri'

# $ grep CLIP_YESTERDAY ~/.bash_profile
# export CLIP_YESTERDAY_TOKEN=xoxp-0000000000-0000000000-000000000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
# export CLIP_YESTERDAY_CHANNEL_ID=C00000000

params = {
  'token' => ENV['CLIP_YESTERDAY_TOKEN'],
  'channel' => ENV['CLIP_YESTERDAY_CHANNEL_ID'],
  'command' => '/clip',
  'text'  => 'yesterday',
}

open("https://slack.com/api/chat.command?#{URI.encode_www_form(params)}") do |f|
  puts f.readlines
end

# vim: set filetype=ruby:

注意

謝辞

@wgkoroさんに教えていただきました。

関連リンク

 2018-08-19  slack  evernote  ruby