如何结束自定义Alexa技能的会话? [英] How to end session for custom Alexa skill?

查看:82
本文介绍了如何结束自定义Alexa技能的会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Alexa创建自定义技能。我想在 AMAZON.StopIntent 上关闭会话。如何使用以下代码实现这一目标?

I am creating a custom skill for Alexa. I want to close the session on AMAZON.StopIntent. How can I achieve this with below code?

const ExitHandler = {
  canHandle(handlerInput) {
    const request = handlerInput.requestEnvelope.request;
    return request.type === 'IntentRequest'
      && (request.intent.name === 'AMAZON.StopIntent');
  },
  handle(handlerInput) {
    return handlerInput.responseBuilder
      .speak('bye!')
      .reprompt('bye!')
      .getResponse();
  },
};


推荐答案

Alexa在 shouldEndSession 时结束会话

Alexa ends the session when shouldEndSession flag is set to true in the response JSON.

... 
"shouldEndSession": true
...

在响应生成器中,您可以尝试使用辅助函数 withShouldEndSession( true)

In your response builder can you try with the helper function withShouldEndSession(true)

 return handlerInput.responseBuilder
      .speak('bye!')
      .withShouldEndSession(true)
      .getResponse();

列出了响应构建器帮助器功能此处

Response builder helper functions are listed here

这篇关于如何结束自定义Alexa技能的会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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