socrates 0.1.17 → 0.1.18
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 +6 -5
- data/lib/socrates/adapters/adapter.rb +14 -11
- data/lib/socrates/adapters/slack.rb +5 -10
- data/lib/socrates/adapters/stubs.rb +6 -12
- data/lib/socrates/core/state.rb +1 -1
- data/lib/socrates/sample_states.rb +1 -1
- data/lib/socrates/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67a86f6c23427a17a1271fc44b51b656b7e3e8c6
|
4
|
+
data.tar.gz: 331e7f16f68d78ca66490fc985861418cc891bf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8445176b8a001cbe6957e23f9e4f4909f376439d9cc0aa045a5f23ecfbeccd850331c1f31313f8a12987222ab8f70900d2bf0a2fd472b6b62b0c0c63a0aeee2
|
7
|
+
data.tar.gz: ff3aeced1731694a2fe660658c83c24f2e21db08755531a64639046e66ab39ad2190c0796d27af612547a5793646ce0345f0441fb15c4d2070437f911c8b0907
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -153,11 +153,12 @@ restarting the bot. Use the `-d` flag for debugging log information.
|
|
153
153
|
|
154
154
|
## Core Concepts
|
155
155
|
|
156
|
-
* Dispatcher
|
157
|
-
*
|
158
|
-
*
|
159
|
-
*
|
160
|
-
*
|
156
|
+
* Dispatcher - Kicks off conversations, responds to input, and provides general state managements.
|
157
|
+
* Session - Buffers messages to channels, until flushed by an Adapter.
|
158
|
+
* Adapter (Slack, Console, Memory) - Captures service specific functionality.
|
159
|
+
* Storage (Memory, Redis) - Handles persisting conversational state.
|
160
|
+
* State - Represents a state of a conversation, provides helpers for state implementations.
|
161
|
+
* Helpers - Simple helpers.
|
161
162
|
|
162
163
|
TODO: Expand descriptions. Include a diagram.
|
163
164
|
|
@@ -3,11 +3,16 @@ require "socrates/adapters/stubs"
|
|
3
3
|
module Socrates
|
4
4
|
module Adapters
|
5
5
|
module Adapter
|
6
|
-
|
6
|
+
# Many of the methods in the Adapter module serve as an interface for Adapter implementations to
|
7
|
+
# implement. We want to serve as an example, even if we don't provide implementations here. Therefor,
|
8
|
+
# we're disabling this cop to avoid its warnings.
|
9
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
10
|
+
|
11
|
+
def client_id_from(context: nil, user: nil)
|
7
12
|
raise NotImplementedError
|
8
13
|
end
|
9
14
|
|
10
|
-
def channel_from(
|
15
|
+
def channel_from(context: nil, user: nil)
|
11
16
|
raise NotImplementedError
|
12
17
|
end
|
13
18
|
|
@@ -21,7 +26,7 @@ module Socrates
|
|
21
26
|
|
22
27
|
def queue_direct_message(session, message, recipient)
|
23
28
|
raise ArgumentError, "recipient is required" unless recipient.present?
|
24
|
-
raise ArgumentError, "recipient.
|
29
|
+
raise ArgumentError, "recipient.id is required" unless recipient.id.present?
|
25
30
|
|
26
31
|
dm_channel = channel_from(user: recipient)
|
27
32
|
|
@@ -35,29 +40,27 @@ module Socrates
|
|
35
40
|
end
|
36
41
|
end
|
37
42
|
|
38
|
-
def send_message(
|
43
|
+
def send_message(channel, message)
|
39
44
|
raise NotImplementedError
|
40
45
|
end
|
41
46
|
|
42
|
-
def
|
47
|
+
def users(include_deleted: false, include_bots: false)
|
43
48
|
raise NotImplementedError
|
44
49
|
end
|
45
50
|
|
46
|
-
def
|
51
|
+
def user_from(context:)
|
47
52
|
raise NotImplementedError
|
48
53
|
end
|
49
54
|
|
50
|
-
def lookup_user(
|
51
|
-
|
55
|
+
def lookup_user(email:)
|
56
|
+
users.members.find { |user| email == user.profile&.email }
|
52
57
|
end
|
53
58
|
|
54
59
|
def lookup_email(*)
|
55
60
|
raise NotImplementedError
|
56
61
|
end
|
57
62
|
|
58
|
-
|
59
|
-
raise NotImplementedError
|
60
|
-
end
|
63
|
+
# rubocop:enable Lint/UnusedMethodArgument
|
61
64
|
end
|
62
65
|
end
|
63
66
|
end
|
@@ -27,18 +27,18 @@ module Socrates
|
|
27
27
|
raise ArgumentError, "Expected context to respond to :channel" unless context.respond_to?(:channel)
|
28
28
|
return context.channel
|
29
29
|
end
|
30
|
-
return
|
30
|
+
return lookup_dm_channel(user) unless user.nil?
|
31
31
|
|
32
32
|
raise ArgumentError, "Must provide one of context or user"
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
35
|
+
def users(include_deleted: false, include_bots: false)
|
36
36
|
client = @real_time_client.web_client
|
37
37
|
|
38
|
-
client.users_list.tap
|
38
|
+
client.users_list.tap { |response|
|
39
39
|
response.members.reject!(&:deleted?) unless include_deleted
|
40
40
|
response.members.reject!(&:is_bot?) unless include_bots
|
41
|
-
|
41
|
+
}.members
|
42
42
|
end
|
43
43
|
|
44
44
|
def user_from(context:)
|
@@ -50,11 +50,6 @@ module Socrates
|
|
50
50
|
info.present? ? info.user : nil
|
51
51
|
end
|
52
52
|
|
53
|
-
# Note: this triggers a call to the Slack API which makes it ill-suited for use within a loop.
|
54
|
-
def lookup_user(email:)
|
55
|
-
users_list.members.find { |user| email == user.profile&.email }
|
56
|
-
end
|
57
|
-
|
58
53
|
def lookup_email(context:)
|
59
54
|
raise ArgumentError, "Expected context to respond to :user" unless context.respond_to?(:user)
|
60
55
|
|
@@ -69,7 +64,7 @@ module Socrates
|
|
69
64
|
@real_time_client.message(text: message, channel: channel)
|
70
65
|
end
|
71
66
|
|
72
|
-
def
|
67
|
+
def lookup_dm_channel(user)
|
73
68
|
im = @real_time_client.ims.values.find { |i| i.user == user }
|
74
69
|
|
75
70
|
return im if im.present?
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module Socrates
|
2
2
|
module Adapters
|
3
3
|
#
|
4
|
-
#
|
4
|
+
# User, Profile are POROs that represent keys concepts that exist in Slack (or other chat systems).
|
5
5
|
#
|
6
|
-
Response = Struct.new(:members)
|
7
|
-
|
8
6
|
User = Struct.new(:id, :name, :tz_offset, :profile) do
|
9
7
|
def real_name
|
10
8
|
return "" if profile.nil?
|
@@ -20,7 +18,7 @@ module Socrates
|
|
20
18
|
# to be used by the stubbed versions of adapters (like Console and Memory).
|
21
19
|
#
|
22
20
|
module StubUserDirectory
|
23
|
-
attr_accessor :default_user
|
21
|
+
attr_accessor :default_user
|
24
22
|
|
25
23
|
def initialize
|
26
24
|
@users = []
|
@@ -34,16 +32,12 @@ module Socrates
|
|
34
32
|
end
|
35
33
|
# rubocop:enable Metrics/ParameterLists
|
36
34
|
|
37
|
-
def
|
38
|
-
@
|
35
|
+
def users(*)
|
36
|
+
@users
|
39
37
|
end
|
40
38
|
|
41
|
-
def
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
def lookup_user(email:)
|
46
|
-
@users.find { |user| email == user.profile&.email }
|
39
|
+
def user_from(*)
|
40
|
+
@default_user
|
47
41
|
end
|
48
42
|
|
49
43
|
def lookup_email(*)
|
data/lib/socrates/core/state.rb
CHANGED
@@ -51,7 +51,7 @@ module Socrates
|
|
51
51
|
@adapter.queue_message(@session, message, send_now: send_now)
|
52
52
|
end
|
53
53
|
|
54
|
-
def send_message(to:, message:)
|
54
|
+
def send_message(to:, message:)
|
55
55
|
displayable_to = to.respond_to?(:id) ? to.id : to
|
56
56
|
|
57
57
|
@logger.info %Q(#{@session.channel} send direct to #{displayable_to}: "#{format_for_logging(message)}")
|
data/lib/socrates/version.rb
CHANGED
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.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|