как обрабатывать несколько событий подтверждения при выполнении диалогового потока с помощью библиотеки действий на Google - PullRequest
0 голосов
/ 02 мая 2020

В моем агенте у меня есть три намерения, которые требуют подтверждения.

поток разговоров

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

нужна помощь в получении этого поток разговоров, не знаю, как обрабатывать эти два подтверждения.

Я также добавил контексты, но это не сработало.

1 Ответ

0 голосов
/ 05 мая 2020

Я решил это, удалив контексты и добавив условия.

мой обновленный код

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