2017-05-02 1 views
1

Ich erhalte eine ungültige Type-Ausnahme, wenn Sie versuchen, PromptDialog.Choice zu verwenden. Hier ist mein Code aus auf meiner Dialoge:PromptDialog.Choice - Ungültiger Typ Ausnahme

public async Task StartAsync(IDialogContext context) { 
    await context.PostAsync(ConversationHelper.CreateReschedulePromptMessage()); 
    context.Wait(MessageReceivedAsync); 
} 

public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result) { 
    var message = await result; 
    var Options = new[] { "Location", "Date and Time", "Both" }; 

    if (message.Text.ToUpper().CompareTo("PICKUP") == 0) { 
    _rescheduleType = "pickup"; 
    string prompt = string.Format("Is the {0} location incorrect, is the date and time incorrect, or both?", _rescheduleType); 
    PromptDialog.Choice(context, OnResumeFromRescheduleChoice, Options, prompt, promptStyle: PromptStyle.Auto, descriptions: Options); 
    } 
    else if (message.Text.ToUpper().CompareTo("DROP") == 0) { 
    _rescheduleType = "drop-off"; 
    string prompt = string.Format("Is the {0} location incorrect, is the date and time incorrect, or both?", _rescheduleType); 
    PromptDialog.Choice(context, OnResumeFromRescheduleChoice, Options, prompt, promptStyle: PromptStyle.Auto, descriptions: Options); 
    } 
    else { 
    await context.PostAsync(ConversationHelper.CreateGenericRescheduleMessage(SUPPORTNUMBER)); 
    } 

    context.Done<object>(null); 
} 

private async Task OnResumeFromRescheduleChoice(IDialogContext context, IAwaitable<string> result) { 
    var choice = await result; 
} 

Die OnResumeFromRescheduleChoice Methode feuert, aber das Ergebnis zeigt fehlgeschlagen, da der ResumeAfter Delegat Typ string erwartet, aber Objekt empfängt. Ist das eine falsche Verwendung des PromptDialogs? Außerdem werden dem Benutzer die Auswahlmöglichkeiten nicht angezeigt. Ich benutze Bot.Builder Version 3.5.5.

+0

Ist der context.Done (null) Anruf zu früh geschehen? –

Antwort

1

Verschieben Sie den context.Done<object>(null); Aufruf innerhalb der else Klausel. Sie können context.Done nicht anrufen, nachdem Sie eine Prompt ausgelöst haben.

+1

Das war mein Problem. Vielen Dank. –

Verwandte Themen