1
votes

I am building a custom Alexa skill In which I can ask the name of User and repeat it. (Working fine). Now, the next part is to confirm the name of the user.

Alexa: "Please confirm your name!"<br>
User:"-"

Alexa: "Please confirm your name!"<br>
User: "No"

Alexa: "Please confirm your name!"<br>
**User: "Yes I confirm"**  
End.

Now I am trying to achieve the above behaviour, as Alexa should prompt "Please confirm your name!" on every 10 seconds until the user Responds

"Yes, I confirm".

I have checked the API documentation but not able to find any Intent related to this case.

Please share some info or solution.

2

2 Answers

1
votes

Repromting every 10 seconds when the user doesn't responds, not sure if we can do.

But we can achieve the Yes/No part. One way of doing this is by using the state. Here in this example, I am using the node-cache module for state management.

Consider the below intent named "ConfirmationQuestionIntent". It sets the state to "confirm-name".

const ConfirmationQuestionIntentHandler = {
  canHandle(handlerInput) {
    return (
      handlerInput.requestEnvelope.request.type === "IntentRequest" &&
      handlerInput.requestEnvelope.request.intent.name === "ConfirmationQuestionIntent"
    );
  },
  handle(handlerInput) {
    const speechText = "Please confirm your name as 'John'.";
    myCache.set('state','confirm-name');
    return handlerInput.responseBuilder
      .speak(speechText)
      .reprompt(speechText)
      .getResponse();
  }
};

Now, enable/Add two BuiltIn intents, AMAZON.YesIntent and AMAZON.NoIntent. Consider the AMAZON.NoIntent below, In the handler function. it checks if there is any state with the name "confirm-name". If it is present, it responds with "Please confirm your name as 'John'." and if not then responds with the default response.

const NoBuiltInIntent = {
  canHandle(handlerInput) {
    return (
      handlerInput.requestEnvelope.request.type === "IntentRequest" &&
      handlerInput.requestEnvelope.request.intent.name === "AMAZON.NoIntent"
    );
  },

  handle(handlerInput) {
    const state = myCache.get("state");
    let speechText = "I didn't get this!. Could you please rephrase.";
    if(state === "confirm-name") speechText = "Please confirm your name as 'John'.";
    return handlerInput.responseBuilder
      .speak(speechText)
      .reprompt(speechText)
      .getResponse();
  }
};

Consider the AMAZON.YesIntent below, In the handle function, it checks if there is any state named "confirm-name". If it is, then it responds back with "Thanks for the confirmation" and deletes the state from the cache. If not then it asks the user to rephrase.

const YesBuiltInIntent = {
  canHandle(handlerInput) {
    return (
      handlerInput.requestEnvelope.request.type === "IntentRequest" &&
      handlerInput.requestEnvelope.request.intent.name === "AMAZON.YesIntent"
    );
  },

  handle(handlerInput) {
    const state = myCache.get("state");
    let speechText = "I didn't get this!. Could you please rephrase.";
    if(state === "confirm-name") speechText = "Thanks for the confirmation.";
    myCache.del('state');
    return handlerInput.responseBuilder
      .speak(speechText)
      .reprompt(speechText)
      .getResponse();
  }
};

So, you can use "State" to identify in which scenario the user is responding to and then provide the right response.

1
votes

I am afraid it is not possible to make Alexa ask the question every 10 seconds untill the user confirm.

I suppose you are using confirmSlotDirective to confirm the name of the user.

confirmSlotDirective or simply any confirmation directive in Alexa works with words that only agree or disagree with the confirmation message. e.g. YES/NO

Solution:

1) If you have already asked for the name of the user (e.g. 'John'), do not ask it again. Simply make Alexa to say:

Alexa: "Your name is John, right?" Or "You said John? please confirm?"

User: can say Yes/No to confirm.

Note: Alexa only recognizes a limited set of international names.

2) Better way to get user's name is using Alexa's Customer Profile Api, so you won't have to worry about Alexa not able to recognize name let alone the confirmation of user's name.