Skip to content

Instantly share code, notes, and snippets.

@umaz
Created February 5, 2019 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umaz/e7708e0dbccfda064477fa4ddbc3b21e to your computer and use it in GitHub Desktop.
Save umaz/e7708e0dbccfda064477fa4ddbc3b21e to your computer and use it in GitHub Desktop.
翻訳した文書を投稿するslackbot
# coding: utf-8
require 'slack'
require 'date'
require 'httpclient'
require 'uri'
TOKEN = 'YOUR_TOKEN'
Slack.configure do |conf|
conf.token = TOKEN
end
client = Slack.realtime
client.on :hello do
puts 'Successfully connected.'
end
client.on :message do |data|
# respond to messages
if /^\[(ja|en)\-(ja|en)\]\s*(.+)$/ =~ data['text']
p data
user = Slack.users_info(user: data['user'])
p user
source = $1
target = $2
text = $3
uri = "https://script.google.com/macros/s/HOGEHOGE/exec?text=#{text}&source=#{source}&target=#{target}"
u = URI.encode(uri)
client = HTTPClient.new()
res = client.get(u, :follow_redirect => true)
params = {
channel: data['channel'],
text: res.body,
username: user['user']['profile']['real_name'],
icon_url: user['user']['profile']['image_72']
}
Slack.chat_postMessage params
end
end
client.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment