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

查看:38
本文介绍了如何结束自定义 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();
  },
};

推荐答案

当响应 JSON 中的 shouldEndSession 标志设置为 true 时,Alexa 结束会话.

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();

响应构建器辅助函数在此处

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

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