0

I'm writing an Alexa application in node.js to answer product spec questions. For example, I'd like to be able to ask "What is the maximum capacity of (product)?" Currently, I have separate intents for each question for each product, which is resulting in incredibly messy code with a ton of handlers. What I'd like to do is just have one MaxCapacity intent for example, that uses slots (containing the different products) to assign the fact. I'm still relatively new at node.js, so I apologize if this is really sloppy. I know how to make new slots on the developer console, I just don't know how to code it on the backend. This is one of the handlers:

const GetNewFactHandler1 = {
  canHandle(handlerInput) {
    const request = handlerInput.requestEnvelope.request;
    return request.type === 'LaunchRequest'
      || (request.type === 'IntentRequest'
        && request.intent.name === 'UMaxCapacityIntent');

      */ And if slot type == *product*, then: */

  },
  handle(handlerInput) {
    const factArr = data;
    const randomFact = factArr[1]; //Array with all the answers
    const speechOutput = GET_FACT_MESSAGE + randomFact;

    return handlerInput.responseBuilder
    .speak(speechOutput)
    .withSimpleCard(SKILL_NAME, randomFact)
    .getResponse();
  },
};

I hope that makes sense, but I'd be happy to explain further. Thank you!

nhlyoung
  • 67
  • 2
  • 8

1 Answers1

0

If I understood correctly, you want to invoke this handler, when slot 'product' exists? If so, you can use 'getSlot' helper method. If slot exists in the request, it returns that slot, otherwise it results in null. So just add extra check to canHandle condition && getSlot(handlerInput.requestEnvelope, 'product') and that should be it.

R. Vait
  • 918
  • 2
  • 7
  • 20
  • Thanks for your response! The slot will always exist (I can't ask about the max capacity of nothing). How would I include the getSlot method? I have const Alexa = require('ask-sdk'); at the top of my code, but it's not taking care of it. Just to clear things up, say the product is a laptop. And the values in the slot are different types of laptops. I would like to have it where if product == latitude (the laptop I'm using now), then respond with a certain fact. Does that make sense? – nhlyoung Aug 23 '19 at 12:26