简体   繁体   中英

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:

  • 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, ie 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]

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM