假设我们在交互模型中有一个名为创建会议请求的意图。
"intents": [
{
"name": "CreateMeetingRequest",
"slots": [
{
"name": "meetingdate",
"type": "AMAZON.DATE",
"samples": [
"{meetingdate} at {meetingTime} for {duration}",
"{meetingdate} at {meetingTime}",
"{meetingdate} and {meetingTime}",
"{meetingdate}"
]
},
{
"name": "meetingTime",
"type": "AMAZON.TIME",
"samples": [
"{meetingTime} for {duration}",
"{meetingTime}"
]
},
{
"name": "duration",
"type": "AMAZON.DURATION",
"samples": [
"{duration}"
]
},
{
"name": "subject",
"type": "AMAZON.SearchQuery",
"samples": [
"{subject}"
]
},
{
"name": "toName",
"type": "AMAZON.US_FIRST_NAME",
"samples": [
"{toName}"
]
}
],
"samples": [
"meeting invite",
"set up meeting",
"setup meeting",
"{meetingdate} at {meetingTime}",
"create meeting with {toName}",
"schedule a meeting with {toName} on {meetingdate} at {meetingTime} for {duration}",
"Setup meeting with {toName}",
"create meeting",
"Setup meeting on {meetingdate} at {meetingTime}",
"Setup new meeting",
"create meeting request"
]
}
]
你想在 lambda 代码中访问它。您可以使用以下行。
'CreateMeetingRequest': function () {
const toName = (this.event.request.intent.slots.toName.value ? this.event.request.intent.slots.toName.value.toLowerCase() : null);
const subject = (this.event.request.intent.slots.subject.value ? this.event.request.intent.slots.subject.value.toLowerCase() : null);
const meetingdate = (this.event.request.intent.slots.meetingdate.value ? this.event.request.intent.slots.meetingdate.value : null);
const meetingTime = (this.event.request.intent.slots.meetingTime.value ? this.event.request.intent.slots.meetingTime.value : null);
const duration = (this.event.request.intent.slots.duration.value ? this.event.request.intent.slots.duration.value : null);
console.log("toName:",toName,", meetingdate:",meetingdate,", meetingTime:", meetingTime);
//your business logic
},
this
是 Object 包含来自 alexa 的完整 JSON 请求。因此,您可以使用 slotname 访问任何插槽 例如:如果我们想访问,subject slot
那么我们可以使用this.event.request.intent.slots.subject.value