gpt4 book ai didi

javascript - 为什么我的代码没有在 Alexa Development Console 模拟器上运行 if 语句,即使我说出/键入插槽中存在的值也是如此?

转载 作者:行者123 更新时间:2023-11-30 06:14:18 24 4
gpt4 key购买 nike

我正在尝试创建 Alexa 技能,但遇到了障碍。我编写/编辑了 AWS Lambda 代码并尝试对其进行测试。现在,我添加了“奥利奥蛋糕”作为我的插槽值之一。当我说出/输入 oreo cake 时,出于某种原因,应该运行的 if 语句没有运行。相反,运行 else 语句。

const GetPrice_Handler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'GetPrice';
},
handle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
const responseBuilder = handlerInput.responseBuilder;
let sessionAttributes = handlerInput.attributesManager.getSessionAttributes();

let slotStatus = '';
let resolvedSlot;
let say = '';

let slotValues = getSlotValues(request.intent.slots);
// getSlotValues returns .heardAs, .resolved, and .isValidated for each slot,
// according to request slot status codes ER_SUCCESS_MATCH, ER_SUCCESS_NO_MATCH,
// or traditional simple request slot without resolutions
if (slotValues == slotValues.cake) {
say = `The price of ${slotValues.cake.heardAs} is 800 Indian Rupees. `;
} else {
say = 'Sorry, I didnt catch that. Could you please repeat that again? ';
}

最佳答案

我可能错了,但你不能像这样做你的 if 语句吗:

if (slotValues.cake)

基本上,如果 .cake 为真,即如果 slotValues 包含 .cake 对象中的任何值,它应该运行 IF 语句吗?

关于javascript - 为什么我的代码没有在 Alexa Development Console 模拟器上运行 if 语句,即使我说出/键入插槽中存在的值也是如此?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57159594/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com