lita-wit 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -5
- data/lib/lita/actions/base.rb +17 -0
- data/lib/lita/actions/weather.rb +19 -0
- data/lib/lita/handlers/wit.rb +3 -2
- data/lib/lita/services/wit_client.rb +5 -34
- data/lib/lita/utils/context_piper.rb +10 -0
- data/lib/lita/utils/entities_navigator.rb +12 -0
- data/lib/lita-wit.rb +4 -0
- data/lita-wit.gemspec +1 -1
- data/spec/lita_config.rb +4 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50952bb8fc939112456f6b7a025624803324f07c
|
4
|
+
data.tar.gz: 5c5aa687530e808caf1ffaa62b776bc686f88b48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dc53348875a94b9256aff973f5cfaa453bad08aeceef11f11f6a165beac6d139a6714acf8dd2a53f9faa906ee7ba9eb21c08ffaba0aedc67ba620a1b4becf97
|
7
|
+
data.tar.gz: e810f236eb31fb95c2fe9f6126ec65622d013ade71d0a366fd45ac293f5738abaf7f631ff0610dff716892bfd9a61241bd8356c227f88b70e14f198e06eb9212
|
data/README.md
CHANGED
@@ -7,12 +7,14 @@ This is a [Lita](https://www.lita.io) handler to converse with [Wit.ai](https://
|
|
7
7
|
|
8
8
|
Using Lita and Wit.ai, you can easily create text or voice based bots that humans can chat with on their preferred messaging platform.
|
9
9
|
|
10
|
-
Something like this Slack snippet...
|
10
|
+
Something like this little Slack snippet...
|
11
11
|
|
12
12
|
![Example of a conversation with Lita](https://raw.github.com/dbastin/lita-wit/master/example.png)
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
The above snippet is a conversation with a Lita bot configured with a Slack adapter and this lita-wit handler.
|
15
|
+
This lita-wit handler is conversing with a publically accessible pre-configured Wit.ai chatbot - https://wit.ai/dbastin/Lita.
|
16
|
+
|
17
|
+
Once you get it up and running, you'll see that Wit.ai not only enables your robot to understand humans, it also helps you discover their unforeseen needs. It's all very clever.
|
16
18
|
|
17
19
|
## Installation
|
18
20
|
|
@@ -24,14 +26,18 @@ gem "lita-wit"
|
|
24
26
|
|
25
27
|
## Configuration
|
26
28
|
|
27
|
-
You'll need to add the Wit.ai API server access token.
|
29
|
+
You'll need to add the Wit.ai API server access token. Please sign up and fork the pre-configured Wit.ai bot.
|
30
|
+
You can configure the callback actions the robot performs by specifying a different `actions_class`
|
28
31
|
|
29
32
|
``` ruby
|
30
33
|
Lita.configure do |config|
|
31
34
|
# config... config... config...
|
32
35
|
|
33
|
-
# https://wit.ai/dbastin/Lita...
|
36
|
+
# https://wit.ai/dbastin/Lita... (fork it!)
|
34
37
|
config.handlers.wit.server_access_token = '72XXMP6VAKG2SAPLTXVQS6H5PBLVQIJW'
|
38
|
+
|
39
|
+
# default actions are in this class... (specify your own if you like)
|
40
|
+
config.handlers.wit.actions_class = Lita::Actions::Weather
|
35
41
|
end
|
36
42
|
```
|
37
43
|
|
@@ -53,3 +59,6 @@ Your robot's name will be stripped from the message we send to Wit.ai
|
|
53
59
|
|
54
60
|
[Tom Beynon](https://github.com/tombeynon) - Great handler for Cleverbot [lita-ai](https://github.com/tombeynon/lita-ai)
|
55
61
|
|
62
|
+
## License
|
63
|
+
|
64
|
+
[MIT](http://opensource.org/licenses/MIT)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Lita
|
2
|
+
module Actions
|
3
|
+
class Weather < Base
|
4
|
+
|
5
|
+
def actions(source)
|
6
|
+
super.merge({
|
7
|
+
:say => -> (session_id, context, msg) {
|
8
|
+
@robot.send_message(source, msg)
|
9
|
+
},
|
10
|
+
:merge => -> (session_id, context, entities, msg) {
|
11
|
+
Utils::ContextPiper.pipe(context, entities, 'intent', 'intent')
|
12
|
+
Utils::ContextPiper.pipe(context, entities, 'location', 'loc')
|
13
|
+
context
|
14
|
+
}
|
15
|
+
})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/lita/handlers/wit.rb
CHANGED
@@ -3,11 +3,12 @@ module Lita
|
|
3
3
|
class Wit < Handler
|
4
4
|
on :unhandled_message, :handle
|
5
5
|
config :server_access_token, type: String, required: true
|
6
|
+
config :actions_class, type: Class, required: true
|
6
7
|
|
7
8
|
def initialize(robot)
|
8
9
|
super
|
9
|
-
@bickle =
|
10
|
-
@client =
|
10
|
+
@bickle = Utils::Bickle.new(robot)
|
11
|
+
@client = Services::WitClient.new(robot)
|
11
12
|
end
|
12
13
|
|
13
14
|
def handle(payload)
|
@@ -4,45 +4,16 @@ module Lita
|
|
4
4
|
|
5
5
|
def initialize(robot)
|
6
6
|
@robot = robot
|
7
|
-
token =
|
8
|
-
@
|
7
|
+
@token = robot.config.handlers.wit.server_access_token
|
8
|
+
@actions_class = robot.config.handlers.wit.actions_class
|
9
9
|
end
|
10
10
|
|
11
11
|
def run_actions(session_id, message, context={}, max_steps=DEFAULT_MAX_STEPS)
|
12
|
-
|
13
|
-
|
12
|
+
actions = @actions_class.new(@robot).actions(message.source)
|
13
|
+
@wit = ::Wit.new(@token, actions)
|
14
|
+
stripped = Utils::AliasStripper.strip(@robot, message)
|
14
15
|
@wit.run_actions(session_id, stripped.body, context, max_steps)
|
15
16
|
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def actions
|
20
|
-
{
|
21
|
-
:say => -> (session_id, context, msg) {
|
22
|
-
@robot.send_message(@source, msg)
|
23
|
-
},
|
24
|
-
:merge => -> (session_id, context, entities, msg) {
|
25
|
-
pipe(context, entities, 'intent', 'intent')
|
26
|
-
pipe(context, entities, 'location', 'loc')
|
27
|
-
context
|
28
|
-
},
|
29
|
-
:error => -> (session_id, context, error) {
|
30
|
-
# Required, but is never ever called
|
31
|
-
},
|
32
|
-
}
|
33
|
-
end
|
34
|
-
|
35
|
-
def first_entity_value(entities, entity)
|
36
|
-
return nil unless entities.has_key? entity
|
37
|
-
val = entities[entity][0]['value']
|
38
|
-
return nil if val.nil?
|
39
|
-
val.is_a?(Hash) ? val['value'] : val
|
40
|
-
end
|
41
|
-
|
42
|
-
def pipe(context, entities, input, output)
|
43
|
-
e = first_entity_value entities, input
|
44
|
-
context[output] = e unless e.nil?
|
45
|
-
end
|
46
17
|
end
|
47
18
|
end
|
48
19
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Lita
|
2
|
+
module Utils
|
3
|
+
class EntitiesNavigator
|
4
|
+
def self.first_value(entities, entity)
|
5
|
+
return nil unless entities.has_key? entity
|
6
|
+
val = entities[entity][0]['value']
|
7
|
+
return nil if val.nil?
|
8
|
+
val.is_a?(Hash) ? val['value'] : val
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/lita-wit.rb
CHANGED
@@ -9,7 +9,11 @@ require 'lita/handlers/wit'
|
|
9
9
|
require 'lita/utils/bickle'
|
10
10
|
require 'lita/utils/aliases'
|
11
11
|
require 'lita/utils/alias_stripper'
|
12
|
+
require 'lita/utils/context_piper'
|
13
|
+
require 'lita/utils/entities_navigator'
|
12
14
|
require 'lita/services/wit_client'
|
15
|
+
require 'lita/actions/base'
|
16
|
+
require 'lita/actions/weather'
|
13
17
|
|
14
18
|
Lita::Handlers::Wit.template_root File.expand_path(
|
15
19
|
File.join('..', '..', 'templates'),
|
data/lita-wit.gemspec
CHANGED
data/spec/lita_config.rb
CHANGED
@@ -3,6 +3,9 @@ Lita.configure do |config|
|
|
3
3
|
config.robot.log_level = :info
|
4
4
|
config.robot.adapter = :shell
|
5
5
|
|
6
|
-
# https://wit.ai/dbastin/Lita...
|
6
|
+
# https://wit.ai/dbastin/Lita... (fork it!)
|
7
7
|
config.handlers.wit.server_access_token = '72XXMP6VAKG2SAPLTXVQS6H5PBLVQIJW'
|
8
|
+
|
9
|
+
# default actions are in this class... (specify your own if you like)
|
10
|
+
config.handlers.wit.actions_class = Lita::Actions::Weather
|
8
11
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-wit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damien Bastin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -179,11 +179,15 @@ files:
|
|
179
179
|
- Rakefile
|
180
180
|
- example.png
|
181
181
|
- lib/lita-wit.rb
|
182
|
+
- lib/lita/actions/base.rb
|
183
|
+
- lib/lita/actions/weather.rb
|
182
184
|
- lib/lita/handlers/wit.rb
|
183
185
|
- lib/lita/services/wit_client.rb
|
184
186
|
- lib/lita/utils/alias_stripper.rb
|
185
187
|
- lib/lita/utils/aliases.rb
|
186
188
|
- lib/lita/utils/bickle.rb
|
189
|
+
- lib/lita/utils/context_piper.rb
|
190
|
+
- lib/lita/utils/entities_navigator.rb
|
187
191
|
- lita-wit.gemspec
|
188
192
|
- locales/en.yml
|
189
193
|
- spec/lita/handlers/wit_spec.rb
|