我正在尝试创建一个监听用户回复的技能。出于某种原因,我不能总是抓住用户的回复。
- 当我说:
Alexa, open MyApp and start chat
- 和 Alexa 回复
New chat session started
- 然后我检查会话,看看它是否是旧的,并用它做一些事情,但它并没有真正起作用。
我的设置有问题。我相信代码没问题,所以可能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