从 LaunchRequest 中调用另一个 Alexa 意图 [英] Calling Another Alexa intent from within LaunchRequest

查看:19
本文介绍了从 LaunchRequest 中调用另一个 Alexa 意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一项 Alexa 技能,我想在用户通过 LaunchRequest 打开技能时将其重定向到一个意图.

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

  • 用户说打开xyz技能
  • Lau​​nchRequest 接收到这个并将请求转发到另一个意图.this.emit('AnotherIntent')
  • AnotherIntent 具有其功能所需的 SLOT.
  • 我已根据需要设置了 SLOT,并且 AnotherIntent 在单独调用时运行良好.
  • 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.

但是,当我启动该技能并尝试从其中调用 AnotherIntent 时,如上面第 2 步所述,Alexa 技能无法启动.

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.

要注意的另一件事是,当我在此场景的技能构建器中测试相同的 Alexa 技能时,输出 json 正确地向我显示了被引出的 SLOT.不确定当我尝试从 Echo 设备运行它时发生了什么.

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.

我正在使用 NodeJS 和 Lambda 来部署我的 Alexa 处理程序.

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

任何帮助将不胜感激.

基于评论的进一步参考 -

Further reference based on the comment -

处理程序 -

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!');
}

};

在 LaunchRequest 中捕获的 JSON 请求

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"
}

从 LaunchRequest 调用时在 Intent 中捕获的 JSON 请求.它表明 intent 没有设置.我相信这就是为什么当我尝试在 fooIntent 实现中发出 elicit 时它一直失败的原因,如上所示.

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"
}

  • 阿米特
  • 推荐答案

    亚马逊的文档,对话界面旨在填充特定意图的所有必需插槽:

    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.

    在您的情况下,用户的请求不是意图(即 IntentRequest 类型),而是 LaunchRequest.因此,它没有交互模型,也没有要引出的槽,即使它是由意图处理程序处理的.

    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,告诉 xyz 技能给我做三明治

    Alexa, tell xyz skill to make me a sandwich

    (如果三明治意图,或者在你的例子中是 fooIntent,有一个 WHEN 槽来引出).

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

    希望这有帮助!

    这篇关于从 LaunchRequest 中调用另一个 Alexa 意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆