aws-lex-conversation 0.5.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 196357c0326b8a475650f1be193292f99818ca79b98a9957234f01b5e228caf9
4
- data.tar.gz: 4acba1d9e6647752ecb57d6fed79746214fbf5dbaba2f495085a77ebb0aa2cde
3
+ metadata.gz: 148e207d8dcce051f2fc01244390021ae5734037a3b856462cd76ccd9e4cde8a
4
+ data.tar.gz: 7f019bdc51b68e037575a60784dbe76217aabccdf15e3394515d4a404dbdd85a
5
5
  SHA512:
6
- metadata.gz: b66d860466c3514f7e4122dccc9545eaf98b3d0fd8a6535873f323c73366071197c6b545f67eef71d25f86ea1d4ddd02a334660087a7ec3c84e85dce00f9f82d
7
- data.tar.gz: d02d3473ef14600f09d78a94bf839c80dce492943956e1afe565261eca22b33dac50c1d6699687e57d97c69e95955a81a415cc122d122f05aab9393e662bd3a1
6
+ metadata.gz: 856f7ab5e25ffc87f93f3ee6f2b834acdd47cbc28adf334a22af4b152b37de435f54d3715374f33acfdf4ceebca1e2945b3557b5f72c4c5873e4b8761af5758a
7
+ data.tar.gz: e6dff0de003696ef87460e6dfdb54b94e470d4ff5b6470f43642dd259fa13b645b276d5d88413369dcacc7368004f4c93d92f38c1c50a5a18487c6cb2210e62d
@@ -5,7 +5,7 @@ require_relative 'conversation/base'
5
5
  module Aws
6
6
  module Lex
7
7
  class Conversation
8
- include Support::Responses
8
+ include Support::Mixins::Responses
9
9
 
10
10
  attr_accessor :event, :context, :lex
11
11
 
@@ -10,8 +10,11 @@ require_relative 'response/confirm_intent'
10
10
  require_relative 'response/delegate'
11
11
  require_relative 'response/elicit_intent'
12
12
  require_relative 'response/elicit_slot'
13
- require_relative 'support/responses'
13
+ require_relative 'support/mixins/responses'
14
+ require_relative 'support/mixins/slot_elicitation'
14
15
  require_relative 'support/inflector'
16
+ require_relative 'slot/elicitation'
17
+ require_relative 'slot/elicitor'
15
18
  require_relative 'type/base'
16
19
  require_relative 'type/enumeration'
17
20
  require_relative 'type/sentiment_label'
@@ -22,6 +25,7 @@ require_relative 'type/dialog_action_type'
22
25
  require_relative 'type/confirmation_status'
23
26
  require_relative 'type/fulfillment_state'
24
27
  require_relative 'type/recent_intent_summary_view'
28
+ require_relative 'type/slot'
25
29
  require_relative 'type/slot_resolution'
26
30
  require_relative 'type/slot_detail'
27
31
  require_relative 'type/current_intent'
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Lex
5
+ class Conversation
6
+ module Slot
7
+ class Elicitation
8
+ attr_accessor :name, :elicit, :message, :follow_up_message,
9
+ :content_type, :fallback, :maximum_elicitations,
10
+ :conversation
11
+
12
+ def initialize(opts = {})
13
+ self.name = opts.fetch(:name)
14
+ self.elicit = opts.fetch(:elicit) { ->(_c) { true } }
15
+ self.message = opts.fetch(:message)
16
+ self.follow_up_message = opts.fetch(:follow_up_message) { opts.fetch(:message) }
17
+ self.content_type = opts.fetch(:content_type) do
18
+ Aws::Lex::Conversation::Type::Message::ContentType.new('PlainText')
19
+ end
20
+ self.fallback = opts.fetch(:fallback) { ->(_c) {} }
21
+ self.maximum_elicitations = opts.fetch(:maximum_elicitations) { 0 }
22
+ end
23
+
24
+ def elicit!
25
+ return fallback.call(conversation) if maximum_elicitations?
26
+
27
+ increment_slot_elicitations!
28
+ conversation.elicit_slot(
29
+ slot_to_elicit: name,
30
+ message: {
31
+ contentType: content_type,
32
+ content: elicitation_content
33
+ }
34
+ )
35
+ end
36
+
37
+ def elicit?
38
+ elicit.call(conversation) && !slot.filled?
39
+ end
40
+
41
+ private
42
+
43
+ def slot
44
+ conversation.slots[name.to_sym]
45
+ end
46
+
47
+ def elicitation_content
48
+ first_elicitation? ? message : follow_up_message
49
+ end
50
+
51
+ def increment_slot_elicitations!
52
+ conversation.session[session_key] = elicitation_attempts + 1
53
+ end
54
+
55
+ def maximum_elicitations?
56
+ return false if maximum_elicitations.zero?
57
+
58
+ elicitation_attempts > maximum_elicitations
59
+ end
60
+
61
+ def first_elicitation?
62
+ elicitation_attempts == 1
63
+ end
64
+
65
+ def session_key
66
+ :"SlotElicitations_#{name}"
67
+ end
68
+
69
+ def elicitation_attempts
70
+ conversation.session[session_key].to_i
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Lex
5
+ class Conversation
6
+ module Slot
7
+ class Elicitor
8
+ attr_accessor :conversation, :elicitations
9
+
10
+ def initialize(opts = {})
11
+ self.conversation = opts.fetch(:conversation)
12
+ self.elicitations = opts.fetch(:elicitations) { [] }
13
+ elicitations.each do |elicitation|
14
+ elicitation.conversation = conversation
15
+ end
16
+ end
17
+
18
+ def elicit?
19
+ incomplete_elicitations.any?
20
+ end
21
+
22
+ def elicit!
23
+ incomplete_elicitations.first.elicit! if elicit?
24
+ end
25
+
26
+ private
27
+
28
+ def incomplete_elicitations
29
+ elicitations.select(&:elicit?)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Lex
5
+ class Conversation
6
+ module Support
7
+ module Mixins
8
+ module Responses
9
+ def close(opts = {})
10
+ params = {
11
+ session_attributes: lex.session_attributes,
12
+ recent_intent_summary_view: lex.recent_intent_summary_view
13
+ }.merge(opts)
14
+ Response::Close.new(params).to_lex
15
+ end
16
+
17
+ def confirm_intent(opts = {})
18
+ params = {
19
+ session_attributes: lex.session_attributes,
20
+ recent_intent_summary_view: lex.recent_intent_summary_view,
21
+ intent_name: lex.current_intent.name,
22
+ slots: lex.current_intent.slots
23
+ }.merge(opts)
24
+ Response::ConfirmIntent.new(params).to_lex
25
+ end
26
+
27
+ def delegate(opts = {})
28
+ params = {
29
+ session_attributes: lex.session_attributes,
30
+ recent_intent_summary_view: lex.recent_intent_summary_view,
31
+ slots: lex.current_intent.slots
32
+ }.merge(opts)
33
+ Response::Delegate.new(params).to_lex
34
+ end
35
+
36
+ def elicit_intent(opts = {})
37
+ params = {
38
+ session_attributes: lex.session_attributes,
39
+ recent_intent_summary_view: lex.recent_intent_summary_view
40
+ }.merge(opts)
41
+ Response::ElicitIntent.new(params).to_lex
42
+ end
43
+
44
+ def elicit_slot(opts = {})
45
+ params = {
46
+ session_attributes: lex.session_attributes,
47
+ recent_intent_summary_view: lex.recent_intent_summary_view,
48
+ slots: lex.current_intent.slots,
49
+ intent_name: lex.current_intent.name
50
+ }.merge(opts)
51
+ Response::ElicitSlot.new(params).to_lex
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Lex
5
+ class Conversation
6
+ module Support
7
+ module Mixins
8
+ module SlotElicitation
9
+ def self.included(base)
10
+ base.include(InstanceMethods)
11
+ base.extend(ClassMethods)
12
+ base.attr_accessor(:conversation)
13
+ base.class_attribute(:slots_to_elicit)
14
+ end
15
+
16
+ module InstanceMethods
17
+ def elicit_slots!
18
+ slot_elicitor.elicit!
19
+ end
20
+
21
+ def slots_elicitable?
22
+ slot_elicitor.elicit?
23
+ end
24
+
25
+ private
26
+
27
+ def slot_elicitor
28
+ @slot_elicitor ||= Aws::Lex::Conversation::Slot::Elicitor.new(
29
+ conversation: conversation,
30
+ elicitations: self.class.slots_to_elicit
31
+ )
32
+ end
33
+ end
34
+
35
+ module ClassMethods
36
+ def slot(opts = {})
37
+ self.slots_to_elicit ||= []
38
+ self.slots_to_elicit.push(
39
+ Aws::Lex::Conversation::Slot::Elicitation.new(opts)
40
+ )
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -13,6 +13,17 @@ module Aws
13
13
  required :confirmation_status
14
14
 
15
15
  class << self
16
+ def slots!
17
+ ->(v) do
18
+ v.each_with_object({}) do |(key, value), hash|
19
+ hash[key.to_sym] = Slot.shrink_wrap(
20
+ name: key,
21
+ value: value
22
+ )
23
+ end
24
+ end
25
+ end
26
+
16
27
  def slot_details!
17
28
  ->(v) do
18
29
  v.each_with_object({}) do |(key, value), hash|
@@ -23,7 +34,7 @@ module Aws
23
34
  end
24
35
 
25
36
  coerce(
26
- slots: symbolize_hash!,
37
+ slots: slots!,
27
38
  slot_details: slot_details!,
28
39
  confirmation_status: ConfirmationStatus
29
40
  )
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Lex
5
+ class Conversation
6
+ module Type
7
+ class Slot
8
+ include Base
9
+
10
+ required :name
11
+ required :value
12
+
13
+ def to_lex
14
+ value
15
+ end
16
+
17
+ def filled?
18
+ value.to_s != ''
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -3,7 +3,7 @@
3
3
  module Aws
4
4
  module Lex
5
5
  class Conversation
6
- VERSION = '0.5.0'
6
+ VERSION = '1.0.0'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-lex-conversation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Doyle
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: exe
14
14
  cert_chain: []
15
- date: 2020-06-23 00:00:00.000000000 Z
15
+ date: 2020-06-26 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: shrink_wrap
@@ -64,8 +64,11 @@ files:
64
64
  - lib/aws/lex/conversation/response/delegate.rb
65
65
  - lib/aws/lex/conversation/response/elicit_intent.rb
66
66
  - lib/aws/lex/conversation/response/elicit_slot.rb
67
+ - lib/aws/lex/conversation/slot/elicitation.rb
68
+ - lib/aws/lex/conversation/slot/elicitor.rb
67
69
  - lib/aws/lex/conversation/support/inflector.rb
68
- - lib/aws/lex/conversation/support/responses.rb
70
+ - lib/aws/lex/conversation/support/mixins/responses.rb
71
+ - lib/aws/lex/conversation/support/mixins/slot_elicitation.rb
69
72
  - lib/aws/lex/conversation/type/base.rb
70
73
  - lib/aws/lex/conversation/type/bot.rb
71
74
  - lib/aws/lex/conversation/type/confirmation_status.rb
@@ -87,6 +90,7 @@ files:
87
90
  - lib/aws/lex/conversation/type/sentiment_label.rb
88
91
  - lib/aws/lex/conversation/type/sentiment_response.rb
89
92
  - lib/aws/lex/conversation/type/sentiment_score.rb
93
+ - lib/aws/lex/conversation/type/slot.rb
90
94
  - lib/aws/lex/conversation/type/slot_detail.rb
91
95
  - lib/aws/lex/conversation/type/slot_resolution.rb
92
96
  - lib/aws/lex/conversation/version.rb
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Aws
4
- module Lex
5
- class Conversation
6
- module Support
7
- module Responses
8
- def close(opts = {})
9
- params = {
10
- session_attributes: lex.session_attributes,
11
- recent_intent_summary_view: lex.recent_intent_summary_view
12
- }.merge(opts)
13
- Response::Close.new(params).to_lex
14
- end
15
-
16
- def confirm_intent(opts = {})
17
- params = {
18
- session_attributes: lex.session_attributes,
19
- recent_intent_summary_view: lex.recent_intent_summary_view,
20
- intent_name: lex.current_intent.name,
21
- slots: lex.current_intent.slots
22
- }.merge(opts)
23
- Response::ConfirmIntent.new(params).to_lex
24
- end
25
-
26
- def delegate(opts = {})
27
- params = {
28
- session_attributes: lex.session_attributes,
29
- recent_intent_summary_view: lex.recent_intent_summary_view,
30
- slots: lex.current_intent.slots
31
- }.merge(opts)
32
- Response::Delegate.new(params).to_lex
33
- end
34
-
35
- def elicit_intent(opts = {})
36
- params = {
37
- session_attributes: lex.session_attributes,
38
- recent_intent_summary_view: lex.recent_intent_summary_view
39
- }.merge(opts)
40
- Response::ElicitIntent.new(params).to_lex
41
- end
42
-
43
- def elicit_slot(opts = {})
44
- params = {
45
- session_attributes: lex.session_attributes,
46
- recent_intent_summary_view: lex.recent_intent_summary_view,
47
- slots: lex.current_intent.slots,
48
- intent_name: lex.current_intent.name
49
- }.merge(opts)
50
- Response::ElicitSlot.new(params).to_lex
51
- end
52
- end
53
- end
54
- end
55
- end
56
- end