rubotnik 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +1 -3
- data/lib/rubotnik.rb +29 -17
- data/lib/rubotnik/helpers.rb +2 -2
- data/lib/rubotnik/message_dispatch.rb +5 -5
- data/lib/rubotnik/postback_dispatch.rb +4 -4
- data/lib/rubotnik/user_store.rb +5 -5
- data/lib/rubotnik/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3475118db8de10d630af79b5d676766f8a13b1a51ac858495a5ca605960c8bcf
|
4
|
+
data.tar.gz: 52bd2b44ae5c5c781f65498418b99d5b49b50e4d3e7ae3661cf99daaf113792c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 770c79520f2bb61efce31f3c3f8666e6ce49d98cd6918d07ef166141b9615ada1e75bb6b6080b55b581bd5f81c73f7fc1e496e5d39230281980076480433b8e5
|
7
|
+
data.tar.gz: c8ce2a56f8ce8d4e5ea187fc96d0aaccdd720034da437cdd32bfc0626fa61f02ee2123733f5285fd48989f3ce51a960ea13e760a2fc5bf688332d28f55731d0f
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -408,9 +408,7 @@ Now don't forget to go back to your Facebook developer console and change the ad
|
|
408
408
|
|
409
409
|
## Coming next
|
410
410
|
|
411
|
-
*
|
412
|
-
|
413
|
-
* More powerful DSL for parsing user input and binding it to commands.
|
411
|
+
* More powerful DSL for parsing user input and binding it to commands.
|
414
412
|
|
415
413
|
* NLP integration with Wit.AI (that allow for more things then the built-in NLP capabilities of Messenger platform, including a wrapper around Wit's interactive learning methods) is in the works and will be added to the gem some time in 2018...
|
416
414
|
|
data/lib/rubotnik.rb
CHANGED
@@ -15,31 +15,43 @@ require 'ui/image_attachment'
|
|
15
15
|
require 'ui/quick_replies'
|
16
16
|
require 'sinatra'
|
17
17
|
require 'facebook/messenger'
|
18
|
+
require 'logger'
|
19
|
+
|
18
20
|
include Facebook::Messenger
|
19
21
|
|
20
22
|
module Rubotnik
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
class << self
|
24
|
+
attr_writer :logger
|
25
|
+
|
26
|
+
def logger
|
27
|
+
@logger ||= Logger.new($stdout).tap do |log|
|
28
|
+
log.progname = self.name
|
29
|
+
end
|
30
|
+
end
|
24
31
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
def route(event, &block)
|
33
|
+
if [:message, :postback].include?(event)
|
34
|
+
Bot.on event do |e|
|
35
|
+
case e
|
36
|
+
when Facebook::Messenger::Incoming::Message
|
37
|
+
Rubotnik::MessageDispatch.new(e).route(&block)
|
38
|
+
when Facebook::Messenger::Incoming::Postback
|
39
|
+
Rubotnik::PostbackDispatch.new(e).route(&block)
|
40
|
+
end
|
33
41
|
end
|
42
|
+
else
|
43
|
+
Bot.on(event, &block)
|
34
44
|
end
|
35
|
-
else
|
36
|
-
Bot.on(event, &block)
|
37
45
|
end
|
38
|
-
end
|
39
46
|
|
40
|
-
|
41
|
-
|
42
|
-
|
47
|
+
def subscribe(token)
|
48
|
+
Facebook::Messenger::Subscriptions.subscribe(access_token: token)
|
49
|
+
end
|
50
|
+
|
51
|
+
def set_profile(*payloads)
|
52
|
+
payloads.each do |payload|
|
53
|
+
Facebook::Messenger::Profile.set(payload, access_token: ENV['ACCESS_TOKEN'])
|
54
|
+
end
|
43
55
|
end
|
44
56
|
end
|
45
57
|
end
|
data/lib/rubotnik/helpers.rb
CHANGED
@@ -63,10 +63,10 @@ module Rubotnik
|
|
63
63
|
@message.typing_off
|
64
64
|
case response.code
|
65
65
|
when 200
|
66
|
-
|
66
|
+
Rubotnik.logger.info "Data received from Graph API: #{response.body}" # logging
|
67
67
|
return JSON.parse(response.body, symbolize_names: true)
|
68
68
|
else
|
69
|
-
|
69
|
+
Rubotnik.logger.info "Request failed: #{response.body}"
|
70
70
|
return false
|
71
71
|
end
|
72
72
|
end
|
@@ -20,7 +20,7 @@ module Rubotnik
|
|
20
20
|
if @user.current_command
|
21
21
|
command = @user.current_command
|
22
22
|
execute(command)
|
23
|
-
|
23
|
+
Rubotnik.logger.info "Command #{command} is executed for user #{@user.id}"
|
24
24
|
else
|
25
25
|
bind_commands(&block)
|
26
26
|
end
|
@@ -54,20 +54,20 @@ module Rubotnik
|
|
54
54
|
|
55
55
|
def handle_command(to, reply_with)
|
56
56
|
if reply_with.empty?
|
57
|
-
|
57
|
+
Rubotnik.logger.info "Command #{to} is executed for user #{@user.id}"
|
58
58
|
execute(to)
|
59
59
|
@user.reset_command
|
60
|
-
|
60
|
+
Rubotnik.logger.info "Command is reset for user #{@user.id}"
|
61
61
|
else
|
62
62
|
say(reply_with[:text], quick_replies: reply_with[:quick_replies])
|
63
63
|
@user.assign_command(to)
|
64
|
-
|
64
|
+
Rubotnik.logger.info "Command #{to} is set for user #{@user.id}"
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
def default
|
69
69
|
return if @matched
|
70
|
-
|
70
|
+
Rubotnik.logger.info 'None of the commands were recognized'
|
71
71
|
yield
|
72
72
|
@user.reset_command
|
73
73
|
end
|
@@ -31,7 +31,7 @@ module Rubotnik
|
|
31
31
|
return unless @postback.payload == regex_string.upcase
|
32
32
|
clear_user_state
|
33
33
|
@matched = true
|
34
|
-
|
34
|
+
Rubotnik.logger.info "Matched #{regex_string} to #{to.nil? ? 'block' : to}"
|
35
35
|
if block_given?
|
36
36
|
yield
|
37
37
|
return
|
@@ -42,13 +42,13 @@ module Rubotnik
|
|
42
42
|
def handle_command(to, reply_with)
|
43
43
|
if reply_with.empty?
|
44
44
|
execute(to)
|
45
|
-
|
45
|
+
Rubotnik.logger.info "Command #{to} is executed for user #{@user.id}"
|
46
46
|
@user.reset_command
|
47
|
-
|
47
|
+
Rubotnik.logger.info "Command is reset for user #{@user.id}"
|
48
48
|
else
|
49
49
|
say(reply_with[:message], quick_replies: reply_with[:quick_replies])
|
50
50
|
@user.assign_command(to)
|
51
|
-
|
51
|
+
Rubotnik.logger.info "Command #{to} is set for user #{@user.id}"
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
data/lib/rubotnik/user_store.rb
CHANGED
@@ -17,18 +17,18 @@ class Rubotnik::UserStore
|
|
17
17
|
@users << user
|
18
18
|
user = @users.last
|
19
19
|
if user
|
20
|
-
|
21
|
-
|
20
|
+
Rubotnik.logger.info "user #{user.inspect} added to store"
|
21
|
+
Rubotnik.logger.info "we got #{@users.count} users: #{@users}"
|
22
22
|
else
|
23
|
-
|
23
|
+
Rubotnik.logger.info 'user not found in store yet'
|
24
24
|
end
|
25
25
|
user
|
26
26
|
end
|
27
27
|
|
28
28
|
def find(id)
|
29
29
|
user = @users.find { |u| u.id == id }
|
30
|
-
|
31
|
-
|
30
|
+
Rubotnik.logger.info "user #{user} found in store" if user
|
31
|
+
Rubotnik.logger.info "we got #{@users.count} users: #{@users}" if user
|
32
32
|
user
|
33
33
|
end
|
34
34
|
end
|
data/lib/rubotnik/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubotnik
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Barnov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: facebook-messenger
|