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

How to catch user reply / response in an Alexa Skill app?

我正在尝试创建一种侦听用户回复的技能。由于某些原因,我不能总是收到用户回复。

我的设置有问题。我相信代码没问题,所以可能 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) 你需要在话语中包含槽位,例如:
ChatSession start chat {Reply}

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

希望对您有所帮助!

我想出来了

  1. 添加一句话ChatSession {Reply}
  2. 将一堆单词和短语添加到自定义插槽中,使用一些在线生成器。