lita-slack-handler 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/LICENSE +19 -0
- data/README.md +63 -0
- data/Rakefile +6 -0
- data/lib/lita/handlers/slack_handler.rb +84 -0
- data/lib/lita-slack-handler.rb +1 -0
- data/lita-slack-handler.gemspec +22 -0
- data/spec/lita/handlers/slack_handler_spec.rb +64 -0
- data/spec/spec_helper.rb +2 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5069dda33ad4e37ed62c5bb41f3b229a0e08d721
|
4
|
+
data.tar.gz: c2c56ed04d8fd09c0f6c1f7b2e92bcc1a2d91a0f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ceb51b4b012fe77cdb9e3d0f0f290305c9b505a4d3884c580ee37d83478a7de7911504a096fb4e49cc80a638fe377198b0eb66a3a9f9f964de0a55fce9374b9d
|
7
|
+
data.tar.gz: 39e649c5e54076d8bb8983c87eb59f5ef16705f1c5434c8bcd6d37891dd314ce65a585de4c8f0d7360cf304b869fc38ef7b52c4cea390c59365b1b0cd913b4b4
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2013 kenjij
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# lita-slack-handler
|
2
|
+
|
3
|
+
**lita-hipchat-handler** is a handler for [Lita](https://github.com/jimmycuadra/lita) that allows you to use the robot with [Slack](https://slack.com/). This handler complements [lita-slack](https://github.com/kenjij/lita-slack) adapter gem.
|
4
|
+
**lita-hipchat-handler** sets up an HTTP route to accept messages from Slack:Outgoing WebHooks integrations, then feeds it into Lita.
|
5
|
+
This handler, otherwise, does nothing by itself; i.e., it does not produce any replies.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add **lita-slack-handler** to your Lita instance's Gemfile:
|
10
|
+
|
11
|
+
``` ruby
|
12
|
+
gem "lita-slack-handler"
|
13
|
+
```
|
14
|
+
|
15
|
+
But most likely, you'd be adding **lita-slack** gem as well:
|
16
|
+
|
17
|
+
``` ruby
|
18
|
+
gem "lita-slack"
|
19
|
+
gem "lita-slack-handler"
|
20
|
+
```
|
21
|
+
|
22
|
+
## Configuration
|
23
|
+
|
24
|
+
**First, you need to make sure your Slack team has [Outgoing WebHooks](https://my.slack.com/services/new/outgoing-webhook) integration setup with the correct Trigger Word(s) and URL:**
|
25
|
+
|
26
|
+
```
|
27
|
+
http://<Lita_server>:<Lita_port>/lita/slack-handler
|
28
|
+
```
|
29
|
+
|
30
|
+
Then, define the following attributes:
|
31
|
+
|
32
|
+
### Required attributes
|
33
|
+
|
34
|
+
* `webhook_token` (String) – Slack integration token.
|
35
|
+
* `team_domain` (String) – Slack team domain; subdomain of slack.com.
|
36
|
+
|
37
|
+
### Example lita_config.rb
|
38
|
+
|
39
|
+
``` ruby
|
40
|
+
Lita.configure do |config|
|
41
|
+
config.robot.name = "Lita"
|
42
|
+
# mention_name should match Slack integration Trigger Word
|
43
|
+
config.robot.mention_name = "@lita"
|
44
|
+
config.robot.alias = "lita"
|
45
|
+
# Most likely you'll be using with the Slack adapter
|
46
|
+
config.robot.adapter = :slack
|
47
|
+
# Lita's HTTP port is used for Slack integration
|
48
|
+
config.http.port = 8080
|
49
|
+
# lita-slack-handler config
|
50
|
+
config.handlers.slack_handler.webhook_token = "aN1NvAlIdDuMmYt0k3n"
|
51
|
+
config.handlers.slack_handler.team_domain = "example"
|
52
|
+
# Some more adapter and other config
|
53
|
+
# .....
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
## Usage
|
58
|
+
|
59
|
+
None. **lita-slack-handler** just takes messages from Slack and feeds it into Lita.
|
60
|
+
|
61
|
+
## License
|
62
|
+
|
63
|
+
[MIT](http://opensource.org/licenses/MIT)
|
data/Rakefile
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require "lita"
|
2
|
+
|
3
|
+
module Lita
|
4
|
+
module Handlers
|
5
|
+
class SlackHandler < Handler
|
6
|
+
# Lita HTTPRoute for Slack: Outgoing WebHook integration
|
7
|
+
http.post '/lita/slack-handler', :receive
|
8
|
+
|
9
|
+
# Class method called by Lita for handler configuration
|
10
|
+
def self.default_config(default)
|
11
|
+
# Slack:Outgoing WebHook integration token
|
12
|
+
default.webhook_token = nil
|
13
|
+
default.team_domain = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def receive(req, res)
|
17
|
+
# For security, do not run with missing config
|
18
|
+
if not config_valid?
|
19
|
+
res.status = 500
|
20
|
+
return
|
21
|
+
end
|
22
|
+
log.debug 'SlackHandler::receive started'
|
23
|
+
# Validate request
|
24
|
+
if not request_valid?(req)
|
25
|
+
res.status = 403
|
26
|
+
return
|
27
|
+
end
|
28
|
+
res.status = 200
|
29
|
+
log.debug "SlackHandler::receive webhook_token:#{req['token']} team_domain:#{req['team_domain']}"
|
30
|
+
log.debug "SlackHandler::receive user id:#{req['user_id']} name:#{req['user_name']}"
|
31
|
+
log.debug "SlackHandler::receive room id:#{req['channel_id']} name:#{req['channel_name']}"
|
32
|
+
log.debug "SlackHandler::receive message text size #{req['text'].size} byte(s)"
|
33
|
+
user = User.create(req['user_id'], name: req['user_name'], mention_name: req['user_name'])
|
34
|
+
# Register channel using Lita::User class
|
35
|
+
room = User.create(req['channel_id'], name: req['channel_name'])
|
36
|
+
source = Source.new(user: user, room: room.id)
|
37
|
+
message = Message.new(robot, req['text'], source)
|
38
|
+
# Route the message to the adapter
|
39
|
+
log.info 'SlackHandler::receive routing message to the adapter'
|
40
|
+
robot.receive message
|
41
|
+
log.debug 'SlackHandler::receive ending'
|
42
|
+
end
|
43
|
+
|
44
|
+
def config_valid?
|
45
|
+
valid = true
|
46
|
+
if config.webhook_token.nil?
|
47
|
+
log.error 'SlackHandler: refuse to run; missing config "webhook_token"'
|
48
|
+
valid = false
|
49
|
+
end
|
50
|
+
if config.team_domain.nil?
|
51
|
+
log.error 'SlackHandler: refuse to run; missing "team_domain"'
|
52
|
+
valid = false
|
53
|
+
end
|
54
|
+
return valid
|
55
|
+
end
|
56
|
+
|
57
|
+
def request_valid?(req)
|
58
|
+
valid = true
|
59
|
+
if req['token'] != config.webhook_token
|
60
|
+
log.warn "SlackHandler: ignoring request; token does not match (received:#{req['token']})"
|
61
|
+
valid = false
|
62
|
+
end
|
63
|
+
if req['team_domain'] != config.team_domain
|
64
|
+
log.warn "SlackHandler: ignoring request; team domain does not match (received:#{req['team_domain']})"
|
65
|
+
valid = false
|
66
|
+
end
|
67
|
+
return valid
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
71
|
+
# Accessor shortcuts
|
72
|
+
#
|
73
|
+
def log
|
74
|
+
Lita.logger
|
75
|
+
end
|
76
|
+
|
77
|
+
def config
|
78
|
+
Lita.config.handlers.slack_handler
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
Lita.register_handler(SlackHandler)
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "lita/handlers/slack_handler"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "lita-slack-handler"
|
3
|
+
spec.version = "0.2.0"
|
4
|
+
spec.authors = ["Ken J."]
|
5
|
+
spec.email = ["kenjij@gmail.com"]
|
6
|
+
spec.description = %q{Lita handler for Slack}
|
7
|
+
spec.summary = %q{Lita handler for Slack; complement lita-slack adapter gem.}
|
8
|
+
spec.homepage = "https://github.com/kenjij/lita-slack-handler"
|
9
|
+
spec.license = "MIT"
|
10
|
+
spec.metadata = { "lita_plugin_type" => "handler" }
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split($/)
|
13
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
|
+
spec.require_paths = ["lib"]
|
16
|
+
|
17
|
+
spec.add_runtime_dependency "lita", "~> 2.7"
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
spec.add_development_dependency "rspec", ">= 2.14"
|
22
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Lita::Handlers::SlackHandler, lita_handler: true do
|
4
|
+
http_route_path = '/lita/slack-handler'
|
5
|
+
req = {}
|
6
|
+
|
7
|
+
it "registers with Lita" do
|
8
|
+
expect(Lita.handlers).to include(described_class)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "registers HTTP route POST #{http_route_path} to :receive" do
|
12
|
+
expect(described_class.http_routes[0].http_method).to eql('POST')
|
13
|
+
expect(described_class.http_routes[0].path).to eql(http_route_path)
|
14
|
+
expect(described_class.http_routes[0].method_name).to eql(:receive)
|
15
|
+
end
|
16
|
+
|
17
|
+
context "with valid config" do
|
18
|
+
before :each do
|
19
|
+
Lita.config.handlers.slack_handler.webhook_token = "aN1NvAlIdDuMmYt0k3n"
|
20
|
+
Lita.config.handlers.slack_handler.team_domain = "example"
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#config_valid?" do
|
24
|
+
it 'returns true' do
|
25
|
+
expect(subject.config_valid?).to eql(true)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#request_valid?" do
|
30
|
+
it 'returns true with valid request' do
|
31
|
+
req['token'] = Lita.config.handlers.slack_handler.webhook_token
|
32
|
+
req['team_domain'] = Lita.config.handlers.slack_handler.team_domain
|
33
|
+
expect(subject.request_valid?(req)).to eql(true)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#request_valid?" do
|
38
|
+
it 'returns false with invalid token request' do
|
39
|
+
req['token'] = 'fUnKyT0K3N'
|
40
|
+
req['team_domain'] = Lita.config.handlers.slack_handler.team_domain
|
41
|
+
expect(subject.request_valid?(req)).to eql(false)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns false with invalid team_domain request' do
|
45
|
+
req['token'] = Lita.config.handlers.slack_handler.webhook_token
|
46
|
+
req['team_domain'] = 'my'
|
47
|
+
expect(subject.request_valid?(req)).to eql(false)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "without valid config" do
|
53
|
+
before :each do
|
54
|
+
Lita.config.handlers.slack_handler.webhook_token = nil
|
55
|
+
Lita.config.handlers.slack_handler.team_domain = nil
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#config_valid?" do
|
59
|
+
it 'returns false' do
|
60
|
+
expect(subject.config_valid?).to eql(false)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-slack-handler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ken J.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: lita
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.14'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.14'
|
69
|
+
description: Lita handler for Slack
|
70
|
+
email:
|
71
|
+
- kenjij@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- Gemfile
|
77
|
+
- LICENSE
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- lib/lita-slack-handler.rb
|
81
|
+
- lib/lita/handlers/slack_handler.rb
|
82
|
+
- lita-slack-handler.gemspec
|
83
|
+
- spec/lita/handlers/slack_handler_spec.rb
|
84
|
+
- spec/spec_helper.rb
|
85
|
+
homepage: https://github.com/kenjij/lita-slack-handler
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata:
|
89
|
+
lita_plugin_type: handler
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.0.7
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Lita handler for Slack; complement lita-slack adapter gem.
|
110
|
+
test_files:
|
111
|
+
- spec/lita/handlers/slack_handler_spec.rb
|
112
|
+
- spec/spec_helper.rb
|