acxcv
acxcv

Reputation: 73

How to handle user names in Dialogflow?

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:

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]

Upvotes: 0

Views: 2471

Answers (2)

Nick Felker
Nick Felker

Reputation: 11968

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.

Upvotes: 1

Sairaj Sawant
Sairaj Sawant

Reputation: 1842

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!

Upvotes: 1

Related Questions