aws-lex-conversation 2.1.0 → 3.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: 50a4b4cc2a28aa4251723f715953de0a102e7cabb0268db095e50470e49e2772
4
- data.tar.gz: a5bd7550ef4a7391c0d9221ac86b3c1760053b03dda9932d8416778f4ea319e5
3
+ metadata.gz: fa157d03f135f23dbb377c404c89d946dffc0439351be55426e30fdb5f77f503
4
+ data.tar.gz: 309f7a91e31d11ef76fa53170cfa64baf78ba444ee092cb4244104501e26860f
5
5
  SHA512:
6
- metadata.gz: 48883e2e7ce637dc0b6a327bdf839b9e233a3a1bc06f99b318f5bdbf83e91c762fb8c2bbe1ffc597ac8a6900d7a01ee4dfab7a67a52c2f941595754e13f8cb06
7
- data.tar.gz: 3bf93255a75da95213ffc74a7a3a86785bba94ea70d758c53dbad1c351b3567f5bb6f23adffafbf67e7581ad9f4a9ece31a489ef35b9cd3ad31311121a209105
6
+ metadata.gz: eb6c81ac0fa0372aa686fbdd2ce14aba638c3ef304601e3658413d365148bd57b62d2a4020e2e8aa84d53d66ee2130dbf9a892834258c5692d71afe8756270eb
7
+ data.tar.gz: 10fe3f5e93bdfdd13c7a5aee638e6820a73b9f1f55190ce10795ce28df78ec3ecef8395c9ac92495b1b7352826cc8bf1e4d865590c5bf984005d66d3911cc048
@@ -57,6 +57,55 @@ module Aws
57
57
  def session
58
58
  lex.session_attributes
59
59
  end
60
+
61
+ # rubocop:disable Metrics/AbcSize
62
+ def checkpoint!(opts = {})
63
+ label = opts.fetch(:label)
64
+ intent = opts.fetch(:intent_name) { intent_name }
65
+ params = {
66
+ checkpoint_label: label,
67
+ confirmation_status: opts.fetch(:confirmation_status) { lex.current_intent.confirmation_status },
68
+ dialog_action_type: opts.fetch(:dialog_action_type),
69
+ fulfillment_state: opts[:fulfillment_state],
70
+ intent_name: intent,
71
+ slots: opts.fetch(:slots) { lex.current_intent.raw_slots },
72
+ slot_to_elicit: opts[:slot_to_elicit]
73
+ }.compact
74
+
75
+ # flag that we need to send a new checkpoint back in the response
76
+ stash[:checkpoint_pending] = true
77
+
78
+ if checkpoint?(label: label)
79
+ # update the existing checkpoint
80
+ checkpoint(label: label).assign_attributes!(params)
81
+ else
82
+ # push a new checkpoint to the recent_intent_summary_view
83
+ lex.recent_intent_summary_view.unshift(
84
+ Type::RecentIntentSummaryView.new(params)
85
+ )
86
+ end
87
+ end
88
+ # rubocop:enable Metrics/AbcSize
89
+
90
+ def checkpoint?(label:)
91
+ lex.recent_intent_summary_view.any? { |v| v.checkpoint_label == label }
92
+ end
93
+
94
+ def checkpoint(label:)
95
+ lex.recent_intent_summary_view.find { |v| v.checkpoint_label == label }
96
+ end
97
+
98
+ # NOTE: lex responses should only include a recent_intent_summary_view
99
+ # block if we want to change/add an existing checkpoint. If we don't
100
+ # send a recent_intent_summary_view back in the response, lex retains
101
+ # the previous intent history.
102
+ def pending_checkpoints
103
+ stash[:checkpoint_pending] && lex.recent_intent_summary_view
104
+ end
105
+
106
+ def stash
107
+ @stash ||= {}
108
+ end
60
109
  end
61
110
  end
62
111
  end
@@ -9,7 +9,7 @@ module Aws
9
9
  def close(opts = {})
10
10
  params = {
11
11
  active_contexts: lex.active_contexts,
12
- recent_intent_summary_view: lex.recent_intent_summary_view,
12
+ recent_intent_summary_view: pending_checkpoints,
13
13
  session_attributes: lex.session_attributes
14
14
  }.merge(opts)
15
15
  Response::Close.new(params).to_lex
@@ -19,7 +19,7 @@ module Aws
19
19
  params = {
20
20
  active_contexts: lex.active_contexts,
21
21
  intent_name: lex.current_intent.name,
22
- recent_intent_summary_view: lex.recent_intent_summary_view,
22
+ recent_intent_summary_view: pending_checkpoints,
23
23
  session_attributes: lex.session_attributes,
24
24
  slots: lex.current_intent.slots
25
25
  }.merge(opts)
@@ -29,7 +29,7 @@ module Aws
29
29
  def delegate(opts = {})
30
30
  params = {
31
31
  active_contexts: lex.active_contexts,
32
- recent_intent_summary_view: lex.recent_intent_summary_view,
32
+ recent_intent_summary_view: pending_checkpoints,
33
33
  session_attributes: lex.session_attributes,
34
34
  slots: lex.current_intent.slots
35
35
  }.merge(opts)
@@ -39,7 +39,7 @@ module Aws
39
39
  def elicit_intent(opts = {})
40
40
  params = {
41
41
  active_contexts: lex.active_contexts,
42
- recent_intent_summary_view: lex.recent_intent_summary_view,
42
+ recent_intent_summary_view: pending_checkpoints,
43
43
  session_attributes: lex.session_attributes
44
44
  }.merge(opts)
45
45
  Response::ElicitIntent.new(params).to_lex
@@ -49,7 +49,7 @@ module Aws
49
49
  params = {
50
50
  active_contexts: lex.active_contexts,
51
51
  intent_name: lex.current_intent.name,
52
- recent_intent_summary_view: lex.recent_intent_summary_view,
52
+ recent_intent_summary_view: pending_checkpoints,
53
53
  session_attributes: lex.session_attributes,
54
54
  slots: lex.current_intent.slots
55
55
  }.merge(opts)
@@ -17,7 +17,7 @@ module Aws
17
17
  required :output_dialog_mode
18
18
  required :message_version
19
19
  required :session_attributes
20
- required :recent_intent_summary_view
20
+ required :recent_intent_summary_view, default: -> { [] }
21
21
  optional :request_attributes
22
22
  optional :sentiment_response
23
23
  optional :kendra_response
@@ -14,8 +14,14 @@ module Aws
14
14
  optional :nlu_intent_confidence_score
15
15
 
16
16
  computed_property :slots, ->(instance) do
17
- instance.raw_slots.each_with_object({}) do |(key, value), hash|
17
+ # any keys indexed without a value will return an empty Slot instance
18
+ default_hash = Hash.new do |_hash, key|
19
+ Slot.new(active: false, name: key.to_sym, value: nil, current_intent: instance)
20
+ end
21
+
22
+ instance.raw_slots.each_with_object(default_hash) do |(key, value), hash|
18
23
  hash[key.to_sym] = Slot.shrink_wrap(
24
+ active: true,
19
25
  name: key,
20
26
  value: value,
21
27
  # pass a reference to the parent down to the slot so that each slot
@@ -11,10 +11,10 @@ module Aws
11
11
  required :slots
12
12
  required :confirmation_status
13
13
  required :dialog_action_type
14
- required :slot_to_elicit
15
14
 
16
- optional :fulfillment_state
17
15
  optional :checkpoint_label
16
+ optional :fulfillment_state
17
+ optional :slot_to_elicit
18
18
 
19
19
  coerce(
20
20
  slots: symbolize_hash!,
@@ -22,6 +22,47 @@ module Aws
22
22
  dialog_action_type: DialogActionType,
23
23
  fulfillment_state: FulfillmentState
24
24
  )
25
+
26
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
27
+ def restore(conversation, opts = {})
28
+ case dialog_action_type.raw
29
+ when 'Close'
30
+ conversation.close(
31
+ fulfillment_state: opts.fetch(:fulfillment_state) { fulfillment_state },
32
+ message: opts.fetch(:message),
33
+ response_card: opts[:response_card]
34
+ )
35
+ when 'ConfirmIntent'
36
+ conversation.confirm_intent(
37
+ intent_name: intent_name,
38
+ message: opts.fetch(:message),
39
+ response_card: opts[:response_card],
40
+ slots: slots
41
+ )
42
+ when 'Delegate'
43
+ conversation.delegate(
44
+ kendra_query_request_payload: opts[:kendra_query_request_payload],
45
+ kendra_query_filter_string: opts[:kendra_query_filter_string],
46
+ slots: slots
47
+ )
48
+ when 'ElicitIntent'
49
+ conversation.elicit_intent(
50
+ message: opts.fetch(:message),
51
+ response_card: opts[:response_card]
52
+ )
53
+ when 'ElicitSlot'
54
+ conversation.elicit_slot(
55
+ intent_name: intent_name,
56
+ message: opts.fetch(:message),
57
+ response_card: opts[:response_card],
58
+ slots: slots,
59
+ slot_to_elicit: slot_to_elicit
60
+ )
61
+ else
62
+ raise ArgumentError, "invalid DialogActionType: `#{dialog_action_type.raw}`"
63
+ end
64
+ end
65
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
25
66
  end
26
67
  end
27
68
  end
@@ -10,6 +10,7 @@ module Aws
10
10
  required :current_intent, from: :current_intent, virtual: true
11
11
  required :name
12
12
  required :value
13
+ optional :active, virtual: true
13
14
 
14
15
  def as_json(_opts = {})
15
16
  to_lex
@@ -19,10 +20,23 @@ module Aws
19
20
  value
20
21
  end
21
22
 
23
+ def active?
24
+ @active
25
+ end
26
+
22
27
  def filled?
23
28
  value.to_s != ''
24
29
  end
25
30
 
31
+ def blank?
32
+ !filled?
33
+ end
34
+
35
+ def value=(other)
36
+ @value = other
37
+ current_intent.raw_slots[name] = @value
38
+ end
39
+
26
40
  def resolve!(index: 0)
27
41
  self.value = resolved(index: index)
28
42
  end
@@ -39,6 +53,10 @@ module Aws
39
53
  details.resolutions.any?
40
54
  end
41
55
 
56
+ def requestable?
57
+ active? && blank?
58
+ end
59
+
42
60
  def details
43
61
  @details ||= current_intent.slot_details.fetch(name.to_sym) do
44
62
  SlotDetail.new(name: name, resolutions: [], original_value: value)
@@ -3,7 +3,7 @@
3
3
  module Aws
4
4
  module Lex
5
5
  class Conversation
6
- VERSION = '2.1.0'
6
+ VERSION = '3.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: 2.1.0
4
+ version: 3.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: 2021-02-11 00:00:00.000000000 Z
15
+ date: 2021-05-27 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: shrink_wrap
@@ -120,7 +120,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  requirements: []
123
- rubygems_version: 3.1.4
123
+ rubyforge_project:
124
+ rubygems_version: 2.7.6
124
125
  signing_key:
125
126
  specification_version: 4
126
127
  summary: AWS Lex Conversation Dialog Management