aws-lex-conversation 3.1.0 → 4.1.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 +4 -4
- data/CHANGELOG.md +44 -0
- data/README.md +28 -6
- data/lib/aws/lex/conversation.rb +8 -20
- data/lib/aws/lex/conversation/base.rb +13 -10
- data/lib/aws/lex/conversation/handler/delegate.rb +1 -3
- data/lib/aws/lex/conversation/handler/echo.rb +6 -4
- data/lib/aws/lex/conversation/response/base.rb +11 -10
- data/lib/aws/lex/conversation/response/close.rb +5 -11
- data/lib/aws/lex/conversation/response/confirm_intent.rb +4 -13
- data/lib/aws/lex/conversation/response/delegate.rb +4 -11
- data/lib/aws/lex/conversation/response/elicit_intent.rb +6 -7
- data/lib/aws/lex/conversation/response/elicit_slot.rb +5 -12
- data/lib/aws/lex/conversation/slot/elicitation.rb +6 -4
- data/lib/aws/lex/conversation/support/mixins/responses.rb +14 -20
- data/lib/aws/lex/conversation/type/base.rb +10 -4
- data/lib/aws/lex/conversation/type/bot.rb +3 -1
- data/lib/aws/lex/conversation/type/checkpoint.rb +57 -0
- data/lib/aws/lex/conversation/type/{confirmation_status.rb → confirmation_state.rb} +1 -1
- data/lib/aws/lex/conversation/type/context.rb +4 -4
- data/lib/aws/lex/conversation/type/{slot_detail.rb → dialog_action.rb} +4 -4
- data/lib/aws/lex/conversation/type/dialog_action_type.rb +3 -3
- data/lib/aws/lex/conversation/type/event.rb +25 -18
- data/lib/aws/lex/conversation/type/fulfillment_state.rb +2 -0
- data/lib/aws/lex/conversation/type/{output_dialog_mode.rb → input_mode.rb} +3 -2
- data/lib/aws/lex/conversation/type/intent.rb +14 -23
- data/lib/aws/lex/conversation/type/intent_confidence.rb +5 -5
- data/lib/aws/lex/conversation/type/interpretation.rb +23 -0
- data/lib/aws/lex/conversation/type/message.rb +4 -2
- data/lib/aws/lex/conversation/type/message/content_type.rb +2 -1
- data/lib/aws/lex/conversation/type/response.rb +3 -4
- data/lib/aws/lex/conversation/type/response_card.rb +5 -6
- data/lib/aws/lex/conversation/type/{sentiment_label.rb → sentiment.rb} +1 -1
- data/lib/aws/lex/conversation/type/sentiment_response.rb +3 -3
- data/lib/aws/lex/conversation/type/sentiment_score.rb +10 -20
- data/lib/aws/lex/conversation/type/session_attributes.rb +29 -0
- data/lib/aws/lex/conversation/type/session_state.rb +25 -0
- data/lib/aws/lex/conversation/type/slot.rb +54 -29
- data/lib/aws/lex/conversation/type/{slot_resolution.rb → slot_shape.rb} +4 -3
- data/lib/aws/lex/conversation/type/slot_value.rb +40 -0
- data/lib/aws/lex/conversation/version.rb +1 -1
- metadata +12 -10
- data/lib/aws/lex/conversation/type/recent_intent_summary_view.rb +0 -70
- data/lib/aws/lex/conversation/type/response_card/content_type.rb +0 -17
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9735c51e883e99b06c28d4c979b52eb5f5bffe95dcb5bb1eebb138b16ef3aa21
|
4
|
+
data.tar.gz: 2cbfd1b527fb7058a7b496d9099edd78087eb69b928ebbc073c9d81bbdf35d80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 263f7eafd97d6c58cd93dcafd8652686e3a6a9909906d6c3bb65ac6e165cf4f94670e3f2f2dc38838758e19e85cfb0ed3806eff5b7521a6184bdbccf296aaeda
|
7
|
+
data.tar.gz: 1b9096daf68a211f23c678da9a36fe4e92aa4cacd5c362f79020698870dfcacc2ace8d152b2260dc9f5390e8e4195a07b34c15cf76e4df56e3619e6c50043feb
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,47 @@
|
|
1
|
+
# 4.1.0 - July 21, 2021
|
2
|
+
|
3
|
+
* Don't set the `intent` property in the response for `ElicitIntent`
|
4
|
+
actions as the field is optional as per [AWS documentation](https://docs.aws.amazon.com/lexv2/latest/dg/lambda.html#lambda-response-format).
|
5
|
+
* Add `InProgress` and `ReadyForFulfillment` enumerations to `FulfillmentState`.
|
6
|
+
|
7
|
+
# 4.0.1 - July 16, 2021
|
8
|
+
|
9
|
+
* Fix a bug with the `Aws::Lex::Conversation::Handler::Echo` class because it
|
10
|
+
didn't correctly return an array of messages required for Lex V2.
|
11
|
+
* Drop a call to `Hash#deep_symbolize_keys` so we don't implicitly rely on
|
12
|
+
ActiveSupport.
|
13
|
+
* Call `Hash#compact` when transforming a Lex response so we don't include any
|
14
|
+
`nil` values in the response.
|
15
|
+
|
16
|
+
# 4.0.0 - July 14, 2021
|
17
|
+
|
18
|
+
**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`.
|
19
|
+
**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).
|
20
|
+
|
21
|
+
# 3.1.0 - June 1, 2021
|
22
|
+
|
23
|
+
* Default both `request_attributes` and `session_attributes`
|
24
|
+
to an empty Hash when the values from the event are `null`.
|
25
|
+
It is much easier to reason and write logic when you can
|
26
|
+
assume that these values are always at least a hash.
|
27
|
+
|
28
|
+
# 3.0.0 - May 20, 2021
|
29
|
+
|
30
|
+
* **breaking change** - Don't pass the `recentIntentSummaryView` back
|
31
|
+
in the Lex response unless we have modified or added an existing
|
32
|
+
checkpoint. Lex will persist the previous intent summary/history
|
33
|
+
if we do not send a `recentIntentSummaryView` value back in the
|
34
|
+
response (see [1]).
|
35
|
+
* Add a few helper methods to the `Aws::Lex::Conversation::Type::Slot`
|
36
|
+
instances:
|
37
|
+
|
38
|
+
- `active?`: returns true if the slot is defined (either optional or
|
39
|
+
required) for the current intent.
|
40
|
+
- `requestable?`: returns true if the slot is active for the current
|
41
|
+
intent and it is not filled.
|
42
|
+
|
43
|
+
[1]: https://docs.aws.amazon.com/lex/latest/dg/lambda-input-response-format.html#lambda-response-recentIntentSummaryView
|
44
|
+
|
1
45
|
# 2.0.0 - August 19, 2020
|
2
46
|
|
3
47
|
* **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
|
-
#
|
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
|
-
|
82
|
-
|
83
|
-
|
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
|
data/lib/aws/lex/conversation.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
84
|
-
Type::
|
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
83
|
!checkpoint(label: label).nil?
|
92
84
|
end
|
93
85
|
|
94
86
|
def checkpoint(label:)
|
95
|
-
|
87
|
+
checkpoints.find { |v| v.label == label }
|
96
88
|
end
|
97
89
|
|
98
|
-
|
99
|
-
|
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/
|
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/
|
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/
|
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/
|
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'
|
@@ -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
|
-
|
15
|
-
|
16
|
-
|
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
|
-
:
|
10
|
-
:
|
11
|
-
:
|
9
|
+
:session_state,
|
10
|
+
:messages,
|
11
|
+
:request_attributes,
|
12
|
+
:fulfillment_state
|
12
13
|
)
|
13
14
|
|
14
15
|
def initialize(opts = {})
|
15
|
-
self.
|
16
|
-
self.
|
17
|
-
self.
|
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
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
13
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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,15 @@ module Aws
|
|
9
9
|
|
10
10
|
def initialize(opts = {})
|
11
11
|
super
|
12
|
-
|
13
|
-
|
12
|
+
session_state.dialog_action = dialog_action
|
13
|
+
# by default, we set intent as nil unless overridden
|
14
|
+
session_state.intent = opts[:intent]
|
14
15
|
end
|
15
16
|
|
16
17
|
def dialog_action
|
17
|
-
|
18
|
-
type: 'ElicitIntent'
|
19
|
-
|
20
|
-
responseCard: response_card
|
21
|
-
}.compact
|
18
|
+
Aws::Lex::Conversation::Type::DialogAction.shrink_wrap(
|
19
|
+
type: 'ElicitIntent'
|
20
|
+
)
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
@@ -5,26 +5,19 @@ module Aws
|
|
5
5
|
class Conversation
|
6
6
|
module Response
|
7
7
|
class ElicitSlot < Base
|
8
|
-
attr_accessor :
|
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
|
-
|
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
|
-
|
23
|
-
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
messages: [
|
31
|
+
{
|
32
|
+
contentType: content_type,
|
33
|
+
content: elicitation_content
|
34
|
+
}
|
35
|
+
]
|
34
36
|
)
|
35
37
|
end
|
36
38
|
|