Custom fallback intents when using confirmation helper

情到浓时终转凉″ 提交于 2019-12-11 03:07:08

问题


I'm trying to create custom fallbacks for intents that contain confirmations. Here is the code:

const functions = require('firebase-functions');
const {
    dialogflow,
    Confirmation
} = require('actions-on-google');


const app = dialogflow({
    debug: true,
});

app.intent('vitals-confirmation', (conv, input, confirmation) => {
    conv.ask(new Confirmation(`Great! Have you fainted recently?`));
});

app.intent('vitals-confirmation-fallback', (conv, input, confirmation) => {
    conv.ask(new Confirmation(`Sorry I didn't understand what you said. Did you faint?`));
})

app.intent('S1-confirmation', (conv, input, confirmation) => {
    if (confirmation) {
        conv.ask(new Confirmation(`I have recorded that you have fainted. Have your feet been hurting?`));
    } else {
        conv.ask(new Confirmation(`I have recorded that you have not fainted. Have your feet been hurting?`));
    }
});

My app asks the user if they have fainted in "vitals-confirmation" and the user is expected to answer with a yes or no type answer that will be identified by the confirmation helper, if they do this correctly they will go to "S1-confirmation" and will be asked the next question.

However the following is outputted when I respond with an answer that is not a yes/no type answer (for example: "red"):

Sorry, Great! Have you fainted recently?

It seems as though there is a default fallback that responds with "Sorry, [repeats previous text output]" and does not go to a custom fallback intent which I have created (which is my desired result).


回答1:


Take a look at the documentation for Confirmation helper of Actions SDK for Node.js.

You have to setup an intent with the actions_intent_CONFIRMATION event in DialogFlow in order to retrieve the user response. My advice is to check how you configured your intents and use this method, otherwise be sure to create the follow-up intents with the desired context lifespan.

Example from documentation:

app.intent('Default Welcome Intent', conv => {
  conv.ask(new Confirmation('Are you sure you want to do that?'))
})

// Create a Dialogflow intent with the `actions_intent_CONFIRMATION` event
app.intent('Get Confirmation', (conv, input, confirmation) => {
  if (confirmation) {
    conv.close(`Great! I'm glad you want to do it!`)
  } else {
    conv.close(`That's okay. Let's not do it now.`)
  }
})


来源:https://stackoverflow.com/questions/54064240/custom-fallback-intents-when-using-confirmation-helper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!