aws-lex-conversation 3.1.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +28 -6
  3. data/lib/aws/lex/conversation.rb +8 -20
  4. data/lib/aws/lex/conversation/base.rb +13 -10
  5. data/lib/aws/lex/conversation/handler/delegate.rb +1 -3
  6. data/lib/aws/lex/conversation/response/base.rb +11 -10
  7. data/lib/aws/lex/conversation/response/close.rb +5 -11
  8. data/lib/aws/lex/conversation/response/confirm_intent.rb +4 -13
  9. data/lib/aws/lex/conversation/response/delegate.rb +4 -11
  10. data/lib/aws/lex/conversation/response/elicit_intent.rb +4 -7
  11. data/lib/aws/lex/conversation/response/elicit_slot.rb +5 -12
  12. data/lib/aws/lex/conversation/slot/elicitation.rb +6 -4
  13. data/lib/aws/lex/conversation/support/mixins/responses.rb +14 -20
  14. data/lib/aws/lex/conversation/type/base.rb +8 -4
  15. data/lib/aws/lex/conversation/type/bot.rb +3 -1
  16. data/lib/aws/lex/conversation/type/checkpoint.rb +57 -0
  17. data/lib/aws/lex/conversation/type/{confirmation_status.rb → confirmation_state.rb} +1 -1
  18. data/lib/aws/lex/conversation/type/context.rb +4 -4
  19. data/lib/aws/lex/conversation/type/{slot_detail.rb → dialog_action.rb} +4 -4
  20. data/lib/aws/lex/conversation/type/dialog_action_type.rb +3 -3
  21. data/lib/aws/lex/conversation/type/event.rb +24 -17
  22. data/lib/aws/lex/conversation/type/{output_dialog_mode.rb → input_mode.rb} +3 -2
  23. data/lib/aws/lex/conversation/type/intent.rb +14 -23
  24. data/lib/aws/lex/conversation/type/intent_confidence.rb +5 -5
  25. data/lib/aws/lex/conversation/type/interpretation.rb +23 -0
  26. data/lib/aws/lex/conversation/type/message.rb +4 -2
  27. data/lib/aws/lex/conversation/type/message/content_type.rb +2 -1
  28. data/lib/aws/lex/conversation/type/response.rb +3 -4
  29. data/lib/aws/lex/conversation/type/response_card.rb +5 -6
  30. data/lib/aws/lex/conversation/type/{sentiment_label.rb → sentiment.rb} +1 -1
  31. data/lib/aws/lex/conversation/type/sentiment_response.rb +3 -3
  32. data/lib/aws/lex/conversation/type/sentiment_score.rb +10 -20
  33. data/lib/aws/lex/conversation/type/session_attributes.rb +31 -0
  34. data/lib/aws/lex/conversation/type/session_state.rb +25 -0
  35. data/lib/aws/lex/conversation/type/slot.rb +54 -29
  36. data/lib/aws/lex/conversation/type/{slot_resolution.rb → slot_shape.rb} +4 -3
  37. data/lib/aws/lex/conversation/type/slot_value.rb +32 -0
  38. data/lib/aws/lex/conversation/version.rb +1 -1
  39. metadata +12 -10
  40. data/lib/aws/lex/conversation/type/recent_intent_summary_view.rb +0 -70
  41. data/lib/aws/lex/conversation/type/response_card/content_type.rb +0 -17
  42. data/lib/aws/lex/conversation/type/response_card/generic_attachment.rb +0 -26
@@ -7,12 +7,12 @@ module Aws
7
7
  class SentimentResponse
8
8
  include Base
9
9
 
10
- required :sentiment_label
10
+ required :sentiment
11
11
  required :sentiment_score
12
12
 
13
13
  coerce(
14
- sentiment_label: SentimentLabel,
15
- sentiment_score: ->(v) { SentimentScore.parse_string(v) }
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 :positive, from: :Positive
11
- required :negative, from: :Negative
12
- required :neutral, from: :Neutral
13
- required :mixed, from: :Mixed
10
+ required :mixed
11
+ required :negative
12
+ required :neutral
13
+ required :positive
14
14
 
15
- class << self
16
- def parse_string(str)
17
- parts = str
18
- .gsub(/[{}]/, '') # remove '{' or '}' chars
19
- .split(',') # break into components
20
- .map { |c| c.gsub(/\s/, '').split(':') }
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,31 @@
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 ||= begin # rubocop:disable Style/RedundantBegin
14
+ JSON.parse(
15
+ Base64.urlsafe_decode64(fetch(:checkpoints) { Base64.urlsafe_encode64([].to_json, padding: false) })
16
+ ).map do |checkpoint|
17
+ Checkpoint.shrink_wrap(checkpoint)
18
+ end
19
+ end
20
+ end
21
+
22
+ def to_lex
23
+ merge(
24
+ checkpoints: Base64.urlsafe_encode64(checkpoints.map(&:to_lex).to_json, padding: false)
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ 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.deep_symbolize_keys] }
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 :current_intent, from: :current_intent, virtual: true
11
- required :name
12
- required :value
13
- optional :active, virtual: true
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
- def as_json(_opts = {})
16
- to_lex
17
- end
16
+ coerce(
17
+ shape: SlotShape,
18
+ lex_value: SlotValue,
19
+ lex_values: Array[Slot]
20
+ )
18
21
 
19
22
  def to_lex
20
- value
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
- value.to_s != ''
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
- self.value = resolved(index: index)
42
- end
76
+ return if shape.list?
43
77
 
44
- def resolved(index: 0)
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
- details.resolutions.any?
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
@@ -4,10 +4,11 @@ module Aws
4
4
  module Lex
5
5
  class Conversation
6
6
  module Type
7
- class SlotResolution
8
- include Base
7
+ class SlotShape
8
+ include Enumeration
9
9
 
10
- required :value
10
+ enumeration('List')
11
+ enumeration('Scalar')
11
12
  end
12
13
  end
13
14
  end
@@ -0,0 +1,32 @@
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 resolve!(index: 0)
18
+ self.interpreted_value = resolved(index: index)
19
+ end
20
+
21
+ def resolved(index: 0)
22
+ resolved_values.fetch(index) { interpreted_value }
23
+ end
24
+
25
+ def resolvable?
26
+ resolved_values.any?
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -3,7 +3,7 @@
3
3
  module Aws
4
4
  module Lex
5
5
  class Conversation
6
- VERSION = '3.1.0'
6
+ VERSION = '4.0.0'
7
7
  end
8
8
  end
9
9
  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: 3.1.0
4
+ version: 4.0.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-06-01 00:00:00.000000000 Z
15
+ date: 2021-07-14 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/confirmation_status.rb
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/response_card/content_type.rb
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/slot_detail.rb
100
- - lib/aws/lex/conversation/type/slot_resolution.rb
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
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Aws
4
- module Lex
5
- class Conversation
6
- module Type
7
- class ResponseCard
8
- class ContentType
9
- include Enumeration
10
-
11
- enumeration('application/vnd.amazonaws.card.generic')
12
- end
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Aws
4
- module Lex
5
- class Conversation
6
- module Type
7
- class ResponseCard
8
- class GenericAttachment
9
- include Base
10
-
11
- required :title
12
- required :buttons
13
-
14
- optional :sub_title
15
- optional :image_url
16
- optional :attachment_link_url
17
-
18
- coerce(
19
- buttons: Array[Button]
20
- )
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end