socrates 0.1.18 → 0.1.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +3 -0
- data/.ruby-version +1 -1
- data/circle.yml +4 -0
- data/exe/socrates +1 -1
- data/lib/socrates/configuration.rb +2 -0
- data/lib/socrates/core/dispatcher.rb +12 -26
- data/lib/socrates/logger.rb +1 -1
- data/lib/socrates/storage/memory.rb +4 -0
- data/lib/socrates/storage/redis.rb +4 -0
- data/lib/socrates/storage/storage.rb +60 -0
- data/lib/socrates/version.rb +1 -1
- data/socrates.gemspec +10 -10
- metadata +21 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e648a9ac94de0a6fd27a051b478618c505f7027541eaa38e40677e555c22fc1a
|
4
|
+
data.tar.gz: '094d6680aefa6c2c5b64a667775c29069c9f95e9aaf953ebfcaefed5bbafef39'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e7e0ee90d0486f5a325fce2889b99f9739b76fd45696577ca3e999f18250d2f4155bc46fb8d324eadeff0d986e65a6809c6baa31d0a2bd07fbe9938a0a148dc
|
7
|
+
data.tar.gz: f8b3c910975023e89e05216eea0b05eb24d17f2af4de933d736ab40f3662ed841e3fef53224076edac5f6e5f2a1c8d160290781e96890a620f1632e0ebb90f5d
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.5.0
|
data/circle.yml
CHANGED
data/exe/socrates
CHANGED
@@ -17,12 +17,14 @@ module Socrates
|
|
17
17
|
attr_accessor :error_message
|
18
18
|
attr_accessor :expired_timeout # seconds
|
19
19
|
attr_accessor :logger
|
20
|
+
attr_accessor :error_handler # a callable proc
|
20
21
|
|
21
22
|
def initialize
|
22
23
|
@storage = Storage::Memory.new
|
23
24
|
@error_message = "Sorry, something went wrong. We'll have to start over..."
|
24
25
|
@expired_timeout = 30.minutes
|
25
26
|
@logger = Socrates::Logger.default
|
27
|
+
@error_handler = proc { |_message, _error| }
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
@@ -18,6 +18,7 @@ module Socrates
|
|
18
18
|
@storage = storage || Socrates.config.storage
|
19
19
|
|
20
20
|
@logger = Socrates.config.logger
|
21
|
+
@error_handler = Socrates.config.error_handler
|
21
22
|
@error_message = Socrates.config.error_message || DEFAULT_ERROR_MESSAGE
|
22
23
|
end
|
23
24
|
|
@@ -41,7 +42,7 @@ module Socrates
|
|
41
42
|
# return false unless conversation_state(user).nil?
|
42
43
|
|
43
44
|
# Create state data to match the request.
|
44
|
-
state_data =
|
45
|
+
state_data = StateData.new(state_id: state_id, state_action: :ask)
|
45
46
|
|
46
47
|
persist_state_data(session.client_id, state_data)
|
47
48
|
|
@@ -57,15 +58,8 @@ module Socrates
|
|
57
58
|
|
58
59
|
return nil unless @storage.has_key?(client_id)
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
state_data = StateData.deserialize(snapshot)
|
63
|
-
state_data = nil if state_data.expired? || state_data.finished?
|
64
|
-
rescue StandardError => e
|
65
|
-
@logger.warn "Error while fetching state_data for client id '#{client_id}'."
|
66
|
-
@logger.warn e
|
67
|
-
state_data = nil
|
68
|
-
end
|
61
|
+
state_data = @storage.fetch(client_id)
|
62
|
+
state_data = nil if state_data&.expired? || state_data&.finished?
|
69
63
|
|
70
64
|
state_data
|
71
65
|
end
|
@@ -119,17 +113,7 @@ module Socrates
|
|
119
113
|
|
120
114
|
# rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
121
115
|
def fetch_state_data(client_id)
|
122
|
-
|
123
|
-
begin
|
124
|
-
snapshot = @storage.get(client_id)
|
125
|
-
state_data = StateData.deserialize(snapshot)
|
126
|
-
rescue StandardError => e
|
127
|
-
@logger.warn "Error while fetching state_data for client id '#{client_id}', resetting state: #{e.message}"
|
128
|
-
@logger.warn e
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
state_data ||= StateData.new
|
116
|
+
state_data = @storage.fetch(client_id) || StateData.new
|
133
117
|
|
134
118
|
# If the current state is nil or END_OF_CONVERSATION, set it to the default state, which is typically a state
|
135
119
|
# that waits for an initial command or input from the user (e.g. help, start, etc).
|
@@ -152,8 +136,7 @@ module Socrates
|
|
152
136
|
# rubocop:enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
153
137
|
|
154
138
|
def persist_state_data(client_id, state_data)
|
155
|
-
state_data
|
156
|
-
@storage.put(client_id, state_data.serialize)
|
139
|
+
@storage.persist(client_id, state_data)
|
157
140
|
end
|
158
141
|
|
159
142
|
def instantiate_state(session, state_data)
|
@@ -168,9 +151,12 @@ module Socrates
|
|
168
151
|
state.data.state_id.nil? || state.data.state_id == StateData::END_OF_CONVERSATION
|
169
152
|
end
|
170
153
|
|
171
|
-
def handle_action_error(
|
172
|
-
|
173
|
-
@logger.warn
|
154
|
+
def handle_action_error(error, session, state)
|
155
|
+
msg = "Error while processing action #{state.data.state_id}/#{state.data.state_action}: #{error.message}"
|
156
|
+
@logger.warn msg
|
157
|
+
@logger.warn error
|
158
|
+
|
159
|
+
@error_handler.call(msg, error) if @error_handler.present?
|
174
160
|
|
175
161
|
@adapter.queue_message(session, @error_message, send_now: true)
|
176
162
|
|
data/lib/socrates/logger.rb
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
require "socrates/core/state_data"
|
2
|
+
|
3
|
+
module Socrates
|
4
|
+
module Storage
|
5
|
+
module Storage
|
6
|
+
def initialize
|
7
|
+
@logger = Socrates.config.logger
|
8
|
+
end
|
9
|
+
|
10
|
+
def fetch(client_id)
|
11
|
+
key = generate_key(client_id)
|
12
|
+
|
13
|
+
snapshot = get(key)
|
14
|
+
|
15
|
+
return if snapshot.nil?
|
16
|
+
|
17
|
+
begin
|
18
|
+
Socrates::Core::StateData.deserialize(snapshot)
|
19
|
+
rescue StandardError => e
|
20
|
+
@logger.warn "Error while fetching state_data for client id '#{client_id}', resetting state: #{e.message}"
|
21
|
+
@logger.warn e
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def persist(client_id, state_data)
|
26
|
+
key = generate_key(client_id)
|
27
|
+
state_data.reset_elapsed_time
|
28
|
+
put(key, state_data.serialize)
|
29
|
+
end
|
30
|
+
|
31
|
+
def generate_key(client_id)
|
32
|
+
client_id
|
33
|
+
end
|
34
|
+
|
35
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
36
|
+
|
37
|
+
def has_key?(key)
|
38
|
+
raise NotImplementedError
|
39
|
+
end
|
40
|
+
|
41
|
+
def clear(key)
|
42
|
+
raise NotImplementedError
|
43
|
+
end
|
44
|
+
|
45
|
+
def get(key)
|
46
|
+
raise NotImplementedError
|
47
|
+
end
|
48
|
+
|
49
|
+
def put(key, value)
|
50
|
+
raise NotImplementedError
|
51
|
+
end
|
52
|
+
|
53
|
+
def clear_all
|
54
|
+
raise NotImplementedError
|
55
|
+
end
|
56
|
+
|
57
|
+
# rubocop:enable Lint/UnusedMethodArgument
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/socrates/version.rb
CHANGED
data/socrates.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
lib = File.expand_path("
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
|
4
4
|
require "socrates/version"
|
@@ -21,17 +21,17 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.required_ruby_version = ">= 2.
|
24
|
+
spec.required_ruby_version = ">= 2.4.0"
|
25
25
|
|
26
|
-
spec.add_development_dependency "bundler", "~> 1.
|
27
|
-
spec.add_development_dependency "rake", "~> 12.
|
28
|
-
spec.add_development_dependency "rspec", "~> 3.
|
29
|
-
spec.add_development_dependency "rubocop", "~> 0.
|
30
|
-
spec.add_development_dependency "timecop", "~> 0.9
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
27
|
+
spec.add_development_dependency "rake", "~> 12.3"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.7"
|
29
|
+
spec.add_development_dependency "rubocop", "~> 0.52"
|
30
|
+
spec.add_development_dependency "timecop", "~> 0.9"
|
31
31
|
|
32
32
|
spec.add_dependency "activesupport", ">= 5.1.4"
|
33
33
|
spec.add_dependency "celluloid-io", ">= 0.17.3"
|
34
|
-
spec.add_dependency "hashie", ">= 3.5.
|
35
|
-
spec.add_dependency "redis", ">= 4.0.
|
36
|
-
spec.add_dependency "slack-ruby-client", ">= 0.
|
34
|
+
spec.add_dependency "hashie", ">= 3.5.7"
|
35
|
+
spec.add_dependency "redis", ">= 4.0.1"
|
36
|
+
spec.add_dependency "slack-ruby-client", ">= 0.11.0"
|
37
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: socrates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,70 +16,70 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.16'
|
20
20
|
type: :development
|
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: '1.
|
26
|
+
version: '1.16'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '12.
|
33
|
+
version: '12.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '12.
|
40
|
+
version: '12.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
47
|
+
version: '3.7'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
54
|
+
version: '3.7'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rubocop
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: '0.52'
|
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: 0.
|
68
|
+
version: '0.52'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: timecop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.9
|
75
|
+
version: '0.9'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.9
|
82
|
+
version: '0.9'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: activesupport
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,42 +114,42 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 3.5.
|
117
|
+
version: 3.5.7
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 3.5.
|
124
|
+
version: 3.5.7
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: redis
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: 4.0.
|
131
|
+
version: 4.0.1
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: 4.0.
|
138
|
+
version: 4.0.1
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: slack-ruby-client
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - ">="
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 0.
|
145
|
+
version: 0.11.0
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 0.
|
152
|
+
version: 0.11.0
|
153
153
|
description:
|
154
154
|
email:
|
155
155
|
- christian@carbonfive.com
|
@@ -186,6 +186,7 @@ files:
|
|
186
186
|
- lib/socrates/sample_states.rb
|
187
187
|
- lib/socrates/storage/memory.rb
|
188
188
|
- lib/socrates/storage/redis.rb
|
189
|
+
- lib/socrates/storage/storage.rb
|
189
190
|
- lib/socrates/string_helpers.rb
|
190
191
|
- lib/socrates/version.rb
|
191
192
|
- sample-conversation-console.gif
|
@@ -202,7 +203,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
202
203
|
requirements:
|
203
204
|
- - ">="
|
204
205
|
- !ruby/object:Gem::Version
|
205
|
-
version: 2.
|
206
|
+
version: 2.4.0
|
206
207
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
207
208
|
requirements:
|
208
209
|
- - ">="
|
@@ -210,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
210
211
|
version: '0'
|
211
212
|
requirements: []
|
212
213
|
rubyforge_project:
|
213
|
-
rubygems_version: 2.
|
214
|
+
rubygems_version: 2.7.4
|
214
215
|
signing_key:
|
215
216
|
specification_version: 4
|
216
217
|
summary: A micro-framework for building stateful conversational bots.
|