aws-lex-conversation 3.1.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -7,10 +7,9 @@ module Aws
|
|
7
7
|
class Response
|
8
8
|
include Base
|
9
9
|
|
10
|
-
required :
|
11
|
-
|
12
|
-
|
13
|
-
optional :active_contexts
|
10
|
+
required :session_state
|
11
|
+
required :messages
|
12
|
+
required :request_attributes
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
@@ -7,14 +7,13 @@ module Aws
|
|
7
7
|
class ResponseCard
|
8
8
|
include Base
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
required :title
|
11
|
+
required :buttons, default: -> { [] }
|
12
|
+
optional :sub_title
|
13
|
+
optional :image_url
|
13
14
|
|
14
15
|
coerce(
|
15
|
-
|
16
|
-
content_type: ResponseCard::ContentType,
|
17
|
-
generic_attachments: Array[GenericAttachment]
|
16
|
+
buttons: Array[ResponseCard::Button]
|
18
17
|
)
|
19
18
|
end
|
20
19
|
end
|
@@ -7,12 +7,12 @@ module Aws
|
|
7
7
|
class SentimentResponse
|
8
8
|
include Base
|
9
9
|
|
10
|
-
required :
|
10
|
+
required :sentiment
|
11
11
|
required :sentiment_score
|
12
12
|
|
13
13
|
coerce(
|
14
|
-
sentiment_label:
|
15
|
-
sentiment_score:
|
14
|
+
sentiment_label: Sentiment,
|
15
|
+
sentiment_score: SentimentScore
|
16
16
|
)
|
17
17
|
end
|
18
18
|
end
|
@@ -7,27 +7,17 @@ module Aws
|
|
7
7
|
class SentimentScore
|
8
8
|
include Base
|
9
9
|
|
10
|
-
required :
|
11
|
-
required :negative
|
12
|
-
required :neutral
|
13
|
-
required :
|
10
|
+
required :mixed
|
11
|
+
required :negative
|
12
|
+
required :neutral
|
13
|
+
required :positive
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
params = parts.each_with_object({}) do |part, hash|
|
23
|
-
label = part.first
|
24
|
-
value = part.last.to_f
|
25
|
-
hash[label] = value
|
26
|
-
end
|
27
|
-
|
28
|
-
shrink_wrap(params)
|
29
|
-
end
|
30
|
-
end
|
15
|
+
coerce(
|
16
|
+
mixed: float!(nilable: true),
|
17
|
+
negative: float!(nilable: true),
|
18
|
+
neutral: float!(nilable: true),
|
19
|
+
positive: float!(nilable: true)
|
20
|
+
)
|
31
21
|
end
|
32
22
|
end
|
33
23
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
module Lex
|
5
|
+
class Conversation
|
6
|
+
module Type
|
7
|
+
class SessionAttributes < Hash
|
8
|
+
include Base
|
9
|
+
|
10
|
+
optional :checkpoints
|
11
|
+
|
12
|
+
def checkpoints
|
13
|
+
@checkpoints ||= JSON.parse(
|
14
|
+
Base64.urlsafe_decode64(fetch(:checkpoints) { Base64.urlsafe_encode64([].to_json, padding: false) })
|
15
|
+
).map do |checkpoint|
|
16
|
+
Checkpoint.shrink_wrap(checkpoint)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_lex
|
21
|
+
merge(
|
22
|
+
checkpoints: Base64.urlsafe_encode64(checkpoints.map(&:to_lex).to_json, padding: false)
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
module Lex
|
5
|
+
class Conversation
|
6
|
+
module Type
|
7
|
+
class SessionState
|
8
|
+
include Base
|
9
|
+
|
10
|
+
optional :active_contexts, default: -> { [] }
|
11
|
+
optional :dialog_action
|
12
|
+
required :intent, default: -> { {} }
|
13
|
+
required :session_attributes, default: -> { {} }
|
14
|
+
|
15
|
+
coerce(
|
16
|
+
active_contexts: Array[Context],
|
17
|
+
dialog_action: DialogAction,
|
18
|
+
intent: Intent,
|
19
|
+
session_attributes: ->(v) { SessionAttributes[v.transform_keys(&:to_sym)] }
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -7,17 +7,57 @@ module Aws
|
|
7
7
|
class Slot
|
8
8
|
include Base
|
9
9
|
|
10
|
-
required :
|
11
|
-
|
12
|
-
required :value
|
13
|
-
|
10
|
+
required :shape, default: -> { 'Scalar' }
|
11
|
+
optional :name, virtual: true
|
12
|
+
required :lex_value, from: :value, default: -> { {} }, virtual: true
|
13
|
+
required :lex_values, from: :values, default: -> { [] }, virtual: true
|
14
|
+
required :active, default: -> { false }, virtual: true
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
coerce(
|
17
|
+
shape: SlotShape,
|
18
|
+
lex_value: SlotValue,
|
19
|
+
lex_values: Array[Slot]
|
20
|
+
)
|
18
21
|
|
19
22
|
def to_lex
|
20
|
-
|
23
|
+
super.merge(
|
24
|
+
value: transform_to_lex(lex_value),
|
25
|
+
values: transform_to_lex(lex_values)
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
def value=(val)
|
30
|
+
raise TypeError, 'use values= for List-type slots' if shape.list?
|
31
|
+
|
32
|
+
lex_value.interpreted_value = val
|
33
|
+
end
|
34
|
+
|
35
|
+
def value
|
36
|
+
raise TypeError, 'use values for List-type slots' if shape.list?
|
37
|
+
|
38
|
+
lex_value.interpreted_value
|
39
|
+
end
|
40
|
+
|
41
|
+
# takes an array of slot values
|
42
|
+
def values=(vals)
|
43
|
+
raise TypeError, 'use value= for Scalar-type slots' if shape.scalar?
|
44
|
+
|
45
|
+
self.lex_values = vals.map do |val|
|
46
|
+
Slot.shrink_wrap(
|
47
|
+
active: true,
|
48
|
+
value: {
|
49
|
+
interpretedValue: val,
|
50
|
+
originalValue: val,
|
51
|
+
resolvedValues: [val]
|
52
|
+
}
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def values
|
58
|
+
raise TypeError, 'use value for Scalar-type slots' if shape.scalar?
|
59
|
+
|
60
|
+
lex_values.map(&:value)
|
21
61
|
end
|
22
62
|
|
23
63
|
def active?
|
@@ -25,43 +65,28 @@ module Aws
|
|
25
65
|
end
|
26
66
|
|
27
67
|
def filled?
|
28
|
-
|
68
|
+
shape.list? ? values.any? : value != '' && !value.nil?
|
29
69
|
end
|
30
70
|
|
31
71
|
def blank?
|
32
72
|
!filled?
|
33
73
|
end
|
34
74
|
|
35
|
-
def value=(other)
|
36
|
-
@value = other
|
37
|
-
current_intent.raw_slots[name] = @value
|
38
|
-
end
|
39
|
-
|
40
75
|
def resolve!(index: 0)
|
41
|
-
|
42
|
-
end
|
76
|
+
return if shape.list?
|
43
77
|
|
44
|
-
|
45
|
-
details.resolutions.fetch(index) { SlotResolution.new(value: value) }.value
|
46
|
-
end
|
47
|
-
|
48
|
-
def original_value
|
49
|
-
details.original_value
|
78
|
+
lex_value.resolve!(index: index)
|
50
79
|
end
|
51
80
|
|
52
81
|
def resolvable?
|
53
|
-
|
82
|
+
return false if shape.list?
|
83
|
+
|
84
|
+
lex_value.resolvable?
|
54
85
|
end
|
55
86
|
|
56
87
|
def requestable?
|
57
88
|
active? && blank?
|
58
89
|
end
|
59
|
-
|
60
|
-
def details
|
61
|
-
@details ||= current_intent.slot_details.fetch(name.to_sym) do
|
62
|
-
SlotDetail.new(name: name, resolutions: [], original_value: value)
|
63
|
-
end
|
64
|
-
end
|
65
90
|
end
|
66
91
|
end
|
67
92
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
module Lex
|
5
|
+
class Conversation
|
6
|
+
module Type
|
7
|
+
class SlotValue
|
8
|
+
include Base
|
9
|
+
|
10
|
+
optional :original_value
|
11
|
+
optional :interpreted_value
|
12
|
+
required :resolved_values, default: -> { [] }
|
13
|
+
|
14
|
+
alias_method :value, :interpreted_value
|
15
|
+
alias_method :value=, :interpreted_value=
|
16
|
+
|
17
|
+
def to_lex
|
18
|
+
{
|
19
|
+
interpretedValue: interpreted_value,
|
20
|
+
originalValue: original_value,
|
21
|
+
resolvedValues: resolved_values
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def resolve!(index: 0)
|
26
|
+
self.interpreted_value = resolved(index: index)
|
27
|
+
end
|
28
|
+
|
29
|
+
def resolved(index: 0)
|
30
|
+
resolved_values.fetch(index) { interpreted_value }
|
31
|
+
end
|
32
|
+
|
33
|
+
def resolvable?
|
34
|
+
resolved_values.any?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
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:
|
4
|
+
version: 4.1.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-
|
15
|
+
date: 2021-07-21 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: shrink_wrap
|
@@ -74,30 +74,32 @@ files:
|
|
74
74
|
- lib/aws/lex/conversation/support/mixins/slot_elicitation.rb
|
75
75
|
- lib/aws/lex/conversation/type/base.rb
|
76
76
|
- lib/aws/lex/conversation/type/bot.rb
|
77
|
-
- lib/aws/lex/conversation/type/
|
77
|
+
- lib/aws/lex/conversation/type/checkpoint.rb
|
78
|
+
- lib/aws/lex/conversation/type/confirmation_state.rb
|
78
79
|
- lib/aws/lex/conversation/type/context.rb
|
80
|
+
- lib/aws/lex/conversation/type/dialog_action.rb
|
79
81
|
- lib/aws/lex/conversation/type/dialog_action_type.rb
|
80
82
|
- lib/aws/lex/conversation/type/enumeration.rb
|
81
83
|
- lib/aws/lex/conversation/type/event.rb
|
82
84
|
- lib/aws/lex/conversation/type/fulfillment_state.rb
|
85
|
+
- lib/aws/lex/conversation/type/input_mode.rb
|
83
86
|
- lib/aws/lex/conversation/type/intent.rb
|
84
87
|
- lib/aws/lex/conversation/type/intent_confidence.rb
|
88
|
+
- lib/aws/lex/conversation/type/interpretation.rb
|
85
89
|
- lib/aws/lex/conversation/type/invocation_source.rb
|
86
90
|
- lib/aws/lex/conversation/type/message.rb
|
87
91
|
- lib/aws/lex/conversation/type/message/content_type.rb
|
88
|
-
- lib/aws/lex/conversation/type/output_dialog_mode.rb
|
89
|
-
- lib/aws/lex/conversation/type/recent_intent_summary_view.rb
|
90
92
|
- lib/aws/lex/conversation/type/response.rb
|
91
93
|
- lib/aws/lex/conversation/type/response_card.rb
|
92
94
|
- lib/aws/lex/conversation/type/response_card/button.rb
|
93
|
-
- lib/aws/lex/conversation/type/
|
94
|
-
- lib/aws/lex/conversation/type/response_card/generic_attachment.rb
|
95
|
-
- lib/aws/lex/conversation/type/sentiment_label.rb
|
95
|
+
- lib/aws/lex/conversation/type/sentiment.rb
|
96
96
|
- lib/aws/lex/conversation/type/sentiment_response.rb
|
97
97
|
- lib/aws/lex/conversation/type/sentiment_score.rb
|
98
|
+
- lib/aws/lex/conversation/type/session_attributes.rb
|
99
|
+
- lib/aws/lex/conversation/type/session_state.rb
|
98
100
|
- lib/aws/lex/conversation/type/slot.rb
|
99
|
-
- lib/aws/lex/conversation/type/
|
100
|
-
- lib/aws/lex/conversation/type/
|
101
|
+
- lib/aws/lex/conversation/type/slot_shape.rb
|
102
|
+
- lib/aws/lex/conversation/type/slot_value.rb
|
101
103
|
- lib/aws/lex/conversation/type/time_to_live.rb
|
102
104
|
- lib/aws/lex/conversation/version.rb
|
103
105
|
homepage: https://github.com/amaabca/aws-lex-conversation
|
@@ -1,70 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Aws
|
4
|
-
module Lex
|
5
|
-
class Conversation
|
6
|
-
module Type
|
7
|
-
class RecentIntentSummaryView
|
8
|
-
include Base
|
9
|
-
|
10
|
-
required :intent_name
|
11
|
-
required :slots
|
12
|
-
required :confirmation_status
|
13
|
-
required :dialog_action_type
|
14
|
-
|
15
|
-
optional :checkpoint_label
|
16
|
-
optional :fulfillment_state
|
17
|
-
optional :slot_to_elicit
|
18
|
-
|
19
|
-
coerce(
|
20
|
-
slots: symbolize_hash!,
|
21
|
-
confirmation_status: ConfirmationStatus,
|
22
|
-
dialog_action_type: DialogActionType,
|
23
|
-
fulfillment_state: FulfillmentState
|
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
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|