I'm trying to access the complete original text from within a method marked as a LuisIntent within a LuisDialog.
The example docs show these methods taking two properties: IDialogContext context, LuisResult result
Neither of which publicly exposes the original text message. The context object does contain the message but in a private property (context.data.message.text) which is not accessible.
Is there a way to access the message text in the context, or can it be passed into the dialog constructor? Some other way?
I have the same question. I am using Application Insights to log intent telemetry on my bot, and I want to add the original message that yielded the intent to the event payload. Solving this scenario would be very helpful for me because it will help me prioritize training common, unclassified utterances into the model.
Please post any wisdom back to Gene's question on SO as well for maximum reach.
https://stackoverflow.com/questions/36482531/how-do-you-get-to-the-original-message-text-in-a-microsoft-bot-framework-luisint
Thanks for your question. We are thinking about better ways of exposing the original message through context but in the mean time to solve your problem you can override the MessageReceived(...) function of the LuisDialg, keep the fields of the message that you need as member variables and access those fields in your intent handlers. Below I modified the SimpleAlarmDialog to show how you can access 'message.Text' in one of the intent handlers:
[LuisModel("c413b2ef-382c-45bd-8ff0-f76d60e2a821", "6d0966209c6e4f6b835ce34492f3e6d9")]
[Serializable]
public class SimpleAlarmDialog : LuisDialog<object>
{
private readonly Dictionary<string, Alarm> alarmByWhat = new Dictionary<string, Alarm>();
[Serializable]
public class PartialMessage
{
public string Text { set; get; }
}
private PartialMessage message;
protected override async Task MessageReceived(IDialogContext context, IAwaitable<Message> item)
{
var msg = await item;
this.message = new PartialMessage { Text = msg.Text };
await base.MessageReceived(context, item);
}
[LuisIntent("builtin.intent.alarm.delete_alarm")]
public async Task DeleteAlarm(IDialogContext context, LuisResult result)
{
await context.PostAsync($"echo: {message.Text}");
Alarm alarm;
if (TryFindAlarm(result, out alarm))
{
this.alarmByWhat.Remove(alarm.What);
await context.PostAsync($"alarm {alarm} deleted");
}
else
{
await context.PostAsync("did not find alarm");
}
context.Wait(MessageReceived);
}
}
Perhaps I'm missing something, but attempting to override gives:
MessageReceived(IDialogContext, IAwaitable
Commit ba25b1 in develop branch made it virtual. We are in the process of doing a release soon (probably today) that will have this change.
Awesome, thanks!
I get an
Severity Code Description Project File Line Suppression State
Error CS0115 'AIDialog.MessageReceived(IDialogContext, IAwaitable)': no suitable method found to override LISA-Bot C:\Users.....\Dialogs\AIDialog.cs 38 Active
error when trying to do this in Microsoft Bot Framework V3. Any suggestions?
Most helpful comment
Thanks for your question. We are thinking about better ways of exposing the original message through context but in the mean time to solve your problem you can override the MessageReceived(...) function of the LuisDialg, keep the fields of the message that you need as member variables and access those fields in your intent handlers. Below I modified the SimpleAlarmDialog to show how you can access 'message.Text' in one of the intent handlers: