Class: Aws::Lex::Conversation
- Inherits:
-
Object
- Object
- Aws::Lex::Conversation
show all
- Includes:
- Support::Mixins::Responses
- Defined in:
- lib/aws/lex/conversation.rb,
lib/aws/lex/conversation/spec.rb,
lib/aws/lex/conversation/version.rb,
lib/aws/lex/conversation/type/bot.rb,
lib/aws/lex/conversation/simulator.rb,
lib/aws/lex/conversation/type/base.rb,
lib/aws/lex/conversation/type/slot.rb,
lib/aws/lex/conversation/type/event.rb,
lib/aws/lex/conversation/type/intent.rb,
lib/aws/lex/conversation/handler/base.rb,
lib/aws/lex/conversation/handler/echo.rb,
lib/aws/lex/conversation/type/context.rb,
lib/aws/lex/conversation/type/message.rb,
lib/aws/lex/conversation/response/base.rb,
lib/aws/lex/conversation/slot/elicitor.rb,
lib/aws/lex/conversation/spec/matchers.rb,
lib/aws/lex/conversation/type/response.rb,
lib/aws/lex/conversation/response/close.rb,
lib/aws/lex/conversation/type/sentiment.rb,
lib/aws/lex/conversation/type/checkpoint.rb,
lib/aws/lex/conversation/type/input_mode.rb,
lib/aws/lex/conversation/type/slot_shape.rb,
lib/aws/lex/conversation/type/slot_value.rb,
lib/aws/lex/conversation/handler/delegate.rb,
lib/aws/lex/conversation/slot/elicitation.rb,
lib/aws/lex/conversation/type/enumeration.rb,
lib/aws/lex/conversation/response/delegate.rb,
lib/aws/lex/conversation/support/inflector.rb,
lib/aws/lex/conversation/type/time_to_live.rb,
lib/aws/lex/conversation/type/dialog_action.rb,
lib/aws/lex/conversation/type/response_card.rb,
lib/aws/lex/conversation/type/session_state.rb,
lib/aws/lex/conversation/type/interpretation.rb,
lib/aws/lex/conversation/response/elicit_slot.rb,
lib/aws/lex/conversation/type/sentiment_score.rb,
lib/aws/lex/conversation/response/elicit_intent.rb,
lib/aws/lex/conversation/type/fulfillment_state.rb,
lib/aws/lex/conversation/type/intent_confidence.rb,
lib/aws/lex/conversation/type/invocation_source.rb,
lib/aws/lex/conversation/handler/slot_resolution.rb,
lib/aws/lex/conversation/response/confirm_intent.rb,
lib/aws/lex/conversation/type/confirmation_state.rb,
lib/aws/lex/conversation/type/dialog_action_type.rb,
lib/aws/lex/conversation/type/sentiment_response.rb,
lib/aws/lex/conversation/type/session_attributes.rb,
lib/aws/lex/conversation/support/mixins/responses.rb,
lib/aws/lex/conversation/exception/missing_handler.rb,
lib/aws/lex/conversation/type/message/content_type.rb,
lib/aws/lex/conversation/type/response_card/button.rb,
lib/aws/lex/conversation/type/slot_elicitation_style.rb,
lib/aws/lex/conversation/support/mixins/slot_elicitation.rb
Defined Under Namespace
Modules: Exception, Handler, Response, Slot, Spec, Support, Type
Classes: Simulator
Constant Summary
collapse
- VERSION =
'6.3.0'
Instance Attribute Summary collapse
Instance Method Summary
collapse
#close, #confirm_intent, #delegate, #elicit_intent, #elicit_slot
Constructor Details
#initialize(opts = {}) ⇒ Conversation
Returns a new instance of Conversation.
12
13
14
15
16
|
# File 'lib/aws/lex/conversation.rb', line 12
def initialize(opts = {})
self.event = opts.fetch(:event)
self.context = opts.fetch(:context)
self.lex = Type::Event.shrink_wrap(event)
end
|
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
10
11
12
|
# File 'lib/aws/lex/conversation.rb', line 10
def context
@context
end
|
#event ⇒ Object
Returns the value of attribute event.
10
11
12
|
# File 'lib/aws/lex/conversation.rb', line 10
def event
@event
end
|
#lex ⇒ Object
Returns the value of attribute lex.
10
11
12
|
# File 'lib/aws/lex/conversation.rb', line 10
def lex
@lex
end
|
Instance Method Details
#active_context(name:) ⇒ Object
112
113
114
|
# File 'lib/aws/lex/conversation.rb', line 112
def active_context(name:)
lex.session_state.active_contexts.find { |c| c.name == name }
end
|
#active_context!(name:, turns: 10, seconds: 300, attributes: {}) ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/aws/lex/conversation.rb', line 116
def active_context!(name:, turns: 10, seconds: 300, attributes: {})
instance = active_context(name: name)
if instance
clear_context!(name: name)
else
instance = Type::Context.new
end
instance.name = name
instance.context_attributes = attributes
instance.time_to_live = Type::TimeToLive.new(
turns_to_live: turns,
time_to_live_in_seconds: seconds
)
lex.session_state.active_contexts << instance
instance
end
|
#active_context?(name:) ⇒ Boolean
108
109
110
|
# File 'lib/aws/lex/conversation.rb', line 108
def active_context?(name:)
!active_context(name: name).nil?
end
|
#chain ⇒ Object
18
19
20
|
# File 'lib/aws/lex/conversation.rb', line 18
def chain
@chain ||= []
end
|
#checkpoint(label:) ⇒ Object
85
86
87
|
# File 'lib/aws/lex/conversation.rb', line 85
def checkpoint(label:)
checkpoints.find { |v| v.label == label }
end
|
#checkpoint!(opts = {}) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/aws/lex/conversation.rb', line 61
def checkpoint!(opts = {})
label = opts.fetch(:label)
params = {
label: label,
dialog_action_type: opts.fetch(:dialog_action_type) { 'Delegate' },
fulfillment_state: opts[:fulfillment_state],
intent: opts.fetch(:intent) { lex.current_intent },
slot_to_elicit: opts[:slot_to_elicit]
}.compact
if checkpoint?(label: label)
checkpoint(label: label).assign_attributes!(params)
else
checkpoints.unshift(
Type::Checkpoint.build(params)
)
end
end
|
#checkpoint?(label:) ⇒ Boolean
81
82
83
|
# File 'lib/aws/lex/conversation.rb', line 81
def checkpoint?(label:)
!checkpoint(label: label).nil?
end
|
#checkpoints ⇒ Object
89
90
91
|
# File 'lib/aws/lex/conversation.rb', line 89
def checkpoints
lex.session_state.session_attributes.checkpoints
end
|
#clear_all_contexts! ⇒ Object
141
142
143
|
# File 'lib/aws/lex/conversation.rb', line 141
def clear_all_contexts!
lex.session_state.active_contexts = []
end
|
#clear_context!(name:) ⇒ Object
137
138
139
|
# File 'lib/aws/lex/conversation.rb', line 137
def clear_context!(name:)
lex.session_state.active_contexts.delete_if { |c| c.name == name }
end
|
#handlers ⇒ Object
37
38
39
|
# File 'lib/aws/lex/conversation.rb', line 37
def handlers
chain.map(&:class)
end
|
#handlers=(list) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/aws/lex/conversation.rb', line 22
def handlers=(list)
last = nil
reversed = list.reverse.map do |element|
handler = element.fetch(:handler).new(
options: element.fetch(:options) { {} },
successor: last
)
last = handler
handler
end
@chain = reversed.reverse
end
|
#intent_confidence ⇒ Object
45
46
47
|
# File 'lib/aws/lex/conversation.rb', line 45
def intent_confidence
@intent_confidence ||= Type::IntentConfidence.new(event: lex)
end
|
#intent_name ⇒ Object
49
50
51
|
# File 'lib/aws/lex/conversation.rb', line 49
def intent_name
lex.current_intent.name
end
|
#respond ⇒ Object
41
42
43
|
# File 'lib/aws/lex/conversation.rb', line 41
def respond
chain.first.handle(self)
end
|
#restore_from!(checkpoint) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/aws/lex/conversation.rb', line 93
def restore_from!(checkpoint)
checkpoints.delete_if { |c| c.label == checkpoint.label }
lex.current_intent = nil
lex.session_state.intent = checkpoint.intent
dialog_action = Type::DialogAction.new(
type: checkpoint.dialog_action_type,
slot_to_elicit: checkpoint.slot_to_elicit
)
lex.session_state.dialog_action = dialog_action
self
end
|
#session ⇒ Object
57
58
59
|
# File 'lib/aws/lex/conversation.rb', line 57
def session
lex.session_state.session_attributes
end
|
#simulate! ⇒ Object
16
17
18
|
# File 'lib/aws/lex/conversation/spec.rb', line 16
def simulate!
@simulate ||= Simulator.new(lex: lex)
end
|
#slots ⇒ Object
53
54
55
|
# File 'lib/aws/lex/conversation.rb', line 53
def slots
lex.current_intent.slots
end
|
#stash ⇒ Object
145
146
147
|
# File 'lib/aws/lex/conversation.rb', line 145
def stash
@stash ||= {}
end
|