如何在Alexa Skill应用程序中捕获用户回复/响应?

时间:2017-01-31 16:50:02

标签: javascript alexa alexa-skills-kit alexa-slot

我正在尝试创建一个侦听用户回复的技能。出于某种原因,我不能总是抓住用户回复。

  • 当我说:New chat session started
  • 时,聊天会话开始了
  • Alexa回复intents
  • 然后我检查会话并查看它是否是旧会话,并对其执行某些操作,但它确实无法正常工作。

我的设置中的某些内容是错误的。我相信代码没问题,所以可能exports.handler = (event, context) => { // if the session is old, if (event.session.new === false) { // get the user reply // this doesn't seem to allways work var userReply = event.request.intent.slots.Reply.value; } try { switch (event.request.type) { case "LaunchRequest": // do nothing here break; case "IntentRequest": switch (event.request.intent.name) { case "ChatSession": // the chat session starts, when I say: Alexa, open MyApp and start chat. // this works, and the session seems to remain open, because Alexa waits for me to say something else alexaReplyes({noCard: true, noNewSession: true, reply: 'New chat session started'}); break; default: throw "Invalid intent" } break; case "SessionEndedRequest": // do nothing here break; default: context.fail(`INVALID REQUEST TYPE`) } } catch (error) { context.fail(`Exception: ${error}`) } }设置错误

代码很简单。

{
    "intents": [
        {
            "intent": "ChatSession",
            "slots": [
                {
                    "name": "Reply",
                    "type": "REPLIES"
                }
            ]
        }
    ]
}



ChatSession start chat
{{1}}

2 个答案:

答案 0 :(得分:0)

是的,意图设置不正确。几件事:

1)您需要在话语中包含插槽,例如:
ChatSession start chat {Reply}

2)为你期望用户说话的方式添加更多话语是有意义的,例如:
ChatSession Yes {Reply}

希望有所帮助!

答案 1 :(得分:0)

我明白了。

  1. 添加一个话语_logger = { '/routeA': _logger(name: 'routeA'), '/routeB': _logger(name: 'routeB') }
  2. 在自定义插槽中添加一堆单词和短语,使用一些在线生成器。