简体   繁体   中英

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

In my agent, I have three intents which requires confirmation.

conversation flow

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.

this is my code

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

need help in having that conversation flow, don't know how to handle these two confirmations.

I also added contexts but it didn't work.

I resolved it by removing the contexts and adding the conditions.

my updated code

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM