lita-slack-handler 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +18 -0
- data/README.md +2 -2
- data/lib/lita/handlers/slack_handler.rb +19 -3
- data/lita-slack-handler.gemspec +3 -3
- data/spec/lita/handlers/slack_handler_spec.rb +15 -7
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1955f5daca8b60f5b4d0ab9a5cf83850bed932b9
|
4
|
+
data.tar.gz: 4609c8a523f8cb8928993f9fd9c0c27d0cac3ec5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0db57c56ff22ad26274bf0a99150dafdc1f267057af7890b360d09f9acf1ca3d251602a569fb0aaea45a9990517e0a605c2e2dc51cdc3ebd979d0051f0a12b3f
|
7
|
+
data.tar.gz: b3fa2d566200305eb1356a3b4888fbf3ac66dca4f887bf7562c766e1d65fa554aad0c3f8a41cad273a712b127bc5a272fff178bb71fd619b96fcef0f1f5bdb75
|
data/.gitignore
ADDED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# lita-slack-handler
|
2
2
|
|
3
|
-
**lita-
|
4
|
-
**lita-
|
3
|
+
**lita-slack-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-slack-handler** sets up an HTTP route to accept messages from Slack:Outgoing WebHooks integrations, then feeds it into Lita.
|
5
5
|
This handler, otherwise, does nothing by itself; i.e., it does not produce any replies.
|
6
6
|
|
7
7
|
## Installation
|
@@ -11,8 +11,9 @@ module Lita
|
|
11
11
|
# Slack:Outgoing WebHook integration token
|
12
12
|
default.webhook_token = nil
|
13
13
|
default.team_domain = nil
|
14
|
+
default.ignore_user_name = nil
|
14
15
|
end
|
15
|
-
|
16
|
+
|
16
17
|
def receive(req, res)
|
17
18
|
# For security, do not run with missing config
|
18
19
|
if not config_valid?
|
@@ -25,6 +26,12 @@ module Lita
|
|
25
26
|
res.status = 403
|
26
27
|
return
|
27
28
|
end
|
29
|
+
# Ignore some requests
|
30
|
+
if ignore?(req)
|
31
|
+
log.debug "SlackHandler::receive ignoring request"
|
32
|
+
res.status = 200
|
33
|
+
return
|
34
|
+
end
|
28
35
|
res.status = 200
|
29
36
|
log.debug "SlackHandler::receive webhook_token:#{req['token']} team_domain:#{req['team_domain']}"
|
30
37
|
log.debug "SlackHandler::receive user id:#{req['user_id']} name:#{req['user_name']}"
|
@@ -67,18 +74,27 @@ module Lita
|
|
67
74
|
return valid
|
68
75
|
end
|
69
76
|
|
77
|
+
def ignore?(req)
|
78
|
+
ignore = false
|
79
|
+
if !config.ignore_user_name.nil? && req['user_name'].eql?(config.ignore_user_name)
|
80
|
+
log.warn "SlackHandler: #{req['user_name']} matches ignore_user_name #{config.ignore_user_name}"
|
81
|
+
ignore = true
|
82
|
+
end
|
83
|
+
return ignore
|
84
|
+
end
|
85
|
+
|
70
86
|
#
|
71
87
|
# Accessor shortcuts
|
72
88
|
#
|
73
89
|
def log
|
74
90
|
Lita.logger
|
75
91
|
end
|
76
|
-
|
92
|
+
|
77
93
|
def config
|
78
94
|
Lita.config.handlers.slack_handler
|
79
95
|
end
|
80
96
|
end
|
81
|
-
|
97
|
+
|
82
98
|
Lita.register_handler(SlackHandler)
|
83
99
|
end
|
84
100
|
end
|
data/lita-slack-handler.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-slack-handler"
|
3
|
-
spec.version = "0.2.
|
3
|
+
spec.version = "0.2.1"
|
4
4
|
spec.authors = ["Ken J."]
|
5
5
|
spec.email = ["kenjij@gmail.com"]
|
6
6
|
spec.description = %q{Lita handler for Slack}
|
@@ -14,9 +14,9 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
15
|
spec.require_paths = ["lib"]
|
16
16
|
|
17
|
-
spec.add_runtime_dependency "lita", "~>
|
17
|
+
spec.add_runtime_dependency "lita", "~> 3.0"
|
18
18
|
|
19
19
|
spec.add_development_dependency "bundler", "~> 1.3"
|
20
20
|
spec.add_development_dependency "rake"
|
21
|
-
spec.add_development_dependency "rspec", ">=
|
21
|
+
spec.add_development_dependency "rspec", ">= 3.0.0.beta1"
|
22
22
|
end
|
@@ -3,29 +3,28 @@ require "spec_helper"
|
|
3
3
|
describe Lita::Handlers::SlackHandler, lita_handler: true do
|
4
4
|
http_route_path = '/lita/slack-handler'
|
5
5
|
req = {}
|
6
|
-
|
6
|
+
|
7
7
|
it "registers with Lita" do
|
8
8
|
expect(Lita.handlers).to include(described_class)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "registers HTTP route POST #{http_route_path} to :receive" do
|
12
|
-
|
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)
|
12
|
+
routes_http(:post, http_route_path).to(:receive)
|
15
13
|
end
|
16
14
|
|
17
15
|
context "with valid config" do
|
18
16
|
before :each do
|
19
17
|
Lita.config.handlers.slack_handler.webhook_token = "aN1NvAlIdDuMmYt0k3n"
|
20
18
|
Lita.config.handlers.slack_handler.team_domain = "example"
|
19
|
+
Lita.config.handlers.slack_handler.ignore_user_name = "lita"
|
21
20
|
end
|
22
|
-
|
21
|
+
|
23
22
|
describe "#config_valid?" do
|
24
23
|
it 'returns true' do
|
25
24
|
expect(subject.config_valid?).to eql(true)
|
26
25
|
end
|
27
26
|
end
|
28
|
-
|
27
|
+
|
29
28
|
describe "#request_valid?" do
|
30
29
|
it 'returns true with valid request' do
|
31
30
|
req['token'] = Lita.config.handlers.slack_handler.webhook_token
|
@@ -47,6 +46,15 @@ describe Lita::Handlers::SlackHandler, lita_handler: true do
|
|
47
46
|
expect(subject.request_valid?(req)).to eql(false)
|
48
47
|
end
|
49
48
|
end
|
49
|
+
|
50
|
+
describe "#ignore?" do
|
51
|
+
it 'returns true when ignore_user_name matches user_name' do
|
52
|
+
req['token'] = Lita.config.handlers.slack_handler.webhook_token
|
53
|
+
req['team_domain'] = Lita.config.handlers.slack_handler.team_domain
|
54
|
+
req['user_name'] = 'lita'
|
55
|
+
expect(subject.ignore?(req)).to eql(true)
|
56
|
+
end
|
57
|
+
end
|
50
58
|
end
|
51
59
|
|
52
60
|
context "without valid config" do
|
@@ -54,7 +62,7 @@ describe Lita::Handlers::SlackHandler, lita_handler: true do
|
|
54
62
|
Lita.config.handlers.slack_handler.webhook_token = nil
|
55
63
|
Lita.config.handlers.slack_handler.team_domain = nil
|
56
64
|
end
|
57
|
-
|
65
|
+
|
58
66
|
describe "#config_valid?" do
|
59
67
|
it 'returns false' do
|
60
68
|
expect(subject.config_valid?).to eql(false)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-slack-handler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken J.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 3.0.0.beta1
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 3.0.0.beta1
|
69
69
|
description: Lita handler for Slack
|
70
70
|
email:
|
71
71
|
- kenjij@gmail.com
|
@@ -73,6 +73,7 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
+
- .gitignore
|
76
77
|
- Gemfile
|
77
78
|
- LICENSE
|
78
79
|
- README.md
|
@@ -103,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
104
|
version: '0'
|
104
105
|
requirements: []
|
105
106
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.2.2
|
107
108
|
signing_key:
|
108
109
|
specification_version: 4
|
109
110
|
summary: Lita handler for Slack; complement lita-slack adapter gem.
|