Class: ActionAlexa::Skill

Inherits:
Object
  • Object
show all
Defined in:
lib/action_alexa/skill.rb

Overview

Top level class that will:

1. Take in the Alexa request payload
2. Fetch the intent Alexa is attempting to run
3. Run the intent
4. Return the response to Alexa for the end user

This class should be run within a Rails Controller to interface between Alexa calls to the web service and intent executions

Constant Summary collapse

MISSING_DEFAULT_INTENT_MESSAGE =
'There was an error talking to the service'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(alexa_payload) ⇒ Skill

Returns a new instance of Skill.



18
19
20
21
# File 'lib/action_alexa/skill.rb', line 18

def initialize(alexa_payload)
  @alexa_payload = ActionAlexa::AlexaRequest.new(alexa_payload)
  @logger = ActionAlexa.config.logger
end

Instance Attribute Details

#alexa_payloadObject (readonly)

Returns the value of attribute alexa_payload.



13
14
15
# File 'lib/action_alexa/skill.rb', line 13

def alexa_payload
  @alexa_payload
end

#loggerObject (readonly)

Returns the value of attribute logger.



13
14
15
# File 'lib/action_alexa/skill.rb', line 13

def logger
  @logger
end

Class Method Details

.execute(alexa_payload) ⇒ Object



23
24
25
# File 'lib/action_alexa/skill.rb', line 23

def self.execute(alexa_payload)
  new(alexa_payload).execute_skill
end

Instance Method Details

#execute_skillObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/action_alexa/skill.rb', line 27

def execute_skill
  # Find the intent based on the registery intents
  intent_class = ActionAlexa::Intent::Registry.find_intent(
    alexa_payload.intent_name
  )

  return fallback_intent_response if intent_class.nil?

  intent = intent_class.new(alexa_payload)

  # Execute the intent and return the result back to Alexa
  intent.execute
end