如何在聊天机器人中为用户提供多种选择 [英] How to give user multiple options to chose from in chat bot

查看:82
本文介绍了如何在聊天机器人中为用户提供多种选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给用户多个选项供选择并显示英雄卡片进行回复。

我在我的代码中使用了一个简单的附件,但它不起作用。



我尝试了什么:



I want to give user multiple options to chose from and show hero cards for reply.
I used a simple attachment in my code here but it doesn't work.

What I have tried:

[LuisIntent("help")]
public async Task help(IDialogContext context,LuisResult result)
{
    List<string> opt = new List<string>();
    opt.Add("1. reply to your greetings");
    opt.Add(" 2.Ask me my name");
    opt.Add("3.ask my height");
   PromptOptions<string> option = new PromptOptions<string>("Please select the number", "Sorry i didn't got you, can you try that again", "Please select from the given options",opt, 3);
    PromptDialog.Choice<string>(context, helpasync,option);
    context.Wait(MessageReceived);
}

private async Task helpasync(IDialogContext context, IAwaitable<string> result)
{
    string choice = await result;
    switch (choice)
    {
        case "1":

            var activity = new Activity();
            var markdownContent = "#A heading\n";
            markdownContent += "##A subheading\n";
            markdownContent += "**something bold**\n\n";
            markdownContent += "*something italic*\n\n";
            markdownContent += "[a link!](http://robinosborne.co.uk/?s=bot)\n\n";
            markdownContent += "![AN IMAGE!](http://robinosborne.co.uk/wp-content/uploads/2016/07/robinosborne.jpg)\n";
            markdownContent += "> A quote of something interesting\n\n";
            markdownContent += "```\nvar this = \"code\";\n```\n";

            Activity reply = activity.CreateReply(markdownContent);
            break;
        case "2":         
            break;
        case "3":
            break;
        default:
           break;
    }

推荐答案

Quote:

我在我的代码中使用了一个简单的附件,但它不起作用。

i used a simple attachment in my code here but it doesn't work.



使用断点来查看例程是否被触发并检查是否 choice 是你所期望的。



当你不明白你的代码在做什么或为什么它做它做的时候,答案是 debugger

使用调试器查看代码正在执行的操作。只需设置断点并查看代码执行情况,调试器允许您逐行执行第1行并在执行时检查变量,这是一个令人难以置信的学习工具。



调试器 - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]

使用Visual Studio 2010进行基本调试 - YouTube [ ^ ]



调试器在这里向您展示您的代码在做什么你的任务是与它应该做的事情进行比较。

调试器中没有魔法,它没有发现错误,它只是帮助你。当代码没有达到预期的效果时,你就会接近一个错误。


Use breakpoint to see if routine is fired and to check if choice is what you expect.

When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.


这篇关于如何在聊天机器人中为用户提供多种选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆