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.
I work for Google Cloud, but this post are personal ideas and opinions