In DialogFlow, we can trigger functions and perform tasks based on either Intent Name or Actions.
Which one should we use to decide? What is better practice?
An intent categorizes an end-user's intention for one conversation turn. For each agent, you define many intents, where your combined intents can handle a complete conversation.
A follow-up intent is a child of its associated parent intent. When you create a follow-up intent, an output context is automatically added to the parent intent and an input context of the same name is added to the follow-up intent.
I've asked a similar question in the past and have experimented with both the function-by-intent and function-by-action patterns, and I have come to view the actions as almost completely useless. Their only benefit seems to be that you can attach the same action to multiple intents, but if anything I would want to have the same intent be handled by multiple functions, based on the specific contexts and parameters. This originates from a design goal of rather having fewer multi-purpose intents than a lot of simpler ones, though the latter pattern is arguably the one implied by many of the Google docs.
Conceptually I think it is useful to think of the fulfillment functions as the transition functions of a finite state machine, where the state is defined by the incoming webhook request, i.e. a tuple of (intent, contexts, parameters, event)
plus maybe other metadata such as locale and surface capabilities. I haven't found the actions to add anything to this model.
In most cases, it won't matter. The approach that @gmolau describes is a good one, and I think they're pretty much spot on.
Certainly the documentation is increasingly going towards using Intent Name for everything rather than Action.
The case where I think it makes the most sense to use the action name instead of an Intent name is when you have different Intents that may respond to the same phrase, and ultimately do the same thing, but only in certain contexts. This lets you do the logic for what gets called on the Dialogflow side and not have to register the same Handler against multiple Intents.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With