Introduing the Alexa_skillresponse gem


require 'alexa_skillresponse'

req =  {"version"=>"1.0", "session"=>{"new"=>true, "sessionId"=>"amzn1.echo-api.session.1", "application"=>{"applicationId"=>"amzn1.ask.skill.0"}, "user"=>{"userId"=>"amzn1.ask.account.I"}}, "context"=>{"System"=>{"application"=>{"applicationId"=>"amzn1.ask.skill.0"}, "user"=>{"userId"=>"amzn1.ask.account.I"}, "device"=>{"deviceId"=>"amzn1.ask.device.A", "supportedInterfaces"=>{}}, "apiEndpoint"=>"https://api.eu.amazonalexa.com", "apiAccessToken"=>"A"}}, "request"=>{"type"=>"LaunchRequest", "requestId"=>"amzn1.echo-api.request.a", "timestamp"=>"2018-07-10T19:42:52Z", "locale"=>"en-GB", "shouldLinkResultBeReturned"=>false}}

h = JSON.parse req.to_json, symbolize_names: true
asr = AlexaSkillResponse.new(package='/home/james/tmp/icecream.rsf', debug: true)
asr.run(h)


file: icecream.rsf

<skill>
  <response id='welcome' attentive='false'>
    <script>
    'How can I help you?'
    </script>
  </response>
  <response id='IcecreamAsk' attentive='true'>
    <script>
    'Would you like a cone or a tub?'
    </script>
  </response>
</skill>

Output:

=> {:version=>"1.0", :response=>{:outputSpeech=>{:type=>"PlainText", :text=>"How can I help you?"}, :shouldEndSession=>false}}

The Alexa_skillresponse gem can be used with any web framework to process a request from an Alexa Skill. It relies upon the logical responses to be found from a kind of XML file known as an RSF file.

Resources