C# 对话框在api get调用后返回父对话框,而不是继续当前对话框
在继续执行其他机器人程序功能之前,我正在尝试对用户进行身份验证,并使用此代码确保用户存在C# 对话框在api get调用后返回父对话框,而不是继续当前对话框,c#,botframework,C#,Botframework,在继续执行其他机器人程序功能之前,我正在尝试对用户进行身份验证,并使用此代码确保用户存在 [Serializable] public class ModifyLicenceDialog: IDialog<object> { private const string CreateLicence = "Create a new licence"; private const string ModifyEndDate = "Modify end date"; p
[Serializable]
public class ModifyLicenceDialog: IDialog<object>
{
private const string CreateLicence = "Create a new licence";
private const string ModifyEndDate = "Modify end date";
private const string CancelLicence = "Cancel a licence";
public async Task StartAsync(IDialogContext context)
{
if (!CommonConversation.User.IsAuthorized)
{
context.Call(new AuthDialog(), ResumeAfterAuth);
}
}
private async Task ResumeAfterAuth(IDialogContext context, IAwaitable<object> result)
{
await result;
PromptDialog.Choice(context, ResumeAfterChoice, new[] { CreateLicence, ModifyEndDate, CancelLicence },
"What licence function would you like?",
"I am sorry i did not understand that, please select one of the below options");
}
private async Task ResumeAfterChoice(IDialogContext context, IAwaitable<string> result)
{
string selected = await result;
switch (selected)
{
case CreateLicence:
context.Call(new CreateLicenseDialog(), AfterLicenseDialog(CreateLicence));
break;
case ModifyEndDate:
break;
case CancelLicence:
break;
}
}
private ResumeAfter<object> AfterLicenseDialog(IDialogContext context, string licenseEvent)
{
switch (licenseEvent)
{
case CancelLicence:
await context.PostAsync("Auth done");
context.Done(licenseEvent);
break;
}
}
更新在Nicolas R提供了一些指导之后,结果表明,此时会抛出一个异常
例外情况如下
{"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."}
" at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at SupportHelpdeskBot.Dialogs.AuthDialog.<MessageReceivedAsync>d__3.MoveNext() in C:\\Workspace\\SupportBot\\SupportHelpdeskBot\\SupportHelpdeskBot\\Dialogs\\AuthDialog.cs:line 41"
{“无法从传输连接读取数据:远程主机强制关闭了现有连接。”}
“在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)\r\n在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\r\n在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n在SupportHelpdeskBot.Dialogs.AuthDialog.d\u 3.MoveNext()在C:\\Workspace\\SupportBot\\SupportHelpdeskBot\\SupportHelpdeskBot\\Dialogs\\AuthDialog.cs:第41行“
我尝试了
System.Net.ServicePointManager.Expect100Continue=false
来阻止这种情况发生,但这没有任何建议?您的实现中没有错误:您正在使用您的上下文在此处完成AuthDialog
。完成(电子邮件)
:
if(res.issusccessstatuscode)
{
CommonConversation.User=JsonConvert.DeserializeObject(wait res.Content.ReadAsStringAsync());
wait context.PostAsync($“Welcome{CommonConversation.User.FirstName}!”);
上下文。完成(电子邮件);
}
这是正常的行为。您想要实现什么?我认为您的问题不完整尝试使用Context.Forward()而不是Context.Call():
等待Context.Forward(new PaymentDialog()、ResumeAfterPaymentDialog、Context.Activity.AsMessageActivity()、CancellationToken.None)代码>您好,感谢您的回复,在使用forward now之后,它甚至在AuthDialog StartAsync上都没有等待。值得一试。是否知道为什么会发生这种情况?不,如果我的问题不清楚,我很抱歉,但问题是它在res=wait client.GetAsync(uri)之后从未到达任何代码;一旦请求完成,而不是像您在if语句中指出的那样继续,它将返回到父对话框。您是否在调试时添加了对“res”的查看?你能把“ModifyLicenceDialog”的所有代码都放进去吗?是的,res返回一个200响应,带有预期的json对象,请给我一秒钟时间,我更新ModifyLicenceDialog的其余部分,我们不能测试web调用,我只能给出一些提示。你可以尝试/捕获MessageReceived的内容吗?啊,很抱歉,这就是你的意思。是的,我在web api调用中也有一个断点,它执行得很好,返回Ok(JsonObject)。我也可以提供相应的代码。不幸的是,我现在不能测试任何东西,因为我来自我的家庭计算机,只能访问我的代码的只读版本。我将在8小时后回到办公室。我已经用完整的代码更新了ModifyLicense对话框
{"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."}
" at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at SupportHelpdeskBot.Dialogs.AuthDialog.<MessageReceivedAsync>d__3.MoveNext() in C:\\Workspace\\SupportBot\\SupportHelpdeskBot\\SupportHelpdeskBot\\Dialogs\\AuthDialog.cs:line 41"
if (res.IsSuccessStatusCode)
{
CommonConversation.User = JsonConvert.DeserializeObject<CustomerUser>(await res.Content.ReadAsStringAsync());
await context.PostAsync($"Welcome {CommonConversation.User.FirstName}!");
context.Done(email);
}