首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用actions-on-google库处理对话流实现中的多个确认事件

如何使用actions-on-google库处理对话流实现中的多个确认事件
EN

Stack Overflow用户
提问于 2020-05-02 22:06:55
回答 1查看 88关注 0票数 0

在我的代理中,我有三个需要确认的意图。

会话流程

代码语言:javascript
复制
user: my number is 000-000-0000
bot: is number 000-000-0000 correct, please confirm?
user: yes
bot: got your number, is your ${location.address} is correct, please confirm?
user: yes
bot: great got your number and address.

这是我的代码

代码语言:javascript
复制
app.intent('CustomerNumberIntent', (conv, parameters) => {
        if (conv.user.storage.serviceType === 'Take Away') {
        conv.ask(new Confirmation(`Is ${customerNumber} is correct number?`));
        } else {
        conv.close(`There might be some issue please try again!`);
        }
});

app.intent('CustomerNumberConfirmationIntent', (conv, parameters, confirmationGranted) => {
    if (confirmationGranted){
      conv.contexts.set(AppContextsDefaultAddConfirm.AWAITING_DEFAULT_ADDRESS_CONFIRMATION, 1);
      conv.ask(new Confirmation(`You want delivery at ${defaultAddress}. Is that right?`));
    } else {
      conv.ask(`Tell me the correct contact number?`);
    }
});

app.intent('CustomerAddressConfirmationIntent', (conv, parameters, confirmationGranted) => {
  const contexDefaultAddConfirm = conv.contexts.get(AppContextsDefaultAddConfirm.AWAITING_DEFAULT_ADDRESS_CONFIRMATION);
  const contexUserAddConfirm = conv.contexts.get(AppContextsUserAddConfirm.AWAITING_USER_ADDRESS_CONFIRMATION);
    if (confirmationGranted){
      conv.close(`Great! I got your number and address.`);
    } else {
      conv.ask(`Where to deliver your order?`);
    }
});

app.intent('CustomerAddressIntent', (conv, parameters) => {
  conv.contexts.set(AppContextsUserAddressConfirmation.AWAITING_USER_ADDRESS_CONFIRMATION, 1);
  const deliveryAddress = parameters.deliveryAddress;
    if (conv.user.storage.serviceType === 'Home Delivery'){
        conv.ask(new Confirmation(`Your delivery address is ${deliveryAddress}, please confirm?`));
    } else {
        conv.close(`There might be some issue please try again!`);
    }
});

需要帮助才能让对话流畅,不知道如何处理这两个确认。

我还添加了上下文,但它不起作用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-05 16:54:50

我通过删除上下文并添加条件解决了这个问题。

我更新的代码

代码语言:javascript
复制
app.intent('CustomerNumberIntent', (conv, parameters) => {
        if (conv.user.storage.serviceType === 'Take Away') {
        conv.ask(new Confirmation(`Is ${customerNumber} is correct number?`));
        } else {
        conv.close(`There might be some issue please try again!`);
        }
});

app.intent('CustomerNumberConfirmationIntent', (conv, parameters, confirmationGranted) => {
    if (confirmationGranted && !conv.user.storage.customerNumber){
      conv.data.customerNumber = customerNumber;
      conv.user.storage.customerNumber = conv.data.customerNumber;
      conv.ask(new Confirmation(`Your delivery address is ${conv.user.storage.address}. Is that right?`));

    } else if (confirmationGranted && conv.user.storage.customerNumber){
      conv.ask(`Great! your order is placed`);

    } else if (!confirmationGranted && !conv.user.storage.customerNumber){
      conv.ask(`Please tell me the correct number?`);

    } else if (!confirmationGranted && conv.user.storage.customerNumber){
      conv.ask(`Please tell me where to deliver your order?`); 
    }
});

app.intent('CustomerAddressIntent', (conv, parameters) => {
    if (conv.user.storage.serviceType === 'Take Away'){
        conv.ask(new Confirmation(`Your delivery address is ${deliveryAddress}, please confirm?`));
    } else {
        conv.close(`There might be some issue please try again!`);
    }
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61560659

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档