对话框流从列表中选择 [英] Dialogflow selecting from list
问题描述
我正在创建一个聊天机器人,模仿通话中的ivr。因此,例如,当用户打个招呼(欢迎意图)时,我发送一条消息,例如,请从下面选择一个选项。
I am creating a chat bot which mimic the ivr in call. So for example when user say hi (welcome intent) I send a message like please select an option from below.
1, 2, 3, 4, 5 (every option gives user a unique information)
然后我创建欢迎意图的后续意图,如默认欢迎意图select.number
then I create a follow up intent of welcome intent as Default welcome intent select.number
在这种情况下,当用户键入2时,我会给他另一组选项。
从下面选择选项
in this situation when user type 2 I give him another set of options. choose the option from below
a, b, c, d, e, f
现在,例如用户类型 a
我需要在dialogflow上创建什么意图进一步处理。
Now for e.g user type a
what intent I need to create on dialogflow to process further.
我正在使用我的python脚本拦截用户答复
I am intercepting the user reply using my python script
并从python脚本调用dialogflow。
and calling dialogflow from python script.
reply, intent, parameter = fetch_reply(x, session_id)
def fetch_reply(query, session_id):
response = detect_intent_from_text(query, session_id)
inetnt = response.intent.display_name
# print(inetnt)
# print('-----')
value = 0.0
try:
if response.parameters['number']:
value = response.parameters['number'][0]
except ValueError:
print('no value found')
return response.fulfillment_text, inetnt, value
在这里,如果用户选择<$ c,我可以简单地使用 if $ c> a
,然后向他发送答复,但是dialogflow是否提供了我可以用来为用户输入提供答案的任何内容。
From here I can simply use if else
if user select a
and then send him reply but is there anything that dialogflow provide which can I use to give answers to user inputs.
还有一个供用户选择的选项,例如按0返回主菜单。
如何处理?
Also there is a option for user like press 0 to go back to main menu. How can I handle it?
如果您希望我提供任何其他信息,请告诉我。
If you want me to provide any other info please let me know.
推荐答案
一种可能的方法是为每个可能的选项{1、2、3 ..a,b,c}创建Intent,并在每次回复后将它们作为建议包括在内。例如,当用户说嗨时,您可以选择1,2,3 ...作为 Hello来回答。当用户选择1时,a,b,c ...会显示为建议。以下代码可以提供帮助:
One possible way is to create Intent for each possible options {1, 2, 3 ..a, b, c} and include them in as Suggestion after each reply. For example, when the user says "Hi" you can respond as "Hello" with 1, 2, 3 ... as selectable suggestions. And when user selects 1 then a, b, c... appear as Suggestions. Here's some code that can help:
.
.
.
const {Card, Suggestion} = require('dialogflow-fulfillment');
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({request, response });
function welcome(agent){
agent.add(`Hello!`);
agent.add(new Suggestion(`1`));
agent.add(new Suggestion(`2`));
agent.add(new Suggestion(`3`));
}
.
.
.
这篇关于对话框流从列表中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!