Back to Parent

on_intent("THE_ALTERNATE") do
 
    response.should_end_session = false
    session_attributes[:userName]
    session_attributes[:ingredients]
    session_attributes[:cuisine]
    session_attributes[:dislikes]
    session_attributes[:intolerances]
    session_attributes[:diet]

    #WORKING WAY TO EXTRACT SESSION INFORMATION
    attributes = session.attributes
    puts attributes.to_s
    rawIngredients = session.attributes["ingredients"]
    savedIngredients = CGI::escape(rawIngredients)


    attributes = session.attributes
    puts attributes.to_s
    savedCuisine = session.attributes["cuisine"]

    attributes = session.attributes
    puts attributes.to_s
    savedDislikes = session.attributes["dislikes"]

    attributes = session.attributes
    puts attributes.to_s
    savedIntolerances = session.attributes["intolerances"]

    attributes = session.attributes
    puts attributes.to_s
    savedDiets = session.attributes["diet"]


    api_url = "https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/searchComplex?addRecipeInformation=false&cuisine=" + savedCuisine + "&diet=" + savedDiets + "&excludeIngredients=" + savedDislikes + "&fillIngredients=false&includeIngredients=" + savedIngredients + "&instructionsRequired=true&intolerances=" + savedIntolerances + "&limitLicense=false"

    rawName = find_alt_recipe api_url
    cleanName = rawName.tr('&', '')
    recipeImage = find_alt_image api_url
    recipeURL = find_alt_URL api_url



    # add a response to Alexa using ssml to add pauses
   
    response.set_output_speech_ssml('<speak> Ok then, how about this one called ' + cleanName + '<break time="2s"/> I\'ll send over the details now. What are your thoughts on this one?</speak>')
  
    # Trigger Twillio SMS response ========================================

    @client = Twilio::REST::Client.new ENV["TWILIO_ACCOUNT_SID"], ENV["TWILIO_AUTH_TOKEN"]

    @client.api.account.messages.create(
      from: ENV['TWILIO_FROM'],
      to: "+0000000000",
      body: "🤷‍ Sorry about that last one. I hope " + cleanName + " works for you!",
      media_url: recipeImage,
    )

    @client.api.account.messages.create(
      from: ENV['TWILIO_FROM'],
      to: "+0000000000",
      body: recipeURL,
    )


    # create a card response in the alexa app
    response.set_simple_card("sous", "onboard")
    # log the output if needed
    logger.info 'alternative processed'
  end
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0