我正在玩Bot框架的例子,並製作了一個簡單的對話框,用來向用戶致敬。我遇到的問題是,在提示輸入用戶名後,恢復方法從不會觸發。它總是返回到ConverstationStartedAsync方法。任何想法爲什麼?Bot框架總是激活對話框的方法
這是對話框:
public class HelloDialog : IDialog<string>
{
public async Task StartAsync(IDialogContext context)
{
context.Wait(ConversationStartedAsync);
}
public async Task ConversationStartedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
{
var message = await argument;
PromptDialog.Text(
context: context,
resume: AfterNameInput,
prompt: "Hi! what's your name?",
retry: "Sorry, I didn't get that.");
}
public async Task AfterNameInput(IDialogContext context, IAwaitable<string> result)
{
var name = await result;
PromptDialog.Text(context, AfterAskNeed, "Hi {name}. How can I help you?", "Sorry, I didn't get that.", 3);
}
,這是在MessagesController行動:
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity != null)
{
// one of these will have an interface and process it
switch (activity.GetActivityType())
{
case ActivityTypes.Message:
try
{
await Conversation.SendAsync(activity,() => new HelloDialog());
}
catch(Exception ex)
{
}
break;
case ActivityTypes.ConversationUpdate:
case ActivityTypes.ContactRelationUpdate:
case ActivityTypes.Typing:
case ActivityTypes.DeleteUserData:
default:
break;
}
}
return new HttpResponseMessage(System.Net.HttpStatusCode.Accepted);
}
是'StartConversationDialog'一樣'HelloDialog'? – stuartd
是的。對不起,我會更正代碼。 – Maxolidean