Reputation: 3365
I have a DialogFlow intent follow up that I'm having a hard time with. It's the only follow up to my main intent, and the issue I'm having is that when
the incidents.data
array is empty it doesn't trigger the conv.ask
statement in the else case and causes DialogFlow to throw an empty speech response error. The code looks something like this:
app.intent('metro_timetable - yes', async (conv: any) => {
const incidents = await serviceIncidents.getIncidents();
if (incidents.data.length > 0) {
conv.ask('I have incidents')
} else {
conv.ask(
`I wasn't able to understand your request, could you please say that again?`
);
}
});
incidents.data
gets stored in the global scope, and is set deep within
the metro_timetable
intent. It stores an incident for the follow up. Because all yes
responses trigger the follow up I setup an else case so it catches it if someone says yes
when metro_timetable
doesn't understand their original request and asks them to repeat it. If incidents.data
actually has information to share the dialog triggers correctly and I have incidents
is correctly read to the user.
In DialogFlow it looks something like this. Where am I going wrong here?
Upvotes: 1
Views: 510
Reputation: 50731
Your description is a little convoluted how incidents.data
actually gets set, but it sounds possible that instead of it being set to an empty array, it isn't set at all. In this case, I suspect that the following happened:
incidents.data
would be undefinedincidents.data.length
would cause an errorYou can probably solve this by doing a test such as (for example)
incidents && incidents.data && incidents.data.length > 0
Your other issue, however, seems to be that you have a Followup Intent set for a scenario where you don't actually want that as the followup. This is one of the reasons you probably shouldn't use Followup Intents but, instead, only set a context when you send a response where that context would make sense, and look for the "Yes" response in the context you define. Then, when metro_timetable
doesn't understand the request, you don't set the context and you give an error.
To do this, you would remove the automatically generated metro_timetable-followup
context from the two Intents. You'll create your own context, which I'll name timetable
for purposes of this example.
In the fulfillment for the metro_timetable
Intent, if you respond with something that needs confirmation (ie - when "yes" will be something the user says), you would set the timetable
context with something like
conv.contexts.set('timetable',2);
conv.ask('Are you sure?');
You can then create an Intent that checks for timetable
as the Incoming Context and has training phrases that are equivalent to "yes". In that Intent, you'd do what you need to and respond.
Upvotes: 1