Calling Another Alexa intent from within LaunchRequest

烈酒焚心 提交于 2019-12-23 19:28:28

问题


I am working on an Alexa skill where I would like to redirect user to one intent when he opens the skill via LaunchRequest.

  • User says Open xyz skill
  • LaunchRequest receives this and forwards the request to another intent.this.emit('AnotherIntent')
  • AnotherIntent has a SLOT which is required for its functioning.
  • I have setup the SLOT as required and AnotherIntent does work perfectly fine when invoked on its own.

However when I Launch the skill and tries to call AnotherIntent from within it as mentioned in Step 2 above, Alexa skill fails to launch.

One more thing to note is when I Test the same Alexa skill from within the skill builder for this scenario, the output json correctly shows me the SLOT being elicited. Not sure what is happening when I am trying to run it from Echo device.

I am using NodeJS and Lambda to deploy my Alexa handlers.

Any help would be appreciated.

Further reference based on the comment -

Handlers -

var handlers = {
'LaunchRequest': function () {
    console.log("LaunchRequest::" + JSON.stringify(this.event.request));
    this.emit('fooIntent');
},
'SessionEndedRequest': function () {
    console.log('session ended!');
},
'fooIntent': function () {
    const intentObj = this.event.request.intent;
     if (!intentObj || (intentObj && !intentObj.slots.WHEN.value)) {
        console.log('fooIntent::UserId' + this.event.session.user.userId);
        const slotToElicit = 'WHEN';
        const speechOutput = 'Ask a question here ?';
        const repromptSpeech = speechOutput;
        console.log("emitting elict now");
        this.emit(':elicitSlot', slotToElicit, speechOutput, repromptSpeech);   
    } else {
        // SLOT is filled, let's query the database to get the value for the slot.
        console.log("fooIntent intent:something is requested for " + this.event.request.intent.slots.WHEN.value);
        // All the slots are filled (And confirmed if you choose to confirm slot/intent)
       fooIntentFunction(this,this.event.request.intent.slots.WHEN.value);
    }
 },
'AMAZON.HelpIntent': function () {
    var speechOutput = "Need to come up with one.";
    var reprompt = "What can I help you with?";
    this.emit(':ask', speechOutput, reprompt);
},
'AMAZON.CancelIntent': function () {
    this.emit(':tell', 'Goodbye!');
},
'AMAZON.StopIntent': function () {
    this.emit(':tell', 'Goodbye!');
}

};

JSON Request captured in LaunchRequest

{
"type": "LaunchRequest",
"requestId": "amzn1.echo-api.request.972bb705-d181-495e-bf60-991f2bd8fbb1",
"timestamp": "2017-12-30T21:35:21Z",
"locale": "en-US"
}

JSON Request captured in the Intent when invoked from LaunchRequest. It shows that intent is not set then. I believe that is why it keeps failing when I try to emit elicit in the fooIntent implementation as shown above.

{
    "type": "LaunchRequest",
    "requestId": "amzn1.echo-api.request.972bb705-d181-495e-bf60-991f2bd8fbb1",
    "timestamp": "2017-12-30T21:35:21Z",
    "locale": "en-US"
}
  • Amit

回答1:


As specified in Amazon's documentation, the dialog interface is meant to fill all required slots of a specific intent:

The questions and answers are intended to gather and confirm values for all of the intent’s required slots. The conversation continues until all slots needed for the intent are filled and confirmed.

In your case, the user's request is not an intent (i.e. of the IntentRequest type), but a LaunchRequest. As such,it has no interaction model and no slots to elicit, even though it is processed by an intent handler.

You should get your Skill to work as intended with a deep invocation, like

Alexa, tell xyz skill to make me a sandwich

(if the sandwich intent, or in your case the fooIntent, has a WHEN slot to elicit).

Hope this helps!




回答2:


try this,

this.emitWithState("IntentName");

Hope this helps. all the best :)




回答3:


Calling an intent from another intent can be simply done using the following snippet - \ this.emit("Intent name")

In the response of your first intent, give the name of the intent you wish to call.



来源:https://stackoverflow.com/questions/48029668/calling-another-alexa-intent-from-within-launchrequest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!