Skip to content

Instantly share code, notes, and snippets.

@nickcharlton
Created May 9, 2019 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickcharlton/1604cb559ae8bdcbc897265ca918d47a to your computer and use it in GitHub Desktop.
Save nickcharlton/1604cb559ae8bdcbc897265ca918d47a to your computer and use it in GitHub Desktop.
Alexa Endpoint Demo
require "sinatra"
require "erb"
before do
content_type :json
end
get "/" do
{ message: "Alexa Demo!" }.to_json
end
post "/endpoint" do
req_body = JSON.parse(request.body.read)
intent = req_body["request"]["intent"]
value = intent["slots"]["pokemon"]["value"]
template = File.open(File.dirname(__FILE__) + "/example.xml.erb", "rb").read
response = {
response: "You asked me about: #{value}. You gotta catch 'em all!"
}
ssml = ERB.new(template).result_with_hash(response)
{
version: "1.0",
response: {
outputSpeech: {
type: "SSML",
ssml: ssml,
}
}
}.to_json
end
<speak>
<voice>
<%= response %>
</voice>
</speak>
source "https://rubygems.org"
gem "sinatra"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment