class Aws::Lex::Conversation::Slot::Elicitation
Attributes
conversation[RW]
elicit[RW]
fallback[RW]
follow_up_messages[RW]
maximum_elicitations[RW]
messages[RW]
name[RW]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/aws/lex/conversation/slot/elicitation.rb, line 11 def initialize(opts = {}) self.name = opts.fetch(:name) self.elicit = opts.fetch(:elicit) { ->(_c) { true } } self.messages = opts.fetch(:messages) self.follow_up_messages = opts.fetch(:follow_up_messages) { opts.fetch(:messages) } self.fallback = opts[:fallback] self.maximum_elicitations = opts.fetch(:maximum_elicitations) { 0 } end
Public Instance Methods
elicit!()
click to toggle source
# File lib/aws/lex/conversation/slot/elicitation.rb, line 20 def elicit! return false unless elicit? return fallback.call(conversation) if maximum_elicitations? increment_slot_elicitations! conversation.elicit_slot( slot_to_elicit: name, messages: elicitation_messages ) end
elicit?()
click to toggle source
# File lib/aws/lex/conversation/slot/elicitation.rb, line 31 def elicit? return false if maximum_elicitations? && fallback.nil? elicit.call(conversation) && !slot.filled? end
Private Instance Methods
compose_messages(msg)
click to toggle source
# File lib/aws/lex/conversation/slot/elicitation.rb, line 47 def compose_messages(msg) msg.is_a?(Proc) ? msg.call(conversation) : msg end
elicitation_attempts()
click to toggle source
# File lib/aws/lex/conversation/slot/elicitation.rb, line 69 def elicitation_attempts conversation.session[session_key].to_i end
elicitation_messages()
click to toggle source
# File lib/aws/lex/conversation/slot/elicitation.rb, line 43 def elicitation_messages first_elicitation? ? compose_messages(messages) : compose_messages(follow_up_messages) end
first_elicitation?()
click to toggle source
# File lib/aws/lex/conversation/slot/elicitation.rb, line 61 def first_elicitation? elicitation_attempts == 1 end
increment_slot_elicitations!()
click to toggle source
# File lib/aws/lex/conversation/slot/elicitation.rb, line 51 def increment_slot_elicitations! conversation.session[session_key] = elicitation_attempts + 1 end
maximum_elicitations?()
click to toggle source
# File lib/aws/lex/conversation/slot/elicitation.rb, line 55 def maximum_elicitations? return false if maximum_elicitations.zero? elicitation_attempts > maximum_elicitations end
session_key()
click to toggle source
# File lib/aws/lex/conversation/slot/elicitation.rb, line 65 def session_key :"SlotElicitations_#{name}" end
slot()
click to toggle source
# File lib/aws/lex/conversation/slot/elicitation.rb, line 39 def slot conversation.slots[name.to_sym] end