aws-lex-conversation 3.0.0 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +42 -0
  3. data/README.md +28 -6
  4. data/lib/aws/lex/conversation.rb +9 -21
  5. data/lib/aws/lex/conversation/base.rb +13 -10
  6. data/lib/aws/lex/conversation/handler/delegate.rb +1 -3
  7. data/lib/aws/lex/conversation/handler/echo.rb +6 -4
  8. data/lib/aws/lex/conversation/response/base.rb +11 -10
  9. data/lib/aws/lex/conversation/response/close.rb +5 -11
  10. data/lib/aws/lex/conversation/response/confirm_intent.rb +4 -13
  11. data/lib/aws/lex/conversation/response/delegate.rb +4 -11
  12. data/lib/aws/lex/conversation/response/elicit_intent.rb +4 -7
  13. data/lib/aws/lex/conversation/response/elicit_slot.rb +5 -12
  14. data/lib/aws/lex/conversation/slot/elicitation.rb +6 -4
  15. data/lib/aws/lex/conversation/support/mixins/responses.rb +14 -20
  16. data/lib/aws/lex/conversation/type/base.rb +10 -4
  17. data/lib/aws/lex/conversation/type/bot.rb +3 -1
  18. data/lib/aws/lex/conversation/type/checkpoint.rb +57 -0
  19. data/lib/aws/lex/conversation/type/{confirmation_status.rb → confirmation_state.rb} +1 -1
  20. data/lib/aws/lex/conversation/type/context.rb +4 -4
  21. data/lib/aws/lex/conversation/type/{slot_detail.rb → dialog_action.rb} +4 -4
  22. data/lib/aws/lex/conversation/type/dialog_action_type.rb +3 -3
  23. data/lib/aws/lex/conversation/type/event.rb +26 -19
  24. data/lib/aws/lex/conversation/type/{output_dialog_mode.rb → input_mode.rb} +3 -2
  25. data/lib/aws/lex/conversation/type/intent.rb +14 -23
  26. data/lib/aws/lex/conversation/type/intent_confidence.rb +5 -5
  27. data/lib/aws/lex/conversation/type/interpretation.rb +23 -0
  28. data/lib/aws/lex/conversation/type/message.rb +4 -2
  29. data/lib/aws/lex/conversation/type/message/content_type.rb +2 -1
  30. data/lib/aws/lex/conversation/type/response.rb +3 -4
  31. data/lib/aws/lex/conversation/type/response_card.rb +5 -6
  32. data/lib/aws/lex/conversation/type/{sentiment_label.rb → sentiment.rb} +1 -1
  33. data/lib/aws/lex/conversation/type/sentiment_response.rb +3 -3
  34. data/lib/aws/lex/conversation/type/sentiment_score.rb +10 -20
  35. data/lib/aws/lex/conversation/type/session_attributes.rb +29 -0
  36. data/lib/aws/lex/conversation/type/session_state.rb +25 -0
  37. data/lib/aws/lex/conversation/type/slot.rb +54 -29
  38. data/lib/aws/lex/conversation/type/{slot_resolution.rb → slot_shape.rb} +4 -3
  39. data/lib/aws/lex/conversation/type/slot_value.rb +40 -0
  40. data/lib/aws/lex/conversation/version.rb +1 -1
  41. metadata +13 -12
  42. data/lib/aws/lex/conversation/type/recent_intent_summary_view.rb +0 -70
  43. data/lib/aws/lex/conversation/type/response_card/content_type.rb +0 -17
  44. data/lib/aws/lex/conversation/type/response_card/generic_attachment.rb +0 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa157d03f135f23dbb377c404c89d946dffc0439351be55426e30fdb5f77f503
4
- data.tar.gz: 309f7a91e31d11ef76fa53170cfa64baf78ba444ee092cb4244104501e26860f
3
+ metadata.gz: 03d9728c4b5f1df6540f4d78885e99bae9c94d7ce3279c370c1b6041095dd55a
4
+ data.tar.gz: eb47cc1400d6202a616c1c408b05571ec553202f98a8e94465436e267076cc9f
5
5
  SHA512:
6
- metadata.gz: eb6c81ac0fa0372aa686fbdd2ce14aba638c3ef304601e3658413d365148bd57b62d2a4020e2e8aa84d53d66ee2130dbf9a892834258c5692d71afe8756270eb
7
- data.tar.gz: 10fe3f5e93bdfdd13c7a5aee638e6820a73b9f1f55190ce10795ce28df78ec3ecef8395c9ac92495b1b7352826cc8bf1e4d865590c5bf984005d66d3911cc048
6
+ metadata.gz: a23afc87b3d9741252853e76639e9415e47f28ee29dbf3a5010bf497579ddf3da980326e49e51f582b1cb5ce1d950217f3f0138e6cadcde6341c9d5747a54983
7
+ data.tar.gz: 829a4f55cab831b4ab96e9f62d3af7f06a78a6e3104100beb9f0aa356323436c91ad2a9a4592a22d25d62196b70bb87894f3c4b2039a655349cd92d19c3d1e5b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,45 @@
1
+ # 4.0.2 - July 20, 2021
2
+
3
+ * Defaulted input_transcript in event.rb to an empty string
4
+
5
+ # 4.0.1 - July 16, 2021
6
+
7
+ * Fix a bug with the `Aws::Lex::Conversation::Handler::Echo` class because it
8
+ didn't correctly return an array of messages required for Lex V2.
9
+ * Drop a call to `Hash#deep_symbolize_keys` so we don't implicitly rely on
10
+ ActiveSupport.
11
+ * Call `Hash#compact` when transforming a Lex response so we don't include any
12
+ `nil` values in the response.
13
+
14
+ # 4.0.0 - July 14, 2021
15
+
16
+ **breaking change** - Drop support for the Lex runtime version 1. If you are using Lex Version 1, please lock this gem to `~> 3.0.0`.
17
+ **breaking change** - Implement support and types for [Lex Version 2](https://docs.aws.amazon.com/lexv2/latest/dg/what-is.html), which implements a new Lambda [input/output event format](https://docs.aws.amazon.com/lexv2/latest/dg/lambda.html#lambda-input-format).
18
+
19
+ # 3.1.0 - June 1, 2021
20
+
21
+ * Default both `request_attributes` and `session_attributes`
22
+ to an empty Hash when the values from the event are `null`.
23
+ It is much easier to reason and write logic when you can
24
+ assume that these values are always at least a hash.
25
+
26
+ # 3.0.0 - May 20, 2021
27
+
28
+ * **breaking change** - Don't pass the `recentIntentSummaryView` back
29
+ in the Lex response unless we have modified or added an existing
30
+ checkpoint. Lex will persist the previous intent summary/history
31
+ if we do not send a `recentIntentSummaryView` value back in the
32
+ response (see [1]).
33
+ * Add a few helper methods to the `Aws::Lex::Conversation::Type::Slot`
34
+ instances:
35
+
36
+ - `active?`: returns true if the slot is defined (either optional or
37
+ required) for the current intent.
38
+ - `requestable?`: returns true if the slot is active for the current
39
+ intent and it is not filled.
40
+
41
+ [1]: https://docs.aws.amazon.com/lex/latest/dg/lambda-input-response-format.html#lambda-response-recentIntentSummaryView
42
+
1
43
  # 2.0.0 - August 19, 2020
2
44
 
3
45
  * **breaking change:** Rename `Aws::Lex::Conversation::Type::CurrentIntent` to `Aws::Lex::Conversation::Type::Intent`.
data/README.md CHANGED
@@ -6,10 +6,30 @@ Have you played around with [AWS Lex](https://aws.amazon.com/lex/) and quickly r
6
6
 
7
7
  ## Installation
8
8
 
9
+ ### Lex V1
10
+
11
+ Version 3.x is the last major version of this gem that will support Lex V1.
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'aws-lex-conversation', '~> 3.0'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ ```bash
22
+ bundle install
23
+ ```
24
+
25
+ ### Lex V2
26
+
27
+ Version 4.x and higher support Lex V2.
28
+
9
29
  Add this line to your application's Gemfile:
10
30
 
11
31
  ```ruby
12
- gem 'aws-lex-conversation'
32
+ gem 'aws-lex-conversation', '>= 4.0'
13
33
  ```
14
34
 
15
35
  And then execute:
@@ -73,15 +93,17 @@ class SayHello < Aws::Lex::Conversation::Handler::Base
73
93
  #
74
94
  # conversation.close(
75
95
  # fulfillment_state: 'Fulfilled',
76
- # message: { content: "Hello, #{name}!", contentType: 'PlainText' }
96
+ # messages: [{ content: "Hello, #{name}!", contentType: 'PlainText' }]
77
97
  # )
78
98
  #
79
99
  conversation.close(
80
100
  fulfillment_state: Aws::Lex::Conversation::Type::FulfillmentState.new('Fulfilled'),
81
- message: Aws::Lex::Conversation::Type::Message.new(
82
- content: "Hello, #{name}!",
83
- content_type: Aws::Lex::Conversation::Type::Message::ContentType.new('PlainText')
84
- )
101
+ messages: [
102
+ Aws::Lex::Conversation::Type::Message.new(
103
+ content: "Hello, #{name}!",
104
+ content_type: Aws::Lex::Conversation::Type::Message::ContentType.new('PlainText')
105
+ )
106
+ ]
85
107
  )
86
108
  end
87
109
  end
@@ -55,52 +55,40 @@ module Aws
55
55
  end
56
56
 
57
57
  def session
58
- lex.session_attributes
58
+ lex.session_state.session_attributes
59
59
  end
60
60
 
61
- # rubocop:disable Metrics/AbcSize
62
61
  def checkpoint!(opts = {})
63
62
  label = opts.fetch(:label)
64
- intent = opts.fetch(:intent_name) { intent_name }
65
63
  params = {
66
- checkpoint_label: label,
67
- confirmation_status: opts.fetch(:confirmation_status) { lex.current_intent.confirmation_status },
64
+ label: label,
68
65
  dialog_action_type: opts.fetch(:dialog_action_type),
69
66
  fulfillment_state: opts[:fulfillment_state],
70
- intent_name: intent,
71
- slots: opts.fetch(:slots) { lex.current_intent.raw_slots },
67
+ intent: lex.current_intent,
72
68
  slot_to_elicit: opts[:slot_to_elicit]
73
69
  }.compact
74
70
 
75
- # flag that we need to send a new checkpoint back in the response
76
- stash[:checkpoint_pending] = true
77
-
78
71
  if checkpoint?(label: label)
79
72
  # update the existing checkpoint
80
73
  checkpoint(label: label).assign_attributes!(params)
81
74
  else
82
75
  # push a new checkpoint to the recent_intent_summary_view
83
- lex.recent_intent_summary_view.unshift(
84
- Type::RecentIntentSummaryView.new(params)
76
+ checkpoints.unshift(
77
+ Type::Checkpoint.new(params)
85
78
  )
86
79
  end
87
80
  end
88
- # rubocop:enable Metrics/AbcSize
89
81
 
90
82
  def checkpoint?(label:)
91
- lex.recent_intent_summary_view.any? { |v| v.checkpoint_label == label }
83
+ !checkpoint(label: label).nil?
92
84
  end
93
85
 
94
86
  def checkpoint(label:)
95
- lex.recent_intent_summary_view.find { |v| v.checkpoint_label == label }
87
+ checkpoints.find { |v| v.label == label }
96
88
  end
97
89
 
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
90
+ def checkpoints
91
+ lex.session_state.session_attributes.checkpoints
104
92
  end
105
93
 
106
94
  def stash
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'base64'
3
4
  require 'json'
4
5
  require 'shrink/wrap'
5
6
 
@@ -18,29 +19,31 @@ require_relative 'slot/elicitation'
18
19
  require_relative 'slot/elicitor'
19
20
  require_relative 'type/base'
20
21
  require_relative 'type/enumeration'
21
- require_relative 'type/sentiment_label'
22
+ require_relative 'type/input_mode'
23
+ require_relative 'type/sentiment'
22
24
  require_relative 'type/sentiment_score'
23
25
  require_relative 'type/sentiment_response'
24
26
  require_relative 'type/invocation_source'
25
27
  require_relative 'type/dialog_action_type'
26
- require_relative 'type/confirmation_status'
28
+ require_relative 'type/dialog_action'
29
+ require_relative 'type/confirmation_state'
27
30
  require_relative 'type/fulfillment_state'
28
31
  require_relative 'type/intent_confidence'
29
32
  require_relative 'type/time_to_live'
30
- require_relative 'type/recent_intent_summary_view'
33
+ require_relative 'type/slot_shape'
34
+ require_relative 'type/slot_value'
31
35
  require_relative 'type/slot'
32
- require_relative 'type/slot_resolution'
33
- require_relative 'type/slot_detail'
34
36
  require_relative 'type/context'
35
37
  require_relative 'type/intent'
36
- require_relative 'type/output_dialog_mode'
38
+ require_relative 'type/checkpoint'
39
+ require_relative 'type/session_attributes'
40
+ require_relative 'type/session_state'
41
+ require_relative 'type/interpretation'
37
42
  require_relative 'type/bot'
38
- require_relative 'type/message/content_type'
39
- require_relative 'type/message'
40
- require_relative 'type/response_card/content_type'
41
43
  require_relative 'type/response_card/button'
42
- require_relative 'type/response_card/generic_attachment'
43
44
  require_relative 'type/response_card'
45
+ require_relative 'type/message/content_type'
46
+ require_relative 'type/message'
44
47
  require_relative 'type/response'
45
48
  require_relative 'type/event'
46
49
  require_relative 'handler/base'
@@ -6,9 +6,7 @@ module Aws
6
6
  module Handler
7
7
  class Delegate < Base
8
8
  def response(conversation)
9
- conversation.delegate(
10
- slots: conversation.lex.current_intent.slots
11
- )
9
+ conversation.delegate
12
10
  end
13
11
  end
14
12
  end
@@ -11,10 +11,12 @@ module Aws
11
11
  fulfillment_state = options.fetch(:fulfillment_state) { Type::FulfillmentState.new('Fulfilled') }
12
12
  conversation.close(
13
13
  fulfillment_state: fulfillment_state,
14
- message: Type::Message.new(
15
- content: content,
16
- content_type: content_type
17
- )
14
+ messages: [
15
+ Type::Message.new(
16
+ content: content,
17
+ content_type: content_type
18
+ )
19
+ ]
18
20
  )
19
21
  end
20
22
  end
@@ -6,15 +6,17 @@ module Aws
6
6
  module Response
7
7
  class Base
8
8
  attr_accessor(
9
- :active_contexts,
10
- :recent_intent_summary_view,
11
- :session_attributes
9
+ :session_state,
10
+ :messages,
11
+ :request_attributes,
12
+ :fulfillment_state
12
13
  )
13
14
 
14
15
  def initialize(opts = {})
15
- self.active_contexts = opts[:active_contexts]
16
- self.recent_intent_summary_view = opts[:recent_intent_summary_view]
17
- self.session_attributes = opts[:session_attributes]
16
+ self.session_state = opts[:session_state]
17
+ self.messages = opts[:messages]
18
+ self.request_attributes = opts[:request_attributes]
19
+ session_state.intent.state = opts.fetch(:fulfillment_state) { session_state.intent.state }
18
20
  end
19
21
 
20
22
  def dialog_action
@@ -23,10 +25,9 @@ module Aws
23
25
 
24
26
  def to_lex
25
27
  Type::Response.new(
26
- active_contexts: active_contexts,
27
- dialog_action: dialog_action,
28
- recent_intent_summary_view: recent_intent_summary_view,
29
- session_attributes: session_attributes
28
+ session_state: session_state,
29
+ messages: messages,
30
+ request_attributes: request_attributes
30
31
  ).to_lex
31
32
  end
32
33
  end
@@ -5,22 +5,16 @@ module Aws
5
5
  class Conversation
6
6
  module Response
7
7
  class Close < Base
8
- attr_accessor :fulfillment_state, :message, :response_card
9
-
10
8
  def initialize(opts = {})
11
9
  super
12
- self.fulfillment_state = opts.fetch(:fulfillment_state)
13
- self.message = opts[:message]
14
- self.response_card = opts[:response_card]
10
+ session_state.dialog_action = dialog_action
11
+ session_state.intent.state = opts.fetch(:fulfillment_state)
15
12
  end
16
13
 
17
14
  def dialog_action
18
- {
19
- type: 'Close',
20
- fulfillmentState: fulfillment_state,
21
- message: message,
22
- responseCard: response_card
23
- }.compact
15
+ Aws::Lex::Conversation::Type::DialogAction.shrink_wrap(
16
+ type: 'Close'
17
+ )
24
18
  end
25
19
  end
26
20
  end
@@ -5,24 +5,15 @@ module Aws
5
5
  class Conversation
6
6
  module Response
7
7
  class ConfirmIntent < Base
8
- attr_accessor :intent_name, :message, :response_card, :slots
9
-
10
8
  def initialize(opts = {})
11
9
  super
12
- self.intent_name = opts.fetch(:intent_name)
13
- self.slots = opts[:slots]
14
- self.message = opts[:message]
15
- self.response_card = opts[:response_card]
10
+ session_state.dialog_action = dialog_action
16
11
  end
17
12
 
18
13
  def dialog_action
19
- {
20
- type: 'ConfirmIntent',
21
- intentName: intent_name,
22
- slots: slots,
23
- message: message,
24
- responseCard: response_card
25
- }.compact
14
+ Aws::Lex::Conversation::Type::DialogAction.shrink_wrap(
15
+ type: 'ConfirmIntent'
16
+ )
26
17
  end
27
18
  end
28
19
  end
@@ -5,22 +5,15 @@ module Aws
5
5
  class Conversation
6
6
  module Response
7
7
  class Delegate < Base
8
- attr_accessor :slots, :kendra_query_request_payload, :kendra_query_filter_string
9
-
10
8
  def initialize(opts = {})
11
9
  super
12
- self.slots = opts[:slots]
13
- self.kendra_query_request_payload = opts[:kendra_query_request_payload]
14
- self.kendra_query_filter_string = opts[:kendra_query_filter_string]
10
+ session_state.dialog_action = dialog_action
15
11
  end
16
12
 
17
13
  def dialog_action
18
- {
19
- type: 'Delegate',
20
- slots: slots,
21
- kendraQueryRequestPayload: kendra_query_request_payload,
22
- kendraQueryFilterString: kendra_query_filter_string
23
- }.compact
14
+ Aws::Lex::Conversation::Type::DialogAction.shrink_wrap(
15
+ type: 'Delegate'
16
+ )
24
17
  end
25
18
  end
26
19
  end
@@ -9,16 +9,13 @@ module Aws
9
9
 
10
10
  def initialize(opts = {})
11
11
  super
12
- self.message = opts[:message]
13
- self.response_card = opts[:response_card]
12
+ session_state.dialog_action = dialog_action
14
13
  end
15
14
 
16
15
  def dialog_action
17
- {
18
- type: 'ElicitIntent',
19
- message: message,
20
- responseCard: response_card
21
- }.compact
16
+ Aws::Lex::Conversation::Type::DialogAction.shrink_wrap(
17
+ type: 'ElicitIntent'
18
+ )
22
19
  end
23
20
  end
24
21
  end
@@ -5,26 +5,19 @@ module Aws
5
5
  class Conversation
6
6
  module Response
7
7
  class ElicitSlot < Base
8
- attr_accessor :intent_name, :message, :response_card, :slots, :slot_to_elicit
8
+ attr_accessor :slot_to_elicit
9
9
 
10
10
  def initialize(opts = {})
11
11
  super
12
- self.intent_name = opts.fetch(:intent_name)
13
12
  self.slot_to_elicit = opts.fetch(:slot_to_elicit)
14
- self.slots = opts.fetch(:slots)
15
- self.message = opts[:message]
16
- self.response_card = opts[:response_card]
13
+ session_state.dialog_action = dialog_action
17
14
  end
18
15
 
19
16
  def dialog_action
20
- {
17
+ Aws::Lex::Conversation::Type::DialogAction.shrink_wrap(
21
18
  type: 'ElicitSlot',
22
- intentName: intent_name,
23
- slots: slots,
24
- slotToElicit: slot_to_elicit,
25
- message: message,
26
- responseCard: response_card
27
- }.compact
19
+ slotToElicit: slot_to_elicit
20
+ )
28
21
  end
29
22
  end
30
23
  end
@@ -27,10 +27,12 @@ module Aws
27
27
  increment_slot_elicitations!
28
28
  conversation.elicit_slot(
29
29
  slot_to_elicit: name,
30
- message: {
31
- contentType: content_type,
32
- content: elicitation_content
33
- }
30
+ messages: [
31
+ {
32
+ contentType: content_type,
33
+ content: elicitation_content
34
+ }
35
+ ]
34
36
  )
35
37
  end
36
38