Home

Awesome

alexa-skills-ruby

Simple library to interface with the Alexa Skills Kit

Build Status

The primary way to interact with this library is by extending the AlexaSkillsRuby::Handler class. Create a subclass and register event handlers.

The following handlers are available:

In event handlers, the following methods are available:

The AlexaSkillsRuby::Handler constructor takes an options hash and processes the following keys:

The AlexaSkillsRuby::Handler#handle method takes 2 arguments: a string containing the body of the request, and a hash of HTTP headers. If using signature validation, the headers hash must contain the Signature and SignatureCertChainUrl HTTP headers.

Example Sinatra App Using this Library

require 'sinatra'
require 'alexa_skills_ruby'

class CustomHandler < AlexaSkillsRuby::Handler

  on_intent("GetZodiacHoroscopeIntent") do
    slots = request.intent.slots
    response.set_output_speech_text("Horoscope Text")
    #response.set_output_speech_ssml("<speak><p>Horoscope Text</p><p>More Horoscope text</p></speak>")
    response.set_reprompt_speech_text("Reprompt Horoscope Text")
    #response.set_reprompt_speech_ssml("<speak>Reprompt Horoscope Text</speak>")
    response.set_simple_card("title", "content")
    logger.info 'GetZodiacHoroscopeIntent processed'
  end

end

post '/' do
  content_type :json

  handler = CustomHandler.new(application_id: ENV['APPLICATION_ID'], logger: logger)

  begin
    hdrs = { 'Signature' => request.env['HTTP_SIGNATURE'], 'SignatureCertChainUrl' => request.env['HTTP_SIGNATURECERTCHAINURL'] }
    handler.handle(request.body.read, hdrs)
  rescue AlexaSkillsRuby::Error => e
    logger.error e.to_s
    403
  end

end