如何使用 npm 中的 alexa-sdk 将 LaunchRequest 委托给 IntentRequest

How can I delegate the LaunchRequest to an IntentRequest using the alexa-sdk from npm

我正在使用 alexa-sdk. I am using a dialog model to handle the user interaction. I am having some trouble passing the flow along to new request types 在节点中构建 Alexa 技能,例如从启动请求到意图请求。

下面是我的处理程序示例以及我理想中想要的。我的具体用例是我想问用户一些问题,然后根据他们的回答将他们发送到不同的意图。在意图中,我想访问请求对象,就好像他们最初输入了那个意图一样,所以对话模型可以完成它的工作。

const handlers = {
    'LaunchRequest': function () {
        this.emit('Entry'); // this does not do what I want
    },
    'Entry': function () {
        let request = this.event.request; // this is the launch request object.
        // I would like to get the request object for Entry, like if the user started here

        // ask some questions, potentially passing the torch to a new intent based on the answers
    }
};

那么,有什么方法可以 "call" 像用户最初针对该意图发出请求那样的意图吗?抱歉,如果我遗漏了文档中明显的内容,我认为我已经非常彻底地搜索了,但是有很多文档。 ps: 我当然可以手动构建请求对象,但我觉得我真的不应该这样做。

我很确定还没有办法像您所问的那样调用意图。

如果你仔细阅读对话框指令的语法描述 here,它会说:

Note that you cannot change intents when returning a Dialog directive, so the intent name and set of slots must match the intent sent to your skill.

通过返回对话指令,您可以 'elicit' 或 'confirm' 插槽或意图,甚至让代理为您处理您的对话,并在 Skill Builder 中设置提示和重新提示。

据我所知,触发特定意图的唯一解决方案是让用户调用它。您可以引导用户说出特定的话语来触发您的意图。

至于保存较早的请求,您可以使用session attributes。只需在 Launch 之后使用包含整个 LaunchRequest 的会话属性构建响应。

"sessionAttributes": {
"oldRequest": this.event.request
}