如何使用 actions-on-google 库处理 dialogflow fulfillment 中的多个确认事件

how to handle multiple confirmation events in dialogflow fulfillment using actions-on-google library

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

对话流程

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.

这是我的代码

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!`);
    }
});

需要帮助进行对话,不知道如何处理这两个确认。

我也添加了上下文,但没有用。

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

我更新的代码

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!`);
    }
});