How to handle user names in Dialogflow? - dialogflow-es

First of all, I'm new to Dialogflow as well as new to coding in general. I'm trying to build a bot that handles subscription pauses.
I have set up some intents and entities for the following steps:
Greet the user and explain what the bot can do
Request a pause for a service subscription (from a pool of ~10
services)
Ask for start time and end time of the pause (two different values)
Sum up the request and repeat the key values
I'm (almost) happy with it but I want to implement a prompt for a username. I don't know if any of the built-in variables can help me here.
That's what I'd like the conversation to look like:
(User): Hi, I would like to pause my subscription for [SUB_NAME] from
[START_DATE] to [END_DATE]
(Assistant): What is your user name for the subscription?
(User): [user_name_123 or UserName123 or USER_NAME] (alphanumeric, not following a certain pattern)
(Assistant): Done. You requested a pause for [SUB_NAME] from [START_DATE] to [END_DATE] for [user_name_123]. Please check your e-mails and confirm your request.
What (I think) I need is a very simple custom variable. In Python I would go for something like this:
user_name = input("What's your user name?")
I'd like to store this as a variable that I can reference with '$'.
Is there any way to do this with Dialogflow?
Also, is it possible to pick up the user name as shown above, i.e. without ML-compatible surrounding sentence structures?
I wouldn't want the conversation to be forcedly repetitive like so:
(Assistant): What's your user name?
(User): My user name is [user_name_123]

If you are using Actions on Google, you can use userStorage to save the username of the user and then later access it to perform tasks ( in your case pausing Subscriptions )
Assuming your intent returns a username, Setting a username in storage is as simple as :
app.intent('ask_username', (conv, params) => {
conv.user.storage.username = params.username; // use $ as conv.user.storage.$ if you want
conv.ask(`Ok, What would I help you with ?.`);
});
Then you can simply access the username as:
conv.user.storage.username
Hope that helps!

You can tag specific words in Dialogflow's training phrases with the type #sys.any, which will be able to grab a part of the input. Then you can grab it as a parameter.
Sys.any is really useful in these types of abstract input types, but will require more training phrases as matching only the username becomes harder.
Instead of using usernames, which don't seem to be authenticated to your service, you may want to look at Google sign-in or OAuth instead. The recommendation above will work, but isn't the best way to do usernames.

Related

How to programattically access parameter prompts in DialogFlow

I have a basic lead gen bot under which I have 2 services (in 2 different intents) for which I am collecting leads. Under both of them I am collecting the name, email, and phone number and I also have checked the required tick boxes.
It's working as expected when I am just availing/submitting lead for a single service. However, if in the same interaction I also want to go for the second service the bot is again asking for the name, email & phone number which it already has from my interaction for the first service. How do I make sure that it doesn't ask for the details if it already has them?
I also do not mind handling it programmatically using fulfillment but I could not find any documentation.
Any help is highly appreciated
you can use the user storage (https://developers.google.com/actions/assistant/save-data)
or alternatively you can try to link the parameters of the two intents to the same context parameters. Set your parameter value like this #context_name.param_name
I was able to do this by setting an output context in the first intent & using the input context in the second intent.
The trick was to assign a default value to the parameters in the second intent as "context_name.param"

How to get data from other intent? (pass data for intents to other intents)

I'm making a actions on google project that will use basic functionality of remembering what the user says and using it for another intent.
So for example, this is what the conversation might look like:
1 User: Hello
2 Bot: Hey! What's your name?
3 User: Joel
4 Bot: Your name is Joel, is that correct?
5 User: Yes that is correct
6 Bot: Awesome, it's great to meet you Joel.
I know how to get the information initially, but I am having trouble with getting the information (the name 'Joel') passed to another intent that is used purely for confirmation.
Here is what I have:
app.intent('greeting', (conv, params) => {
const context = conv.contexts.set('context'); // working good
conv.ask(`I got ${params.name}, is that right?`);
});
app.intent('greeting_1', (conv,params) => {
const context1 = conv.contexts.get('context'); //not working
conv.ask(`Awesome, it's great to meet yoy ${params.name}`);
});
If this helps, specifically the error I'm getting reads:
TypeError: Cannot read property 'userDecision' of undefined
How do I get this to work? I have a feeling I have to save the data in userStorage but I've only really had to do that is very basic cases so I'm not to familiar with that.
Thanks for the help!
First of all, hi!
Your initial thought of storing the data in UserStorage might be correct depending on your use case. Let me elaborate:
Two Ways of Saving Data with Actions On Google Node.JS Client Library
Storing Data In A Conversation
You can use conv.data.name = 'Joel' to save the data between the turns of a conversation. But this data won't be available the next time user comes back.
Storing Data Permanently (As Long As The User Allows It)
This is where userStorage comes into play. You can use conv.user.storage.name = 'Joel' to remember the user's name every time they come back. Keep in mind that this type of permanent storage may require consent from the user depending on where they live.
Legal note: Obtaining consent prior to accessing userStorage. Some
countries have regulations that require developers to obtain consent
from the user before they can access, or save certain information
(e.g. personal information) in the userStorage. If you operate in one
of these countries and you want to access, or save such information in
userStorage, you must use the Confirmation helper to ask consent to
the user and obtain the consent before you can start storing such
information in userStorage.
You also need to explain the data you're saving in your Privacy Policy.
As for you specific use case, storing data that won't change (i.e. name) in userStorage is a much better method. Since if you only save it for one conversation, you'll need to ask for permission again the next time.
These should cover your basic needs of saving data on the platform. However, if you do need a more complex state management solution, you may want to check Dialogflow Contexts.
EDIT: I overlooked that you were already using contexts. But the answer still stands, you don't need to use contexts if all you want to do is to save data during a conversation.
But I think the reason you're having a problem is that you're not setting or getting the context parameters correctly. Take a look at the examples here and here:
The context.set() method gets three parameters; name, lifespan and parameters. You're only passing the name of the context in your code.
And, using only contexts.get() method isn't enough to read parameters of a context. You need to read them like this:
app.intent('Tell Greeting', conv => {
const context1 = conv.contexts.get('context1')
const { color, num } = context1.parameters
})
But, I repeat my original point. You shouldn't make things so complicated for yourself if you don't really need to. Try using conv.data and conv.user.storage if possible.

Google Assistant - how to re-prompt the user with #sys.any when an input is determined to be invalid

I'm trying to create a custom action through Google Assistant. I have custom user data which is defined by the user and I want the user to ask me something about this data, identifying which data they want to know about by supplying it's name.
ex:
User says "Tell me about Fred"
Assistant replies with "Fred is red"
[
{
"name":"Fred",
"info":"Fred is red"
}
]
The problem I'm having is how to add a Training phrases or re-prompting for the user to use when they supply a name which doesn't exist.
ex:
User says "Tell me about Greg"
Assistant replies with "I couldn't find 'Greg'. Who would you like to know about?"
[
{
"name":"Fred",
"info":"Fred is red"
}
]
I've tried adding a Training response which only contains the 'name' parameter, but then if the user says "Tell me about Fred", the "name" parameter is set to "Tell me about Fred" instead of just "Fred", which means it ignores other Training responses I have setup.
Anyone out there who can be my Obi-wan Kenobi?
Edit:
I've used Alexa for this same project and have sent to Alexa an elicitSlot directive. Can something similar be implemented?
There is no real equivalent to an elicitSlot directive in this case (at least not the way I usually see it used), but it does provide several tools for accomplishing what you're trying to do.
The general approach is that, when sending your reply, you also set an Output Context with the reply. You can set as parameters for the Context any information that you want to retain (what value you're prompting for and possibly other state you've already collected).
Then you can have Intents that have this context set as an Input Context. The Intent will then only be matched if the Context is active. This Intent can match #sys.any, or whatever other Entity type might be appropriate in this case.
One advantage of this approach is that it allows for users to reply more conversationally, or pivot their reply away from the prompting question you've just asked. It allows for users to answer within the Context, or through other Intents that you've already setup for other purposes.

Dialogflow inline editor ask for additional info

I am developing a google assistant app on Dialogflow.
And I have a intent that receives two entities: #name and #age
Using the fulfillment throught the inline editor I verify if the #age is below 18.
In that case I need to ask for additional info, I need to ask the name of the person responsible for the child.
I looked around the internet, including the fulfillment samples at https://dialogflow.com/docs/samples
I believe it would look something like this:
let conv = agent.conv();
conv.ask('As your age is under 18 I need the name of the person responsible for you:');
//Some code to retrieve user input into a variable
agent.add(conv);
But I was unable to find how to do it.
Can someone help me to achieve this?
Thanks in advance.
While you are handling an Intent, there is no way to "wait for" the user to respond to your question. Instead, you need to handle user input this way:
You send a response back from your Intent.
The user replies with something they say.
You handle this new user statement through an Intent.
Intents always represent the user taking some action - usually saying something.
So one approach would be to create a new Intent that accepts the user's response. But somehow you need to distinguish this response from the initial Intent that captured the person's name.
One way to do this would be, in the case you ask the question about who the responsible adult is, is to also set a Context. Then you can have a different Intent be triggered only when that Context is set and handle this new Intent to get the name of the adult.

Sending specific words to webhook

I'm trying to make an agent that can give me details about movies.
For example, the user says "Tell me about (movie-name)", which sends a post request to my API with the (movie-name) which then returns the response.
However, I don't understand how to grab the movie name from the user's speech without creating a movieName entity with a list of all the movies out there. I just want to grab the next word the user says after "tell me about" and store it as a parameter. How do I go about achieving that?
Yes, you must create a movieName entity, but you do not need to create a list of all movies. Maybe you are experienced with Alexa which requires a list of suggested values, but in api.ai you don't need to do that.
I find that api.ai is not very good at figuring out which words are part of a free-form entity like movieName, but hopefully adding enough user expressions will help it with that.
edit: the entity I was thinking of is '#sys.any' but maybe it would be better to use a list of movie names with the 'automated expansion' feature. I haven't tried that, but it sounds like the way that Alexa's custom slots work, which is actually a lot more flexible (just using the list as a guideline) then people seem to think.

Resources