如何在对话流实现中使用 OR 运算符
How to use OR operator in dialogflow fulfillment
我有一个 4 phone 的列表,我正在使用 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`);
}
});
但是当我 select Phone4 或 Phone3 然后它也返回选项 1 的响应
conv.ask(`${option} is in stock. Do you want to add it to your cart.`);
我是不是做错了什么
请把条件语句改成这个。
if (option === 'Phone1' || option === 'Phone2')
我有一个 4 phone 的列表,我正在使用 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`);
}
});
但是当我 select Phone4 或 Phone3 然后它也返回选项 1 的响应
conv.ask(`${option} is in stock. Do you want to add it to your cart.`);
我是不是做错了什么
请把条件语句改成这个。
if (option === 'Phone1' || option === 'Phone2')