aws-lex-conversation 3.1.0 → 4.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 +4 -4
- 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/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 +4 -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 +8 -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 +24 -17
- 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 +31 -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 +32 -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: f57f415463cb7d78d0ddb4f48232b1c0038bc91e4813fb9d6de6455fa7f0a4d9
|
4
|
+
data.tar.gz: 7ba9cdf27e3f2368862bc7584eb1ce555a24a253d2a1ce3dd4c1d8500264fd0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 168eb69456d693dbf0f2618a23e4ec13fef7daca4921871b2d0b5a532ef39f4a1fdceb435b3122518aee7e4ae9495546b85f58e4d95bceab255fb2b91f8fcfc6
|
7
|
+
data.tar.gz: 2d9577a331c617a681c3f961daaa1d1825812c907f6d40ebe838db4ce471b37ea948d9f0b75985430795d449ffcf4a59968180a591f9cfbc66a8f115864d75eb
|
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'
|
@@ -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,13 @@ module Aws
|
|
9
9
|
|
10
10
|
def initialize(opts = {})
|
11
11
|
super
|
12
|
-
|
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
|
-
|
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 :
|
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
|
|
@@ -8,51 +8,45 @@ module Aws
|
|
8
8
|
module Responses
|
9
9
|
def close(opts = {})
|
10
10
|
params = {
|
11
|
-
|
12
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
32
|
-
|
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
|
-
|
42
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
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
|