Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get to the original message text in a Microsoft Bot Framework LuisIntent method

I'm trying to access the complete original text from within a method marked as a LuisIntent within a LuisDialog.

The documentation shows these methods as taking two arguments:

IDialogContext context, LuisResult result

Neither of which publicly exposes the original text of the 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 this in the context, or can it be passed into the dialog constructor?

like image 359
Gene Reddick Avatar asked Apr 07 '16 16:04

Gene Reddick


People also ask

How does Microsoft bot framework work?

It hosts bots and makes them available to channels, such as Microsoft Teams, Facebook, or Slack. The Bot Framework Service, which is a component of the Azure Bot Service, sends information between the user's bot-connected app and the bot. Each channel can include additional information in the activities they send.

What is dialog in bot framework?

What is a dialog in Bot framework? Basically dialog is a class, which allows Bot developer to logically separate various areas of Bot functionality and guide conversational flow.

How do you use Luis in bot framework?

Create a LUIS app in the LUIS portal Sign in to the LUIS portal and if needed create an account and authoring resource. On the Conversation apps page in LUIS, select Import, then Import as JSON. In the Import new app dialog: Choose the FlightBooking.

Which of the following method is called when creating proactive messages for Microsoft teams bot?

The continue conversation method uses the conversation reference and a turn callback handler to: Create a turn in which the bot application can send the proactive message.


2 Answers

You can override the MessageReceived(...) function of the LuisDialog 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);
    }
}
like image 157
Shahin Shayandeh Avatar answered Oct 09 '22 09:10

Shahin Shayandeh


With the new version of Bot Framework (1.0.2) the LuisResult object now has a Query parameter that contains the original query sent to LUIS.

like image 25
fdezjose Avatar answered Oct 09 '22 10:10

fdezjose