Created
February 5, 2019 12:55
-
-
Save umaz/e7708e0dbccfda064477fa4ddbc3b21e to your computer and use it in GitHub Desktop.
翻訳した文書を投稿するslackbot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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