lita-visitor-notification-handler 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +48 -0
- data/Rakefile +6 -0
- data/lib/lita-visitor-notification-handler.rb +12 -0
- data/lib/lita/handlers/visitor_notification_handler.rb +43 -0
- data/lita-visitor-notification-handler.gemspec +24 -0
- data/locales/en.yml +4 -0
- data/spec/lita/handlers/visitor_notification_handler_spec.rb +29 -0
- data/spec/spec_helper.rb +6 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 37ff9bc4df49f4ce7e318888008fc971f1dae65e
|
4
|
+
data.tar.gz: 90a875303a0214f9afdfe3429d1f6d483c372a4e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8fe2f01c81df1fc4aaf808ede67372eed45675aeaafb3138aa8484f39a8bb0a9a2875d4b9480078d449b1ab64fb19eff6a38f7c00f928caae82f1b47d55328f0
|
7
|
+
data.tar.gz: 378bbcafefe056f3eb151d9e6bb26340f8e343687e84c7fbd45d6ac76fd3380f9ea0355db836177d5a9bb482a64660d21d9318d6a7a580da60db909eccd1a7e7
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Envoy
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# lita-visitor-notification-handler
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/envoy/lita-visitor-notification-handler.svg?branch=master)](https://travis-ci.org/envoy/lita-visitor-notification-handler)
|
4
|
+
|
5
|
+
Lita handler for parsing Envoy visitor notification message
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add lita-visitor-notification-handler to your Lita instance's Gemfile:
|
10
|
+
|
11
|
+
``` ruby
|
12
|
+
gem "lita-visitor-notification-handler"
|
13
|
+
```
|
14
|
+
|
15
|
+
## Configuration
|
16
|
+
|
17
|
+
To make this handler send a post request to your webhook, you can specify `webhook_url`
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
Lita.configure do |config|
|
21
|
+
config.handlers.visitor_notification_handler.webhook_url = 'http://my-webhook.com'
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
If you need extra headers for the post request, you can also use `webhook_headers` to specify it.
|
26
|
+
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
This handler monitors private messages to it, when it sees Envoy visitor notification message, it parses it and reply the extracted data
|
31
|
+
|
32
|
+
```
|
33
|
+
Envoy ッ:
|
34
|
+
Hello! John Doe is here without a specified host at the Envoy front desk.
|
35
|
+
|
36
|
+
Lita bot:
|
37
|
+
{"guest_name":"John Doe","location_name":"Envoy"}
|
38
|
+
```
|
39
|
+
|
40
|
+
It also makes a post request callback to the webhook you provided, the body will be JSON in this format
|
41
|
+
|
42
|
+
```JSON
|
43
|
+
{
|
44
|
+
"host_name": "Host name",
|
45
|
+
"guest_name": "Visitor name",
|
46
|
+
"location_name": "Location name"
|
47
|
+
}
|
48
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "lita"
|
2
|
+
|
3
|
+
Lita.load_locales Dir[File.expand_path(
|
4
|
+
File.join("..", "..", "locales", "*.yml"), __FILE__
|
5
|
+
)]
|
6
|
+
|
7
|
+
require "lita/handlers/visitor_notification_handler"
|
8
|
+
|
9
|
+
Lita::Handlers::VisitorNotificationHandler.template_root File.expand_path(
|
10
|
+
File.join("..", "..", "templates"),
|
11
|
+
__FILE__
|
12
|
+
)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
module Lita
|
5
|
+
module Handlers
|
6
|
+
class VisitorNotificationHandler < Handler
|
7
|
+
# URL to webhook when we see a visitor noticiation
|
8
|
+
config :webhook_url
|
9
|
+
# header for webhook request
|
10
|
+
config :webhook_headers
|
11
|
+
|
12
|
+
route(/^(.+) is here to see you at (.+) - front desk\.$/, :notify_visitor)
|
13
|
+
route(/^(.+) is here at (.+) - front desk\.$/, :notify_visitor)
|
14
|
+
|
15
|
+
def notify_visitor(response)
|
16
|
+
groups = response.matches[0]
|
17
|
+
if groups.size == 2
|
18
|
+
notification = {
|
19
|
+
:guest_name => groups[0],
|
20
|
+
:location_name => groups[1],
|
21
|
+
}
|
22
|
+
else
|
23
|
+
notification = {
|
24
|
+
:host_name => groups[0],
|
25
|
+
:guest_name => groups[1],
|
26
|
+
:location_name => groups[2],
|
27
|
+
}
|
28
|
+
end
|
29
|
+
payload = notification.to_json
|
30
|
+
if config.webhook_url
|
31
|
+
resp = HTTParty.post(
|
32
|
+
config.webhook_url,
|
33
|
+
body: payload,
|
34
|
+
headers: config.webhook_headers,
|
35
|
+
)
|
36
|
+
end
|
37
|
+
response.reply(payload)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
Lita.register_handler(VisitorNotificationHandler)
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "lita-visitor-notification-handler"
|
3
|
+
spec.version = "0.0.3"
|
4
|
+
spec.authors = ["Victor Lin"]
|
5
|
+
spec.email = ["victor@signwithenvoy.com"]
|
6
|
+
spec.summary = "Lita handler for parsing Envoy visitor notification message"
|
7
|
+
spec.homepage = "https://github.com/envoy/lita-visitor-notification-handler"
|
8
|
+
spec.license = "MIT"
|
9
|
+
spec.metadata = { "lita_plugin_type" => "handler" }
|
10
|
+
|
11
|
+
spec.files = `git ls-files`.split($/)
|
12
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
13
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
14
|
+
spec.require_paths = ["lib"]
|
15
|
+
|
16
|
+
spec.add_runtime_dependency "lita", ">= 4.3"
|
17
|
+
spec.add_runtime_dependency "httparty"
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "pry-byebug"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rack-test"
|
23
|
+
spec.add_development_dependency "rspec", ">= 3.0.0"
|
24
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Lita::Handlers::VisitorNotificationHandler, lita_handler: true do
|
5
|
+
it { is_expected.not_to route('How are you doing') }
|
6
|
+
it { is_expected.not_to route('To code or not to code, that is a question') }
|
7
|
+
it { is_expected.not_to route('How do you turn this one?') }
|
8
|
+
it { is_expected.not_to route('YOLO') }
|
9
|
+
it { is_expected.not_to route('lol') }
|
10
|
+
it { is_expected.to route('foo bar is here to see you at Envoy - front desk.') }
|
11
|
+
it { is_expected.to route('af1c3a41-b65d-4ee5-8f07-4a76ffcd1528 is here to see you at Envoy - front desk.') }
|
12
|
+
it { is_expected.to route('0c984ee5-1e07-4344-b726-2a3e10284c32 is here at Envoy - front desk.') }
|
13
|
+
it { is_expected.to route('Foo bar is here at Envoy - front desk.') }
|
14
|
+
|
15
|
+
it 'consumes and replies message' do
|
16
|
+
send_message('foo bar is here to see you at Envoy - front desk.')
|
17
|
+
expect(JSON.parse(replies.last)).to eq({
|
18
|
+
'guest_name' => 'foo bar',
|
19
|
+
'location_name' => 'Envoy',
|
20
|
+
})
|
21
|
+
end
|
22
|
+
it 'consumes UUID guest name and replies message' do
|
23
|
+
send_message('af1c3a41-b65d-4ee5-8f07-4a76ffcd1528 is here to see you at Big Brother - front desk.')
|
24
|
+
expect(JSON.parse(replies.last)).to eq({
|
25
|
+
'guest_name' => 'af1c3a41-b65d-4ee5-8f07-4a76ffcd1528',
|
26
|
+
'location_name' => 'Big Brother',
|
27
|
+
})
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
require "lita-visitor-notification-handler"
|
2
|
+
require "lita/rspec"
|
3
|
+
|
4
|
+
# A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
|
5
|
+
# was generated with Lita 4, the compatibility mode should be left disabled.
|
6
|
+
Lita.version_3_compatibility_mode = false
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-visitor-notification-handler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Victor Lin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-19 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: '4.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rack-test
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.0.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 3.0.0
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- victor@signwithenvoy.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".travis.yml"
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- lib/lita-visitor-notification-handler.rb
|
125
|
+
- lib/lita/handlers/visitor_notification_handler.rb
|
126
|
+
- lita-visitor-notification-handler.gemspec
|
127
|
+
- locales/en.yml
|
128
|
+
- spec/lita/handlers/visitor_notification_handler_spec.rb
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
homepage: https://github.com/envoy/lita-visitor-notification-handler
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata:
|
134
|
+
lita_plugin_type: handler
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.5.1
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: Lita handler for parsing Envoy visitor notification message
|
155
|
+
test_files:
|
156
|
+
- spec/lita/handlers/visitor_notification_handler_spec.rb
|
157
|
+
- spec/spec_helper.rb
|
158
|
+
has_rdoc:
|