aws-lex-conversation 2.1.0 → 4.0.1

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -0
  3. data/README.md +28 -6
  4. data/lib/aws/lex/conversation.rb +38 -1
  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 +25 -18
  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 +20 -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 +63 -20
  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 -11
  42. data/lib/aws/lex/conversation/type/recent_intent_summary_view.rb +0 -29
  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: 50a4b4cc2a28aa4251723f715953de0a102e7cabb0268db095e50470e49e2772
4
- data.tar.gz: a5bd7550ef4a7391c0d9221ac86b3c1760053b03dda9932d8416778f4ea319e5
3
+ metadata.gz: 476f05cfb93c1025db506486915dedc693c7ad4d89579841a6eb5400d96c29bd
4
+ data.tar.gz: db5be62a9dc9239d9fbdaaa93bef25ecd1fe7add316712d9c63e3cacd0b0b75b
5
5
  SHA512:
6
- metadata.gz: 48883e2e7ce637dc0b6a327bdf839b9e233a3a1bc06f99b318f5bdbf83e91c762fb8c2bbe1ffc597ac8a6900d7a01ee4dfab7a67a52c2f941595754e13f8cb06
7
- data.tar.gz: 3bf93255a75da95213ffc74a7a3a86785bba94ea70d758c53dbad1c351b3567f5bb6f23adffafbf67e7581ad9f4a9ece31a489ef35b9cd3ad31311121a209105
6
+ metadata.gz: 7d6b36def37b7daf757b05a769877ebc35186e0639c99847317457e8786d50d0def6e2b8d539bab73ad0d43c704d3325702f8331387bf5549361b70cf7ecf055
7
+ data.tar.gz: f6ac291760737662ea7452ad6ebc092f225aaefbccbcdc20f549c42b0aa1661267669b827bd82696a3d7d10c06c31e6deeaa4c9a2365cfc90739ab4dac3093f6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,41 @@
1
+ # 4.0.1 - July 16, 2021
2
+
3
+ * Fix a bug with the `Aws::Lex::Conversation::Handler::Echo` class because it
4
+ didn't correctly return an array of messages required for Lex V2.
5
+ * Drop a call to `Hash#deep_symbolize_keys` so we don't implicitly rely on
6
+ ActiveSupport.
7
+ * Call `Hash#compact` when transforming a Lex response so we don't include any
8
+ `nil` values in the response.
9
+
10
+ # 4.0.0 - July 14, 2021
11
+
12
+ **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`.
13
+ **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).
14
+
15
+ # 3.1.0 - June 1, 2021
16
+
17
+ * Default both `request_attributes` and `session_attributes`
18
+ to an empty Hash when the values from the event are `null`.
19
+ It is much easier to reason and write logic when you can
20
+ assume that these values are always at least a hash.
21
+
22
+ # 3.0.0 - May 20, 2021
23
+
24
+ * **breaking change** - Don't pass the `recentIntentSummaryView` back
25
+ in the Lex response unless we have modified or added an existing
26
+ checkpoint. Lex will persist the previous intent summary/history
27
+ if we do not send a `recentIntentSummaryView` value back in the
28
+ response (see [1]).
29
+ * Add a few helper methods to the `Aws::Lex::Conversation::Type::Slot`
30
+ instances:
31
+
32
+ - `active?`: returns true if the slot is defined (either optional or
33
+ required) for the current intent.
34
+ - `requestable?`: returns true if the slot is active for the current
35
+ intent and it is not filled.
36
+
37
+ [1]: https://docs.aws.amazon.com/lex/latest/dg/lambda-input-response-format.html#lambda-response-recentIntentSummaryView
38
+
1
39
  # 2.0.0 - August 19, 2020
2
40
 
3
41
  * **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,7 +55,44 @@ module Aws
55
55
  end
56
56
 
57
57
  def session
58
- lex.session_attributes
58
+ lex.session_state.session_attributes
59
+ end
60
+
61
+ def checkpoint!(opts = {})
62
+ label = opts.fetch(:label)
63
+ params = {
64
+ label: label,
65
+ dialog_action_type: opts.fetch(:dialog_action_type),
66
+ fulfillment_state: opts[:fulfillment_state],
67
+ intent: lex.current_intent,
68
+ slot_to_elicit: opts[:slot_to_elicit]
69
+ }.compact
70
+
71
+ if checkpoint?(label: label)
72
+ # update the existing checkpoint
73
+ checkpoint(label: label).assign_attributes!(params)
74
+ else
75
+ # push a new checkpoint to the recent_intent_summary_view
76
+ checkpoints.unshift(
77
+ Type::Checkpoint.new(params)
78
+ )
79
+ end
80
+ end
81
+
82
+ def checkpoint?(label:)
83
+ !checkpoint(label: label).nil?
84
+ end
85
+
86
+ def checkpoint(label:)
87
+ checkpoints.find { |v| v.label == label }
88
+ end
89
+
90
+ def checkpoints
91
+ lex.session_state.session_attributes.checkpoints
92
+ end
93
+
94
+ def stash
95
+ @stash ||= {}
59
96
  end
60
97
  end
61
98
  end
@@ -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
 
@@ -8,51 +8,45 @@ module Aws
8
8
  module Responses
9
9
  def close(opts = {})
10
10
  params = {
11
- active_contexts: lex.active_contexts,
12
- recent_intent_summary_view: lex.recent_intent_summary_view,
13
- session_attributes: lex.session_attributes
11
+ session_state: lex.session_state,
12
+ request_attributes: lex.request_attributes
14
13
  }.merge(opts)
15
14
  Response::Close.new(params).to_lex
16
15
  end
17
16
 
18
17
  def confirm_intent(opts = {})
19
18
  params = {
20
- active_contexts: lex.active_contexts,
21
- intent_name: lex.current_intent.name,
22
- recent_intent_summary_view: lex.recent_intent_summary_view,
23
- session_attributes: lex.session_attributes,
24
- slots: lex.current_intent.slots
19
+ session_state: lex.session_state,
20
+ request_attributes: lex.request_attributes,
21
+ intent: lex.current_intent
25
22
  }.merge(opts)
23
+ lex.session_state.intent = params.fetch(:intent)
26
24
  Response::ConfirmIntent.new(params).to_lex
27
25
  end
28
26
 
29
27
  def delegate(opts = {})
30
28
  params = {
31
- active_contexts: lex.active_contexts,
32
- recent_intent_summary_view: lex.recent_intent_summary_view,
33
- session_attributes: lex.session_attributes,
34
- slots: lex.current_intent.slots
29
+ session_state: lex.session_state,
30
+ request_attributes: lex.request_attributes
35
31
  }.merge(opts)
36
32
  Response::Delegate.new(params).to_lex
37
33
  end
38
34
 
39
35
  def elicit_intent(opts = {})
40
36
  params = {
41
- active_contexts: lex.active_contexts,
42
- recent_intent_summary_view: lex.recent_intent_summary_view,
43
- session_attributes: lex.session_attributes
37
+ session_state: lex.session_state,
38
+ request_attributes: lex.request_attributes
44
39
  }.merge(opts)
45
40
  Response::ElicitIntent.new(params).to_lex
46
41
  end
47
42
 
48
43
  def elicit_slot(opts = {})
49
44
  params = {
50
- active_contexts: lex.active_contexts,
51
- intent_name: lex.current_intent.name,
52
- recent_intent_summary_view: lex.recent_intent_summary_view,
53
- session_attributes: lex.session_attributes,
54
- slots: lex.current_intent.slots
45
+ session_state: lex.session_state,
46
+ request_attributes: lex.request_attributes,
47
+ intent: lex.current_intent
55
48
  }.merge(opts)
49
+ lex.session_state.intent = params.fetch(:intent)
56
50
  Response::ElicitSlot.new(params).to_lex
57
51
  end
58
52
  end