aws-lex-conversation 0.5.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.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ci.yml +35 -0
  3. data/.gitignore +15 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +29 -0
  6. data/.simplecov +5 -0
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/Gemfile +12 -0
  9. data/LICENSE.md +21 -0
  10. data/README.md +160 -0
  11. data/Rakefile +11 -0
  12. data/aws-lex-conversation.gemspec +38 -0
  13. data/bin/console +15 -0
  14. data/bin/setup +8 -0
  15. data/lib/aws-lex-conversation.rb +3 -0
  16. data/lib/aws/lex/conversation.rb +58 -0
  17. data/lib/aws/lex/conversation/base.rb +40 -0
  18. data/lib/aws/lex/conversation/handler/base.rb +34 -0
  19. data/lib/aws/lex/conversation/handler/delegate.rb +17 -0
  20. data/lib/aws/lex/conversation/handler/echo.rb +24 -0
  21. data/lib/aws/lex/conversation/response/base.rb +30 -0
  22. data/lib/aws/lex/conversation/response/close.rb +29 -0
  23. data/lib/aws/lex/conversation/response/confirm_intent.rb +31 -0
  24. data/lib/aws/lex/conversation/response/delegate.rb +29 -0
  25. data/lib/aws/lex/conversation/response/elicit_intent.rb +27 -0
  26. data/lib/aws/lex/conversation/response/elicit_slot.rb +33 -0
  27. data/lib/aws/lex/conversation/support/inflector.rb +43 -0
  28. data/lib/aws/lex/conversation/support/responses.rb +56 -0
  29. data/lib/aws/lex/conversation/type/base.rb +95 -0
  30. data/lib/aws/lex/conversation/type/bot.rb +17 -0
  31. data/lib/aws/lex/conversation/type/confirmation_status.rb +17 -0
  32. data/lib/aws/lex/conversation/type/current_intent.rb +34 -0
  33. data/lib/aws/lex/conversation/type/dialog_action_type.rb +19 -0
  34. data/lib/aws/lex/conversation/type/enumeration.rb +44 -0
  35. data/lib/aws/lex/conversation/type/event.rb +37 -0
  36. data/lib/aws/lex/conversation/type/fulfillment_state.rb +16 -0
  37. data/lib/aws/lex/conversation/type/invocation_source.rb +16 -0
  38. data/lib/aws/lex/conversation/type/message.rb +20 -0
  39. data/lib/aws/lex/conversation/type/message/content_type.rb +19 -0
  40. data/lib/aws/lex/conversation/type/output_dialog_mode.rb +16 -0
  41. data/lib/aws/lex/conversation/type/recent_intent_summary_view.rb +29 -0
  42. data/lib/aws/lex/conversation/type/response.rb +17 -0
  43. data/lib/aws/lex/conversation/type/response_card.rb +23 -0
  44. data/lib/aws/lex/conversation/type/response_card/button.rb +18 -0
  45. data/lib/aws/lex/conversation/type/response_card/content_type.rb +17 -0
  46. data/lib/aws/lex/conversation/type/response_card/generic_attachment.rb +26 -0
  47. data/lib/aws/lex/conversation/type/sentiment_label.rb +18 -0
  48. data/lib/aws/lex/conversation/type/sentiment_response.rb +21 -0
  49. data/lib/aws/lex/conversation/type/sentiment_score.rb +35 -0
  50. data/lib/aws/lex/conversation/type/slot_detail.rb +20 -0
  51. data/lib/aws/lex/conversation/type/slot_resolution.rb +15 -0
  52. data/lib/aws/lex/conversation/version.rb +9 -0
  53. metadata +117 -0
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Lex
5
+ class Conversation
6
+ module Type
7
+ module Base
8
+ def self.included(base)
9
+ base.include(Shrink::Wrap)
10
+ base.include(InstanceMethods)
11
+ base.extend(ClassMethods)
12
+ base.transform(Shrink::Wrap::Transformer::Symbolize)
13
+ base.class_eval do
14
+ def initialize(opts = {})
15
+ assign_attributes!(opts)
16
+ end
17
+ end
18
+ end
19
+
20
+ module InstanceMethods
21
+ def assign_attributes!(opts = {})
22
+ self.class.attributes.each do |attribute|
23
+ instance_variable_set("@#{attribute}", opts[attribute])
24
+ end
25
+ end
26
+
27
+ def to_lex
28
+ self.class.attributes.each_with_object({}) do |attribute, hash|
29
+ value = transform_to_lex(instance_variable_get("@#{attribute}"))
30
+ hash[self.class.mapping.fetch(attribute)] = value
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def transform_to_lex(value)
37
+ case value
38
+ when Hash
39
+ value.each_with_object({}) do |(key, val), hash|
40
+ hash[key.to_sym] = transform_to_lex(val)
41
+ end
42
+ when Array
43
+ value.map { |v| transform_to_lex(v) }
44
+ else
45
+ if value.respond_to?(:to_lex)
46
+ value.to_lex
47
+ else
48
+ value
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ module ClassMethods
55
+ def integer!
56
+ ->(v) { v.to_i }
57
+ end
58
+
59
+ def symbolize_hash!
60
+ ->(v) { v.transform_keys(&:to_sym) }
61
+ end
62
+
63
+ def required(attribute, opts = {})
64
+ property(attribute, opts.merge(allow_nil: false))
65
+ end
66
+
67
+ def optional(attribute, opts = {})
68
+ property(attribute, opts.merge(allow_nil: true))
69
+ end
70
+
71
+ def property(attribute, opts = {})
72
+ from = opts.fetch(:from) do
73
+ Support::Inflector.new(attribute).to_camel_case.to_sym
74
+ end
75
+ params = { from: from }.merge(opts)
76
+
77
+ attr_accessor(attribute)
78
+
79
+ mapping[attribute] = from
80
+ translate(attribute => params)
81
+ end
82
+
83
+ def attributes
84
+ @attributes ||= mapping.keys
85
+ end
86
+
87
+ def mapping
88
+ @mapping ||= {}
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Lex
5
+ class Conversation
6
+ module Type
7
+ class Bot
8
+ include Base
9
+
10
+ required :name
11
+ required :alias
12
+ required :version
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Lex
5
+ class Conversation
6
+ module Type
7
+ class ConfirmationStatus
8
+ include Enumeration
9
+
10
+ enumeration('None')
11
+ enumeration('Confirmed')
12
+ enumeration('Denied')
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Lex
5
+ class Conversation
6
+ module Type
7
+ class CurrentIntent
8
+ include Base
9
+
10
+ required :name
11
+ required :slots
12
+ required :slot_details
13
+ required :confirmation_status
14
+
15
+ class << self
16
+ def slot_details!
17
+ ->(v) do
18
+ v.each_with_object({}) do |(key, value), hash|
19
+ hash[key.to_sym] = SlotDetail.shrink_wrap(value)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ coerce(
26
+ slots: symbolize_hash!,
27
+ slot_details: slot_details!,
28
+ confirmation_status: ConfirmationStatus
29
+ )
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Lex
5
+ class Conversation
6
+ module Type
7
+ class DialogActionType
8
+ include Enumeration
9
+
10
+ enumeration('ElicitIntent')
11
+ enumeration('ElicitSlot')
12
+ enumeration('ConfirmIntent')
13
+ enumeration('Delegate')
14
+ enumeration('Close')
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Lex
5
+ class Conversation
6
+ module Type
7
+ module Enumeration
8
+ def self.included(base)
9
+ base.extend(ClassMethods)
10
+ base.include(InstanceMethods)
11
+ base.attr_accessor(:raw)
12
+ base.class_eval do
13
+ def initialize(raw)
14
+ self.raw = raw
15
+ end
16
+ end
17
+ end
18
+
19
+ module InstanceMethods
20
+ def to_lex
21
+ raw # maintain original casing
22
+ end
23
+ end
24
+
25
+ module ClassMethods
26
+ def enumeration(value)
27
+ enumerations << value
28
+ snake_case = Support::Inflector.new(value).to_snake_case
29
+ class_eval(
30
+ "def #{snake_case}?; raw.casecmp('#{value}').zero?; end",
31
+ __FILE__,
32
+ __LINE__ - 2
33
+ )
34
+ end
35
+
36
+ def enumerations
37
+ @enumerations ||= []
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Lex
5
+ class Conversation
6
+ module Type
7
+ class Event
8
+ include Base
9
+
10
+ required :current_intent
11
+ required :bot
12
+ required :user_id
13
+ required :input_transcript
14
+ required :invocation_source
15
+ required :output_dialog_mode
16
+ required :message_version
17
+ required :session_attributes
18
+ required :recent_intent_summary_view
19
+ optional :request_attributes
20
+ optional :sentiment_response
21
+ optional :kendra_response
22
+
23
+ coerce(
24
+ current_intent: CurrentIntent,
25
+ bot: Bot,
26
+ invocation_source: InvocationSource,
27
+ output_dialog_mode: OutputDialogMode,
28
+ session_attributes: symbolize_hash!,
29
+ request_attributes: symbolize_hash!,
30
+ recent_intent_summary_view: Array[RecentIntentSummaryView],
31
+ sentiment_response: SentimentResponse
32
+ )
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Lex
5
+ class Conversation
6
+ module Type
7
+ class FulfillmentState
8
+ include Enumeration
9
+
10
+ enumeration('Fulfilled')
11
+ enumeration('Failed')
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Lex
5
+ class Conversation
6
+ module Type
7
+ class InvocationSource
8
+ include Enumeration
9
+
10
+ enumeration('DialogCodeHook')
11
+ enumeration('FulfillmentCodeHook')
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Lex
5
+ class Conversation
6
+ module Type
7
+ class Message
8
+ include Base
9
+
10
+ optional :content_type, default: 'PlainText'
11
+ required :content
12
+
13
+ coerce(
14
+ content_type: Message::ContentType
15
+ )
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Lex
5
+ class Conversation
6
+ module Type
7
+ class Message
8
+ class ContentType
9
+ include Enumeration
10
+
11
+ enumeration('PlainText')
12
+ enumeration('SSML')
13
+ enumeration('CustomPayload')
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Lex
5
+ class Conversation
6
+ module Type
7
+ class OutputDialogMode
8
+ include Enumeration
9
+
10
+ enumeration('Voice')
11
+ enumeration('Text')
12
+ end
13
+ end
14
+ end
15
+ end
16
+ 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 RecentIntentSummaryView
8
+ include Base
9
+
10
+ required :intent_name
11
+ required :slots
12
+ required :confirmation_status
13
+ required :dialog_action_type
14
+ required :slot_to_elicit
15
+
16
+ optional :fulfillment_state
17
+ optional :checkpoint_label
18
+
19
+ coerce(
20
+ slots: symbolize_hash!,
21
+ confirmation_status: ConfirmationStatus,
22
+ dialog_action_type: DialogActionType,
23
+ fulfillment_state: FulfillmentState
24
+ )
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Lex
5
+ class Conversation
6
+ module Type
7
+ class Response
8
+ include Base
9
+
10
+ required :dialog_action
11
+ optional :session_attributes
12
+ optional :recent_intent_summary_view
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Lex
5
+ class Conversation
6
+ module Type
7
+ class ResponseCard
8
+ include Base
9
+
10
+ optional :version
11
+ optional :content_type, default: 'application/vnd.amazonaws.card.generic'
12
+ required :generic_attachments
13
+
14
+ coerce(
15
+ version: integer!,
16
+ content_type: ResponseCard::ContentType,
17
+ generic_attachments: Array[GenericAttachment]
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Lex
5
+ class Conversation
6
+ module Type
7
+ class ResponseCard
8
+ class Button
9
+ include Base
10
+
11
+ required :text
12
+ required :value
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end