node.js - 如何在对话流实现中使用 OR 运算符

标签 node.js actions-on-google dialogflow-es-fulfillment

我有 4 部手机的列表,我正在使用 OR 运算符,但它无法正常工作

这是我的代码

app.intent(SHOW_PHONE_INTENT, (conv) => {
  conv.contexts.set(AppContexts.AWAITING_PHONE, 1);
  conv.ask("Here's the list of phone's.");
  conv.ask(new List(PhoneList));
});

app.intent(SELECTED_PHONE_INTENT, (conv, input, option) => {
    const context = conv.contexts.get(AppContexts.AWAITING_PHONE);
    conv.contexts.set(AppContexts1.AWAITING_REPLY, 1, {phone: option});

    if (option === 'Phone1' || 'Phone2'){
      conv.ask(`${option} is in stock. Do you want to add it to your cart.`); 
    } else if (option === 'Phone3'){
      conv.ask(`${option} is out of stock. Would you like to order other products`);
    } else if (option === 'Phone4'){
      conv.ask(`${option} will be launched 1 week later. Would you like to register for this`);
    }
});

但是当我选择 Phone4 或 Phone3 时,它也会返回选项 1 的响应

conv.ask(`${option} is in stock. Do you want to add it to your cart.`);

我是不是做错了什么

最佳答案

请将条件语句更改为此。

if (option === 'Phone1' || option === 'Phone2')

关于node.js - 如何在对话流实现中使用 OR 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60558488/

相关文章:

node.js - 定义异步函数时的 async/await Node v9 "unexpected token function"

firebase - 实时数据库中具有 Dialoglflow 实现的阅读列表

machine-learning - Dialogflow 中的意图限制可以增加吗?

node.js - 在生产中使用 GridFS 在 Node 中下载文件

mysql - Node.JS async/await MySQL 获取插入行的结果

javascript - async.js 的 waterfall 方法在调用 Mongoose 保存方法时挂起

javascript - 无法将 Dialogflow 响应解析为 AppResponse

actions-on-google - 如何从 Google Actions 演示中删除 "Sure, here is the test version of <action name>"?

go - 从自定义客户端终止 Dialogflow 应用程序

dialogflow-es - Dialogflow 响应时间限制可以修改吗?