Reputation: 51
I have been working on the Bot Framework, in that i have created the Prompt choice as Yes, No, I'm independent type of question. But if i enter the any text which was not present the option List then i should pass the user text to LUIS for hitting the corresponding Intent. I have tried that by getting the user text in Catch block but (await result) not getting the user text.enter image description here
Upvotes: 1
Views: 747
Reputation: 3426
Consider the following prompt:
PromptDialog.Choice(context, this.ChoiceReceivedAsync, new List<string>() { "Choice 1", "Choice 2" }, "stuff and things");
in the resume after method, you can apply logic on the users choice like:
private Task ChoiceReceivedAsync(IDialogContext context, IAwaitable<string> result)
{
Activity a = context.Activity as Activity;
switch (a.Text)
{
case "Choice 1":
//do stuff
break;
case "Choice 2":
//do stuff
break;
default:
context.Forward(new Luis(), afterLuis, context.Activity, CancellationToken.None);
break;
}
a = a.CreateReply("things");
context.PostAsync(a);
return Task.CompletedTask;
}
That way if the user enters anything other than a choice it will be sent to Luis()
which in my case is a public class Luis : LuisDialog<object>
or a Luis dialog to handle Luis calls.
You could also have done it like this calling the LUIS API rather than using a LUIS dialog.
private async Task ChoiceReceivedAsync(IDialogContext context, IAwaitable<string> result)
{
Activity a = context.Activity as Activity;
switch (a.Text)
{
case "Choice 1":
//do stuff
break;
case "Choice 2":
//do stuff
break;
default:
using (HttpClient client = new HttpClient())
{
string RequestURI = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/YOUR_MODEL_ID?" +
"subscription-key=YOUR_SUBSCRIPTION_KEY&verbose=true&timezoneOffset=0&q=" +
a.Text;
HttpResponseMessage msg = await client.GetAsync(RequestURI);
if (msg.IsSuccessStatusCode)
{
var JsonDataResponse = await msg.Content.ReadAsStringAsync();
LUISData luisData = JsonConvert.DeserializeObject<LUISData>(JsonDataResponse);
}
}
break;
}
a = a.CreateReply("things");
await context.PostAsync(a);
}
in order to do it this way you would have to add classes like this to support the deserialization.
public class LUISData
{
public string query { get; set; }
public LUISIntent[] intents { get; set; }
public LUISEntity[] entities { get; set; }
}
public class LUISEntity
{
public string Entity { get; set; }
public string Type { get; set; }
public string StartIndex { get; set; }
public string EndIndex { get; set; }
public float Score { get; set; }
}
public class LUISIntent
{
public string Intent { get; set; }
public float Score { get; set; }
}
Upvotes: 1