You are currently viewing Dialogflow 6 – Using events to trigger intents

Dialogflow 6 – Using events to trigger intents

Hi,

Today’s topic is a short one … we are going to see how to trigger a particular intent using events.

We saw in our first post that events trigger functions, and the particular case of the “Welcome” event that starts all the bots in Google Assistant. Now we are going to see how to define custom intents and how to use them in our fulfillments.

To create a new event we just need to name it in the intent that it will trigger, as you can see here:

This intent doesn’t need training phrases, as it will be triggered from the event, and it will answer with the programmed responses, or a fulfillment, and in this case is also adding an output context that flags that we are finishing the conversation.

The code to call this event is this one, but the relevant one is the last line:

In our Hoteles Martinez demo this code es called when the reservation is for more than 10 days, indicating with the text “ans_nomore10days” that you can’t make reservations for more than 10 days using the assistant … the “cancellation” context has this information and the next fulfillment will use it.

I’m doing it from the next intent because if you call setFollowupEvent, any answer created by agent.add won’t be send to the user.

Easy, right?

Regards,

Jamarmu

============================================================

I work for Google Cloud, but this post are personal ideas and opinions

 

This Post Has 6 Comments

  1. Zeeshan Amanat

    Hi Jmarmu,

    From which function you’re triggering the intent using the ‘FINISH_EVENT” event? Could you please elaborate in more detail?

    1. jamarmu

      Hi,

      The event is called from the main reservation function once a certain criteria is met:

      “In our Hoteles Martinez demo this code is called when the reservation is for more than 10 days, indicating with the text “ans_nomore10days” that you can’t make reservations for more than 10 days using the assistant … the “cancellation” context has this information and the next fulfilment will use it.”

  2. Anurag

    Hi Jamarmu

    I want to understand how can I achieve showing a response text (Response-Text 1) to user (Intent-1), and simultaneously also triggering an event which will show user the next response text (Response-Text 2) after a configured amount of seconds (triggering an event to match Intent-2 configured with that event which will show the next. As per the docs here https://cloud.google.com/dialogflow/docs/events-custom – “When the followupEventInput parameter is set for a WebhookResponse, Dialogflow ignores the fulfillmentText, fulfillmentMessages, and payload fields.” So how can I achieve showing Response-Text 1, and then after 8 seconds Response-Text 2?

    1. jamarmu

      Hi Anurag,

      You are right, you can’t return a message and then jump to another intent, as the message will be ignored.
      To solve this you can provide an answer on the follow up event, but it will require the user to answer something … you would be able to capture this with contexts in order to follow the conversation properly.
      I will create a post with this topic, as I already got this question before and have a solution.

      Javier

  3. Danilo

    Hi Anurag,
    thanks for this.
    +1 on Jamarmu question…

  4. Andrew

    Hi Jamarmu,

    I´m working in a chatbot, and trying to trigger an Event from the fulfillment. I have this code…

    function consultarHorario(agent){
    const hoy = new Date().toLocaleString(“en-US”, {timeZone: “America/Mexico_City”});
    console.log(hoy);
    const hora = hoy.getHours();
    console.log(hora);

    if(hoy < 18){
    console.log("Setting AGENT as follow up event");
    agent.setFollowupEvent('Agente');
    }else{
    console.log("Setting EMAIL as follow up event");
    agent.setFollowupEvent('EMAIL');
    }

    When I make a try, I obtain this error message " .setFollowupEvent is not a function".
    Am I missing something in the code?
    Thanks for your help

Leave a Reply