简体   繁体   English

如何在Dialogflow中处理用户名?

[英]How to handle user names in Dialogflow?

First of all, I'm new to Dialogflow as well as new to coding in general. 首先,我是Dialogflow的新手,也是一般编码的新手。 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) 请求暂停服务订阅(从约10个服务池中)
  • 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] (用户): 您好,我想从[START_DATE]至[END_DATE]暂停对[SUB_NAME]的订阅

(Assistant): What is your user name for the subscription? (助理): 您的订阅用户名是什么?

(User): [user_name_123 or UserName123 or USER_NAME] (alphanumeric, not following a certain pattern) (用户): [user_name_123或UserName123或USER_NAME](字母数字,不遵循特定模式)

(Assistant): Done. (助理): 完成。 You requested a pause for [SUB_NAME] from [START_DATE] to [END_DATE] for [user_name_123]. 您请求[USER_NAME_123]从[START_DATE]到[END_DATE]暂停[SUB_NAME]。 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: 在Python中,我会选择这样的东西:

user_name = input("What's your user name?") user_name = input(“您的用户名是什么?”)

I'd like to store this as a variable that I can reference with '$'. 我想将其存储为一个变量,可以用“ $”引用。 Is there any way to do this with Dialogflow? 有没有办法用Dialogflow做到这一点?

Also, is it possible to pick up the user name as shown above, ie without ML-compatible surrounding sentence structures? 另外,是否有可能获得上述用户名,即没有ML兼容的环绕语句结构? 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] (用户): 我的用户名是 [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. 您可以使用@ sys.any类型在Dialogflow的培训短语中标记特定单词,这将能够捕获部分输入。 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. Sys.any在这些抽象输入类型的类型中确实很有用,但由于仅匹配用户名变得更加困难,因此将需要更多的训练短语。

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. 您可能要查看Google登录或OAuth,而不是使用似乎未通过服务验证的用户名。 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 ) 如果您在Google上使用“操作”,则可以使用userStorage来保存用户的用户名,然后再访问该用户名以执行任务(在您的情况下,暂停“订阅”)

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! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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