確認提示用ParseMessage發送文本到Luis,然後返回true或false。我在這個文件中設置了調試器,並且驗證的響應返回了bool。從IAwaitable獲得布爾<IMessageActivity>
有問題的代碼。當我收到結果時說Cannot implicitly convert IAwaitable<bool> to bool
,這是Convert.ToBoolean()
進來的地方;但仍然沒有運氣。
如何檢查返回的布爾值,以便我可以驗證此if語句中的結果。
在該當前代碼示例它只是回送一個消息在機器人仿真器說:
例外:無法轉換類型的對象「Microsoft.Bot.Builder.Internals.Fibers.Wait`2 [Microsoft.Bot .Builder.Dialogs.Internals.DialogTask,System.Boolean]'鍵入'System.IConvertible'。
編輯:更新了更多的代碼
RootDialog.cs
private async Task SendWelcomeMessageAsync(IDialogContext context)
{
await context.PostAsync("Hi, I'm the Basic Multi Dialog bot. Let's get started.");
context.Call(new ConfirmLuisPrompt(), this.ConfirmLuisPromptAfter);
}
private async Task ConfirmLuisPromptAfter(IDialogContext context, IAwaitable<bool> result)
{
//var res = Convert.ToBoolean(result);
var confirm = await result;
if (confirm)
{
//yes
context.Call(FormDialog.FromForm(PersonInfo.BuildForm, FormOptions.PromptInStart), this.PersonInfoAfter);
}else
{
//no
await context.PostAsync($"Ok, let's get you started");
context.Call(FormDialog.FromForm(PatientInfo.BuildForm, FormOptions.PromptInStart), InHospital);
}
}
ConfirmLuisPrompt.cs
[Serializable]
public class ConfirmLuisPrompt : IDialog<bool>
{
public async Task StartAsync(IDialogContext context)
{
await context.PostAsync("Do you have insurance?");
context.Wait(this.MessageReceivedAsync);
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
dynamic m = await result;
var message = m.Text.ToString();
//context.Wait(ParseMessage(context, message));
bool response = await ParseMessage(message);
context.Done(response);
//context.PostAsync(response.toString());
}
public bool ParseMessage(string input)
{
LuisClient luisClient = new LuisClient("<key1>", "<key2>");
Task<LuisResult> resultTask = luisClient.Predict(input);
resultTask.Wait();
LuisResult result = resultTask.Result;
if (result.TopScoringIntent.Name == "Yes")
{
return true;
}
else if (result.TopScoringIntent.Name == "No")
{
return false;
}
else
{
return false;
}
}
}
說'例外:「布爾」不包含「GetAwaiter''的定義似乎很奇怪,因爲它是一個IAwaitable笑 – teachtyler
我覺得這個評論是針對對方的回答。 –
我試了兩次,得到了同樣的例外 – teachtyler