I want to do something similar to this question: Looping back to an intent?
My bot is telling jokes when a user ask "Tell me a joke", (intent: smalltalk.agent.telljoke) and if the user respond with "another one" I want to send another one.
I understand the answer in the linked question, I can create repeat.smalltalk.agent.telljoke intent if the user say "another one" with a specific input context set in smalltalk.agent.telljoke intent.
But can I trigger my smalltalk.agent.telljoke intent in the repeat.smalltalk.agent.telljoke intent ? I am not calling a webhook to get the jokes so they are in the Responses section of my smalltalk.agent.telljoke intent and I do not want to write them at two places (in both intents).
Can I redirect an intent to another one's responses ?
I asked the same question on the Dialogflow Google forum:
Looping back to an intent without repeat the responses list
To have the input "another one" trigger the joke-telling intent (smalltalk.agent.telljoke), just add "another one" to the training phrases of that intent. There's no need to have two intents if they both do exactly the same thing.
You can do that by adding an output context (let's name it anotherJoke) to your smalltalk.agent.telljoke intent which can expire after two messages (to allow a follow up to a ha ha ha or lol from the user).
Then create a new intent (maybe smalltalk.agent.anotherJoke) that will take the anotherJoke as it's input context.Make this intent recognize another one, shoot again, etc and provide another set of jokes for it.
That way the smalltalk.agent.anotherJoke intent will have priority matching only after the smalltalk.agent.telljoke intent has been triggered, the context kinda links the two intents together.
Related
I'm trying to build a basic "question/answer" app in Actions using DialogFlow. Right now I have two intents:
Intent 1: User says "Ask me a question" and the intent responds "Tell me about yourself"
Intent 2: I'd like to capture the user response to "tell me about yourself", but frankly there's no way to write enough training phrases to cover it.
I tried following this suggestion, and having Intent 1 send an output context called save_response and Intent 2 has an input context of save_response. Then for the training phrase I used #sys.any:save_response
When I try this action, it just invokes the default fallback intent every time. Thoughts on where I might be going wrong?
You need to create 2 intents, in the first intent your training phrase would be Ask me a question, output context will be save_response and response will be the question which you want to throw at the user.
Then in intent 2, you need to do following:
Set input context to save_response, so that it will only be
triggered when this is present in the contexts
Go to actions and parameters section and create a parameter named
answer, give entity type as #sys.any
Then go to training phrases section and add any training phrase, then
highlight it all, and select the parameter you just created
After that, your training phrases and entity section will be looking
like something like below image
Save the intent and you are done
Hope it helps.
In general, having an Intent with a training phrase that consists only of #sys.any may not always work as you expect.
Better would be to have a Fallback Intent that has the Input Context set to make sure you only capture things in that state (save_response in your case) and then to use the full text captured in your fulfillment.
When doing it this way, you do not need the "Intent 2" you described - or rather, this would be a Fallback Intent that you create in the Dialogflow UI. The Fallback Intent is triggered if no other Intent would match what the user has said.
To create a Fallback Intent, select the three dots in the upper right of the Dialogflow UI
then select "Create Fallback Intent"
The Fallback Intent editor is very similar to the normal Intent editor. The biggest difference is that the phrases you enter (and you don't need to enter any) will explicitly not match this Intent, and there are no parameters. Other aspects (the name, the Incoming Context, turning on fulfillment) are the same.
Can Follow-up intent has more than 1 parent?
For example, my program will be like
from(A)
if(A.response == yes){
go_to_intent(B)
go_to_intent(C) //A-->B-->C
}
else
go_to_intent_(C) //A-->C
which can be seen that both B and A are the possible parents of C.
So how to set C as the follow-up intent of both A and B?
In short - no. You're not supposed to "go to" Intents - Intents represent user inputs under different conditions.
So Using your example, the user has said or done something that matches Intent A. As a response, your agent asks a question.
If they answer "yes", then it should match Intent B.
If not, then it will match Intent C.
Now... what you do in your webhook fulfillment in Intents A, B, and C is a completely different story. You're allowed to call the same functions for B and C and just return different messages from each.
Intents aren't about what your agent does - it is about what your user does.
Update
Based on your example in the comments, I want to repeat - don't think of Intents as what your agent is saying, think of it as what the user is saying or doing.
Based on this, I would rephrase your Intents this way:
When the user starts the action, this triggers Intent A. In the handler for Intent A:
Set the context "ask-city"
Send the message "Do you want to provide the city?"
When the context "ask-city" is active, and the user says "yes", trigger Intent B. In the handler for Intent B:
Clear the context "ask-city"
Set the context "prompt-city"
Send the message "What city?"
When the context "ask-city" is active, the user may also just reply with the city, so trigger Intent B1. In the handler for Intent B1:
Clear the context "ask-city"
Save the city information
Set the context "prompt-gender"
Send the message "What is your gender?"
When the context "ask-city" is active, the user may reply "no", so trigger Intent C. In the handler for Intent C:
Clear the context "ask-city"
Save that there is no city information
Set the context "prompt-gender"
Send the message "What is your gender?"
When the context "prompt-city" is active, and the user says a city name, trigger Intent C1. In the handler for Intent C1:
Clear the context "prompt-city"
Save the city information
Set the context "prompt-gender"
Send the message "What is your gender?"
You notice that Intents B1, C, and C1 all have very similar, but not identical, fulfillments. So in your webhook, they can all essentially call the same (or similar) code. But you notice that they're triggered under slightly different conditions, so each one needs a different Dialogflow Intent.
I added Intent B1 because this may very well be how the user responds to you. In a conversational UI, we're not presenting them with a phone menu - they can respond as if they were responding to another human asking the same question.
Also keep in mind that there may be other Intents that you want to build that are handled differently in each state. For example, when the "ask-city" context is valid, if the user says something besides "yes", "no", or a city, you may want to clarify what you're asking.
Also note that none of these are, technically, Followup Intents. Followup Intents are just some visual coating around Contexts. You never need to use a Followup Intent - they just make some, very specific, things better organized. In your case - they also cause problems. If all you accept in a followup is "yes" and "no", then the user saying other things aren't allowed and you end up with a much more stilted conversation. The important part about each case isn't if they're followups or not - they're the ability to set an output context and that Intents will only be triggered on those contexts being specified as input contexts.
Consider a scenario where user wants to order a meal :
User : I would like to order 1 burger 1 orange juice and one coffee
Bot : Would you like to have a veg burger or a non-veg one?
User: A veg burger
User: Sorry, I would like it to be non-veg
Bot: (Generally how would we handle this change of mind without having to start the conversation from scratch) ?
In this part where I've been implementing something like a bus ticket booking, this the bot seems to remember the previous order that is veg-burger or some how ends up falling on to default intent or fallback intent whichever is suitable. But I would like to know if there is a way for letting the bot know that the user has "Changed the mind" (Hopefully it is possible using or manipulating the context) and wants a non-veg burger now?
Can we work out an followup intent recognizing words like Sorry and then entity such as type i.e. non-veg here. What is the best practice? Because starting the conversation from scratch doesn't seem to be a good idea from UX point of view.
Good day TGW,
You have 2 options, either you split your intents into a search intent and book intent e.g. search.salad and buy.salad intents OR you have a confirmation step before you actually send to Fulfilment.
If you choose to split your intents into 2 then a similar flow should work for you:
If the food type is finite then create an entity with the options.
Add your search.salad intent that should have most of what the users will say to order a salad. Remember to incoporate the entity from step 1.
Add a followup intent to your search.salad Intent, and select custom from the options.
In this newly created followup Intent add the User says that you want to use to update the search, enable fulfilment and save.
NB: Ensure the newly created intent has an intent that ends with *-followup in the In-context and this same intent is in the Out-context of the search.salad intent. Dialogflow will automatically update the parameters for you based on what the user enters.
The second option is similar to this, you can add your confirmation step as a followup to the search.salad intent and enable fulfilment only on the confirmation intent.
I have one intent named "search.category" which has user queries like "32gb phones" and it has a follow up intent to get_brand question like "do you have any specific brand? ".
This can have two type of answers that user can enter brand name or he can say "I don't know."
Is there any way to pass the whole user query in main intent to followup intents.
How can we pass the original user query(32gb phones) as a parameter across the intents?
In the second picture, you can see that two entities are selected, so is there any way to select the other text from user query ( I want the "show me some under 40000")
To do this, you would create a new Output Context on the first intent. Output contexts created as part of an intent contain the parameters that were set by the user when they were created and are available in subsequent intents (for as long as their lifespan is active). You can access the context's parameters either in the response or in your fulfillment webhook.
If you're trying to use values that aren't set in the parameters, then in the fulfillment of the original intent you can set any value you want as a parameter of an Output Context that you create in your webhook.
I want to do some thing like this with api.ai. I am doing it as a telegram bot.
1st question: Tell me a joke?
Bot: Tells a joke ( picks it from text response that I specified )
2nd input from user: Some more.
Bot: It should tell another joke from the same list of responses.
One thing I could do is include MORE as a user input is joke intent and it would pick a response.
But I can not do this, because then even without asking 1st question if I give "more" as input it would pick a response from the list. Basically that wouldn't pick response based on context.
Any help onn the structure I should be using on api.ai to achieve something like this.
So the first intent where the user asks "tell me a joke?" sets an outgoing context- 'jokes'.
Follow-up intents for telling more jokes have 'jokes' for the incoming context, and, if you want to chain repeatable requests, set the outgoing context as 'jokes' as well.
If the user input like "tell me more" outside the 'jokes' context is still triggering the followup intent, either train your bot to recognize the difference, or create an explicit "tell me more" example in a fallback intent outside the jokes context.