在尝试使用特别慢的api时,我试图让我的机器人用户忙。我将用户转发到新对话框,并提供取消令牌以在api返回我的结果后取消该对话框。
当我在取消令牌上调用Cancel()时,我期望下面的代码退出stallUntilCompletedDialog
public async Task ResumeAfterFirstDialog(IDialogContext context,
IAwaitable<API.Models.Request> result)
{
var requestData = await result;
var response = new API.Models.Response();
var cancellationToken = new CancellationTokenSource();
Task.Run(async () =>
{
response = await _slowApi.CallApi(requestData, accessToken);
cancellationToken.Cancel();
});
var stallUntilCompletedDialog = new StallUntilCompletedDialog<ApiResponse>();
await context.Forward(stallUntilCompletedDialog,
ResumeAfterCompletedDialog,
result,
cancellationToken.Token);
}
ResumeAfterCompletedDialog永远不会启动,我陷入了停滞对话框。 如何在api响应时退出对话框,以及如何在ResumeAfterCompletedDialog中使api响应可用?