如何在聊天机器人启动后立即显示按钮

How to have a button visible as soon as chatbot starts

我有一个使用 QnA Maker 的机器人框架聊天机器人。该机器人主要用于产品支持常见问题解答类型的问题。我建立了一系列后续提示,允许用户通过出现的按钮导航到不同的 questions/answers。

目前,您必须先输入诸如“我有一个问题”之类的问题才能看到提示,但我会(以某种方式)喜欢特定的提示对(“按问题类型搜索”/“按产品搜索”下图中以红色显示的类别”),以便在对话开始时自动出现,这样用户无需键入任何内容即可看到提示。

我在 Microsoft 机器人中找到了类似行为的真实示例,可以通过单击 this link,然后单击出现在页面右下角。

在这个现实生活中的微软示例中,机器人会自动显示一条消息,然后显示一个显示“开始”的按钮,然后用户会收到一系列提示。我很乐意在我的机器人上有一个“开始”按钮,如果它可以让我的用户进入提示对“按问题类型搜索”/“按产品类别搜索”:

我的机器人(碰巧)有一个“你好,欢迎!”消息(在第一个屏幕截图中以紫色突出显示),它是通过 bot 代码中的 c# 实现的。 [碰巧我对 C# 一点都不熟练]。

我可以在 QnAMaker 中实现我的 objective 吗?还是我必须在 c# 代码中执行某些操作才能显示提示。如果我确实必须走 c# 路线,任何指针都会很棒。

Let's begin with your questions

"Can I achieve my objective just within QnAMaker ? or do I have to do something in the c# code to bring up prompt(s)?"

No you cannot do it only within QnAMaker. You have to write your custom C# bot code.

"If I do have to go down the c# route, any pointers would be great"

As you might know bot conversation started from OnMembersAddedAsync method. so if you want to prompt a button card at the very begining of your conversation you could try something like below:

Starting Point:

protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
        {
            

            foreach (var member in membersAdded)
            {
                if (member.Id != turnContext.Activity.Recipient.Id)
                {
                    var productProactivePromptCardEvening = ProductAndCategoryPromptCard();
                    await turnContext.SendActivityAsync(productProactivePromptCardEvening);

                }
            }
        }

ProductAndCategoryPromptCard:

public IMessageActivity ProductAndCategoryPromptCard()
        {
            try
            {
                //Break in Segment
                var productCategoryInfoCard = Activity.CreateMessageActivity();
                //Bind to Card
                var heroCard = new HeroCard
                {
                    Title = "Try to search using the type of issue, or type of device",
                   
                    Images = new List<CardImage> { new CardImage("") },
                    Buttons = new List<CardAction> {
                        new CardAction(ActionTypes.ImBack, "Search By Issue Type", value: "SearchByIssueType") ,
                        new CardAction(ActionTypes.ImBack, "Search By Product Category", value: "SearchByProductCategory")
                    },
                };

                // Create the attachment.
                var attachment = heroCard.ToAttachment();

                productCategoryInfoCard.Attachments.Add(attachment);
                productCategoryInfoCard.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                return timeInfoCard;
            }
            catch (Exception ex)
            {
                throw new NotImplementedException(ex.Message, ex.InnerException);
            }

        }

Output:

Hope this is what exactly you are loking for. For details project example you could have a look here. You can modify the project with this code.

希望它能相应地满足您的要求