class Aws::Lex::Conversation

Constants

VERSION

Attributes

context[RW]
event[RW]
lex[RW]

Public Class Methods

new(opts = {}) click to toggle source
# 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

Public Instance Methods

active_context(name:) click to toggle source
# File lib/aws/lex/conversation.rb, line 98
def active_context(name:)
  lex.session_state.active_contexts.find { |c| c.name == name }
end
active_context!(name:, turns: 10, seconds: 300, attributes: {}) click to toggle source
# File lib/aws/lex/conversation.rb, line 102
def active_context!(name:, turns: 10, seconds: 300, attributes: {})
  # look for an existing active context if present
  instance = active_context(name: name)

  if instance
    lex.session_state.active_contexts.delete_if { |c| c.name == name }
  else
    instance = Type::Context.new
  end

  # update attributes as requested
  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:) click to toggle source
# File lib/aws/lex/conversation.rb, line 94
def active_context?(name:)
  !active_context(name: name).nil?
end
chain() click to toggle source
# File lib/aws/lex/conversation.rb, line 18
def chain
  @chain ||= []
end
checkpoint(label:) click to toggle source
# File lib/aws/lex/conversation.rb, line 86
def checkpoint(label:)
  checkpoints.find { |v| v.label == label }
end
checkpoint!(opts = {}) click to toggle source
# 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),
    fulfillment_state: opts[:fulfillment_state],
    intent: lex.current_intent,
    slot_to_elicit: opts[:slot_to_elicit]
  }.compact

  if checkpoint?(label: label)
    # update the existing checkpoint
    checkpoint(label: label).assign_attributes!(params)
  else
    # push a new checkpoint to the recent_intent_summary_view
    checkpoints.unshift(
      Type::Checkpoint.new(params)
    )
  end
end
checkpoint?(label:) click to toggle source
# File lib/aws/lex/conversation.rb, line 82
def checkpoint?(label:)
  !checkpoint(label: label).nil?
end
checkpoints() click to toggle source
# File lib/aws/lex/conversation.rb, line 90
def checkpoints
  lex.session_state.session_attributes.checkpoints
end
clear_all_contexts!() click to toggle source
# File lib/aws/lex/conversation.rb, line 127
def clear_all_contexts!
  lex.session_state.active_contexts = []
end
clear_context!(name:) click to toggle source
# File lib/aws/lex/conversation.rb, line 123
def clear_context!(name:)
  lex.session_state.active_contexts.delete_if { |c| c.name == name }
end
handlers() click to toggle source
# File lib/aws/lex/conversation.rb, line 37
def handlers
  chain.map(&:class)
end
handlers=(list) click to toggle source
# 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() click to toggle source
# File lib/aws/lex/conversation.rb, line 45
def intent_confidence
  @intent_confidence ||= Type::IntentConfidence.new(event: lex)
end
intent_name() click to toggle source
# File lib/aws/lex/conversation.rb, line 49
def intent_name
  lex.current_intent.name
end
respond() click to toggle source
# File lib/aws/lex/conversation.rb, line 41
def respond
  chain.first.handle(self)
end
session() click to toggle source
# File lib/aws/lex/conversation.rb, line 57
def session
  lex.session_state.session_attributes
end
simulate!() click to toggle source
# File lib/aws/lex/conversation/spec.rb, line 16
def simulate!
  @simulate ||= Simulator.new(lex: lex)
end
slots() click to toggle source
# File lib/aws/lex/conversation.rb, line 53
def slots
  lex.current_intent.slots
end
stash() click to toggle source
# File lib/aws/lex/conversation.rb, line 131
def stash
  @stash ||= {}
end