├── .gitignore ├── CHANGELOG.md ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── lib └── ruboty │ ├── adapters │ └── slack.rb │ ├── slack.rb │ └── slack │ └── version.rb └── ruboty-slack.gemspec /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | Gemfile.lock 7 | InstalledFiles 8 | _yardoc 9 | coverage 10 | doc/ 11 | lib/bundler/man 12 | pkg 13 | rdoc 14 | spec/reports 15 | test/tmp 16 | test/version_tmp 17 | tmp 18 | *.bundle 19 | *.so 20 | *.o 21 | *.a 22 | mkmf.log 23 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.1.12 2 | * Support the latest problem of Slack XMPP Gateway about groupchat with resource name 3 | 4 | ## 0.1.11 5 | * Add missing comma 6 | 7 | ## 0.1.10 8 | * Fix groupchat behavior 9 | 10 | ## 0.1.9 11 | * Use xrc v0.1.8 or later 12 | * Fix groupchat behavior 13 | 14 | ## 0.1.8 15 | * Fix error class loading problem 16 | 17 | ## 0.1.7 18 | * Set RUBOTY_NAME to slack username if name not given 19 | 20 | ## 0.1.6 21 | * Support multi rooms 22 | 23 | ## 0.1.5 24 | * Ignore delayed messages when ruboty was logging out 25 | 26 | ## 0.1.4 27 | * Rename: Ellen -> Ruboty 28 | 29 | ## 0.1.3 30 | * Support Ruboty::Message#from_name 31 | 32 | ## 0.1.2 33 | * Format message body if :code option is passed 34 | 35 | ## 0.1.1 36 | * Fix private message handler 37 | 38 | ## 0.1.0 39 | * Use XMPP Gateway instead of IRC 40 | 41 | ## 0.0.4 42 | * Support Ruboty v0.2.0 43 | 44 | ## 0.0.3 45 | * Support multiline message 46 | 47 | ## 0.0.2 48 | * Fix encoding problem (forced to UTF-8) 49 | 50 | ## 0.0.1 51 | * 1st Release 52 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in ruboty-slack.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Ryo Nakamura 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ruboty::Slack 2 | Slack adapter for [Ruboty](https://github.com/r7kamura/ruboty). 3 | 4 | ## Usage 5 | See https://my.slack.com/admin/settings to enable XMPP Gateway on Slack. 6 | 7 | ```ruby 8 | # Gemfile 9 | gem "ruboty-slack" 10 | ``` 11 | 12 | ## ENV 13 | ``` 14 | SLACK_PASSWORD - Account's XMPP password 15 | SLACK_ROOM - Room name to join in at first (e.g. general,random) 16 | SLACK_TEAM - Account's team name (e.g. wonderland) 17 | SLACK_USERNAME - Account's username (e.g. alice) 18 | ``` 19 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | 3 | -------------------------------------------------------------------------------- /lib/ruboty/adapters/slack.rb: -------------------------------------------------------------------------------- 1 | require "xrc" 2 | 3 | module Ruboty 4 | module Adapters 5 | class Slack < Base 6 | env :SLACK_PASSWORD, "Account's XMPP password (See https://tqhouse.slack.com/account/gateways)" 7 | env :SLACK_ROOM, "Room name to join in at first (e.g. general)" 8 | env :SLACK_TEAM, "Account's team name (e.g. wonderland)" 9 | env :SLACK_USERNAME, "Account's username (e.g. alice)" 10 | 11 | def run 12 | init 13 | bind 14 | connect 15 | end 16 | 17 | def say(message) 18 | client.say( 19 | body: message[:code] ? "```\n#{message[:body]}\n```" : message[:body], 20 | from: message[:from], 21 | to: message[:original][:type] == "chat" ? message[:to] + "/resource" : message[:to].split("/", 2).first, 22 | type: message[:original][:type], 23 | ) 24 | end 25 | 26 | private 27 | 28 | def client 29 | @client ||= Xrc::Client.new( 30 | jid: jid, 31 | nickname: username, 32 | password: password, 33 | room_jid: room_jids.join(","), 34 | ) 35 | end 36 | 37 | def init 38 | ENV["RUBOTY_NAME"] ||= username 39 | end 40 | 41 | def jid 42 | "#{username}@#{host}" 43 | end 44 | 45 | def room_jids 46 | rooms.map do |room| 47 | "#{room}@#{room_host}" 48 | end 49 | end 50 | 51 | def host 52 | "#{team}.xmpp.slack.com" 53 | end 54 | 55 | def room_host 56 | "conference.#{host}" 57 | end 58 | 59 | def rooms 60 | ENV["SLACK_ROOM"].split(",") 61 | end 62 | 63 | def username 64 | ENV["SLACK_USERNAME"] 65 | end 66 | 67 | def password 68 | ENV["SLACK_PASSWORD"] 69 | end 70 | 71 | def team 72 | ENV["SLACK_TEAM"] 73 | end 74 | 75 | def bind 76 | client.on_private_message(&method(:on_message)) 77 | client.on_room_message(&method(:on_message)) 78 | end 79 | 80 | def connect 81 | client.connect 82 | end 83 | 84 | # @note Ignores delayed messages when ruboty was logging out 85 | def on_message(message) 86 | unless message.delayed? 87 | robot.receive( 88 | body: message.body, 89 | from: message.from, 90 | from_name: username_of(message), 91 | to: message.to, 92 | type: message.type, 93 | ) 94 | end 95 | end 96 | 97 | def username_of(message) 98 | case message.type 99 | when "groupchat" 100 | Xrc::Jid.new(message.from).resource 101 | else 102 | Xrc::Jid.new(message.from).node 103 | end 104 | end 105 | end 106 | end 107 | end 108 | -------------------------------------------------------------------------------- /lib/ruboty/slack.rb: -------------------------------------------------------------------------------- 1 | require "ruboty/adapters/slack" 2 | require "ruboty/slack/version" 3 | -------------------------------------------------------------------------------- /lib/ruboty/slack/version.rb: -------------------------------------------------------------------------------- 1 | module Ruboty 2 | module Slack 3 | VERSION = "0.1.12" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /ruboty-slack.gemspec: -------------------------------------------------------------------------------- 1 | lib = File.expand_path("../lib", __FILE__) 2 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 3 | require "ruboty/slack/version" 4 | 5 | Gem::Specification.new do |spec| 6 | spec.name = "ruboty-slack" 7 | spec.version = Ruboty::Slack::VERSION 8 | spec.authors = ["Ryo Nakamura"] 9 | spec.email = ["r7kamura@gmail.com"] 10 | spec.summary = "Slack adapter for Ruboty." 11 | spec.homepage = "https://github.com/r7kamura/ruboty-slack" 12 | spec.license = "MIT" 13 | 14 | spec.files = `git ls-files -z`.split("\x0") 15 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 16 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 17 | spec.require_paths = ["lib"] 18 | 19 | spec.add_dependency "ruboty", ">= 1.0.4" 20 | spec.add_dependency "xrc", ">= 0.1.8" 21 | spec.add_development_dependency "bundler", "~> 1.6" 22 | spec.add_development_dependency "rake" 23 | end 24 | --------------------------------------------------------------------------------