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

标签 javascript node.js aws-lambda alexa alexa-skill

我正在尝试创建 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/

相关文章:

javascript - Google Sheets API Node 客户端库最小示例

node.js - 转发到另一个路由处理程序而不在 Express 中重定向

go - 接收 lambda InvokeInput 的 lambda 的方法签名是什么?

node.js - 仅在 AWS Lambda : ImageMagick Error: Command failed: convert: no decode delegate for this image format 中

javascript - Angular 8 : Pipe to hide past events doesn't work

javascript - 处理缓存 beyong Nginx 服务器和 webpack js 和 css 版本控制

javascript - xmlDoc.getElementsByTagName ("tiles").hasChildNodes 不是一个函数?

node.js - 如何在meteor上远程调试服务器代码?

javascript - 从 php 文件访问 javascript 数组

amazon-web-services - AWS Lambda 设计器未显示函数角色