Dialogflow - Google Assistant: setFollowupEvent after showing a message

Viewed 2355

Here it is my use case: somewhere in my fulfillment, while handling the Intent A, I want to call Intent B using setFollowupEvent. Something like:

function intentA_Handler(){
    ....
    agent.add('This is the response when calling Intent A');
    agent.setFollowupEvent('call_intent_B_event');
}

function intentB_Handler(){
    agent.add('I am in intent B now.');
    ....
}

What I'm expecting:

  1. The assistant Shows & Speaks out the string This is the response when calling Intent A
  2. Then calling agent.setFollowupEvent('call_intent_B_event'); and Showing & Speaking out the string I am in intent B now.

What happens:

The assistant immediately shows & speaks out to me the string I am in intent B now and omits the first string This is the response when calling Intent A

Already tried:

function intentA_Handler(){
    ....
    new Promise((resolve, reject) => {
        agent.add('This is the response when calling Intent A');
        resolve();
    });

    agent.setFollowupEvent('call_intent_B_event');
}

But still the same result. Any idea how to achieve my goal?

2 Answers

This is the expected behavior. The followup event goes back to Dialogflow and not the Actions on Google platform. The second intent response will go back to the assistant as the only response coming from the agent.

If you use the Actions on Google client library (https://developers.google.com/actions/reference/nodejsv2/overview), the it has a way to pass parameters with the follow up event: https://actions-on-google.github.io/actions-on-google-nodejs/classes/dialogflow.dialogflowconversation.html#followup You could use the parameter values to track additional information you want to include in the final response.

In general - you don't need to use followup events if you are doing things through fulfillment. Remember - Intents usually represent the user doing or saying something, not what you want the reply to be.

If you need to call some code in both the Intent Handler for A and for B - just call that code as another function. If you want to conclude with the same message in both A and B - then you can just call add() with the messages you want in both A and B - either directly or by calling a common function. Perhaps something like this:

function addMessageB(){
    agent.add('This was from adding message B.');
}

function intentA_Handler(){
    ....
    agent.add('This is the response when calling Intent A');
    addMessageB();
}

function intentB_Handler(){
    addMessageB();
    ....
}

There are limitations (you can only add() two Simple Messages, for example), but this would be the general approach.

Related