2017-02-06 1 views
1

Ich habe kürzlich einen Chatbot mit Microsoft Botframework entwickelt. Ich benutze prompt.confirm, um die Ja/Nein-Eingabe des Benutzers zu nehmen, aber es zeigt zu viele Versuche, Ausnahme, wenn ich Basic Ja/Nein schreibe. Ich möchte nicht, dass mein Bot zu viele Versuche ausgibt Ausnahme, stattdessen möchte ich es intern behandeln. Hier ist mein Code.C# BotFramework Prompt.Confirm zeigt zu viele Versuche an Ausnahme

[LuisIntent("None")] 
public async Task NoneIntent(IDialogContext context, LuisResult result) 
{ 
    try 
    { 
     PromptDialog.Confirm(context, NextQuestionAsync, QuestionPrompt, attempts: 1, promptStyle: PromptStyle.Auto); 
    } 
    catch (Exception ex) 
    { 
     await context.PostAsync("Something really bad happened."); 
    } 
} 

public async Task NextQuestionAsync(IDialogContext context, IAwaitable<bool> result) 
{ 
    try 
    { 
     if (await result) 
     { 
      await context.PostAsync($"Ok, alarm 0 disabled."); 
      //context.Wait(NoneIntent); 
     } 
     else 
     { 
      await context.PostAsync("You Said No"); 
     } 
    } 
    catch (Exception e) 
    { 

    } 
} 
+0

https://github.com/Microsoft/BotBuilder/issues/1757 – stuartd

Antwort

2

Ich löste dieses Problem durch Überschreiben des PromptOptions-Konstruktors, Dank ezequiel. Ich habe PromptDialog.Choice benutzt, um es zu erreichen, aber ich hätte es auch mit bestätigen können. Hier ist, was ich tat

List<string> questions = new List<string>(); 
    questions.Add("Yes"); // Added yes option to prompt 
    questions.Add("No"); // Added no option to prompt 
    string QuestionPrompt = "Are you sure?"; 
    PromptOptions<string> options = new PromptOptions<string>(QuestionPrompt, "", "", questions, 1); // Overrided the PromptOptions Constructor. 
    PromptDialog.Choice<string>(context, NextQuestionAsync, options); 
+0

PromptConfirm ist besser für die Ja/Nein-Frage. Das ist eine Art Duplikat meiner Antwort. Und Sie überschreiben nicht den Konstruktor; das ist eine falsche Aussage. –

+0

Sicher ... dasselbe Muster, das du in anderen Fragen gemacht hast. Vergiss es –

3

können Sie außer Kraft setzen nur die TooManyAttempts Nachricht von Ihrem eigenen String in der PromptOptions constructor vorbei, die später here die Nachricht anzuzeigen verwendet wird. im Auge

Auch hat, dass die Art und Weise in dem Fall der TooManyAttempts Ausnahme zu handhaben es in der try/catch der ResumeAfter Methode (in diesem Fall Ihrer NextQuestionAsync-Methode) ist, die await und nicht in dem Anrufer Umgebung Methode.

Verwandte Themen