Class: Alexa::Session

Inherits:
HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/alexa/session.rb

Instance Method Summary collapse

Constructor Details

#initialize(session = {}) ⇒ Session

Returns a new instance of Session.



17
18
19
20
# File 'lib/alexa/session.rb', line 17

def initialize(session={})
  @variables = session
  super(session["attributes"])
end

Instance Method Details

#application_idObject

Get application’s ID from session



56
57
58
# File 'lib/alexa/session.rb', line 56

def application_id
  @variables["application"]["applicationId"]
end

#elicitation_count_for(slot_name) ⇒ Object

Get the elicitation count of a slot.

Elicitation counts are maintained in the session so that they can be referred to within the intenthandlers or the views

Options:

- slot_name: Slot name to return the elicitation count for


29
30
31
32
33
34
# File 'lib/alexa/session.rb', line 29

def elicitation_count_for(slot_name)
  self["elicitations"] ||= {}
  if self["elicitations"][slot_name].present?
    return self["elicitations"][slot_name]["count"] end
  return 0
end

#increment_elicitation_count!(slot_name) ⇒ Object

Increase the elicitation count of a slot.

Elicitation counts are maintained in the session so that they can be referred to within the intenthandlers or the views

Options:

- slot_name: Slot name to increment the elicitation count for


43
44
45
46
47
48
# File 'lib/alexa/session.rb', line 43

def increment_elicitation_count!(slot_name)
  count = elicitation_count_for(slot_name)
  self["elicitations"].merge!(
    "#{slot_name}": { count: count + 1 }
  )
end

#new?Boolean

Whether its a new session.

Returns:

  • (Boolean)


51
52
53
# File 'lib/alexa/session.rb', line 51

def new?
  @variables["new"] == true
end

#user_idObject

Get Amazon user’s ID from session



61
62
63
# File 'lib/alexa/session.rb', line 61

def user_id
  @variables["user"]["userId"]
end