Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
549 views
in Technique[技术] by (71.8m points)

c# - How do I cancel/exit or escape from PromptDialog.Choice in Bot Framework?

The PromptDialog.Choice in the Bot Framework display the choice list which is working well. However, I would like to have an option to cancel/escape/exit the dialog with giving cancel/escape/exit optioin in the list. Is there anything in PromptDialog.Choice which can be overridden since i have not found any cancel option.

here is my code in c#..

PromptDialog.Choice(
                 context: context,
                 resume: ChoiceSelectAsync,
                 options: getSoftwareList(softwareItem),
                 prompt: "We have the following software items matching " + softwareItem + ". (1), (2), (3). Which one do you want?:",
                 retry: "I didn't understand. Please try again.",
                 promptStyle: PromptStyle.PerLine);

Example:

Bot: We have the following software items matching Photoshop. (1), (2), (3). Which one do you want

  • Version 1
  • Version 2
  • Version 3

What I want if user enter none of above or a command or number, cancel, exit, that bypasses the options above, without triggering the retry error message.

How do we do that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are two ways of achieving this:

  1. Add cancel as an option as suggested. While this would definitely work, long term you will find repeating yourself a lot, plus that you will see the cancel option in the list of choices, what may not be desired.
  2. A better approach would be to extend the current PromptChoice to add your exit/cancelation logic. The good news is that there is something already implemented that you could use as is or as the base to achieve your needs. Take a look to the CancelablePromptChoice included in the BotBuilder-Samples repository. Here is how to use it.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...