如何在Alexa Skills中动态设置插槽值



我正在尝试制作我自己的Alexa技能,我有一个Intent,需要填充两个槽才能返回响应,第一个槽是DATE,所以我没有任何问题,第二个槽是列表中的名称,该名称列表对于将使用我的技能的每个用户是不同的,因此在我自己的服务器中我具有API;名称";目前,它是所有测试的默认值,返回值是一个JSON,根据ID和值如下的实体的文档进行格式化:

(这是从我的API返回的实时JSON(

[
{
"type": "Dialog.UpdateDynamicEntities",
"updateBehavior": "REPLACE",
"types": [
{
"name": "PuntoVenditaType",
"values": [
{
"id": "0",
"name": {
"value": "PC-STEVE"
}
},
{
"id": "1",
"name": {
"value": "GINESI - NUOVO"
}
},
{
"id": "4",
"name": {
"value": "IGOR"
}
},
{
"id": "10",
"name": {
"value": "TELEX - SELF"
}
}
]
}
]
}
]

下面是我从LaunchRequest委托的意向:

const LaunchRequestHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
},
handle(handlerInput) {
const speakOutput = 'XXX.';
return handlerInput.responseBuilder
.speak(speakOutput)
.addDelegateDirective({
name: 'IncassoIntent',
confirmationStatus: 'NONE',
slots: {}
})
.getResponse();
}
};
const IncassoIntent = {
canHandle(handlerInput) {
return (
Alexa.getRequestType(handlerInput.requestEnvelope) === "IntentRequest"
&& Alexa.getIntentName(handlerInput.requestEnvelope) === "IncassoIntent"
);
},
async handle(handlerInput) {
const {requestEnvelope, responseBuilder} = handlerInput;
const {intent} = requestEnvelope.request;
console.log(intent)

let speech = "XXX"

const replaceEntityDirective = await getPuntiVendita();
console.log(replaceEntityDirective)
if (intent.confirmationStatus === 'CONFIRMED') {
const date = Alexa.getSlotValue(requestEnvelope, 'date');
const puntoVendita = Alexa.getSlotValue(requestEnvelope, 'puntoVendita');
speech = handlerInput.t('XXX {{date}} XXX {{puntoVendita}} XXX', {date, puntoVendita})
}else {
const repeat = handlerInput.t('XXX?')
responseBuilder.reprompt(repeat)
}
return handlerInput.responseBuilder
.speak(speech)
.addDirective(replaceEntityDirective)
.getResponse();
},
};
function getPuntiVendita() {
return new Promise(((resolve, reject) => {
var options = {
host: 'www.example.cloud',
port: 443,
path: '/api/alexa/negozi',
method: 'GET',
};
const request = https.request(options, (response) => {
let returnData = '';
response.on('data', (chunk) => {
returnData += chunk;
});

response.on('end', () => {
resolve(JSON.parse(returnData));
});

response.on('error', (error) => {
console.log(error)
reject(error);
});
});
request.end();
}));
}

因此,tipoNegozio应该只接受从我的API返回的数据,但它接受任何值。。。

您正在寻找此处描述的动态实体:https://developer.amazon.com/en-US/docs/alexa/custom-skills/use-dynamic-entities-for-customized-interactions.html

如果您没有使用Node或Java库,则必须指定它们在以前某个调用发送的响应模型中讨论的指令。此处对此进行了描述:https://developer.amazon.com/en-US/docs/alexa/custom-skills/request-and-response-json-reference.html

最新更新