1

I'm trying to access the original message in a LuisIntent method in a LuisModel class I am using in a Microsoft Bot Framework (version 3) C# project. However, I can't seem to figure it out myself, nor do any suggestions made in a related StackOverflow question work (because this concerns MBF version 1).

I tried commenting on a related issue on GitHub, without success.

Does anyone know how to get the user message that fired the method?

Community
  • 1
  • 1
  • Luis returns the actual message in query, so check args.query. The args is all json format, you can easily log it to see what coming from luis and what should be parsed. – N0mi Aug 04 '16 at 18:46

1 Answers1

1

Update (08/09/2016)

Since latest release (3.2.0), thanks for the commit (https://github.com/Microsoft/BotBuilder/commit/f156a60880e86f7b853b1f94a5546386436ac3d0)

Now we are able to get the activity directly from the intent handler

Sample code

public async Task Test(IDialogContext context, IAwaitable<IMessageActivity> origin, LuisResult result)

Original answer (05/08/2016)

You can have a property to store the origin activity and assign it in MessageReceived

public class YourDialog : LuisDialog<string>
{    
    [NonSerialized]
    private IMessageActivity _originActivity;

    internal YourDialog()
    {
    }

    [LuisIntent("IntentionConstant.Empty")]
    public async Task HandleLuisResult(IDialogContext context, LuisResult result)
    {
        try
        {
            // you can access _originActivity here

        }
        catch (Exception ex) when(ex is ApplicationException)
        {
            throw;
        }
        catch (Exception ex) when (ex is TaskCanceledException)
        {
        }
    }

    protected override async Task MessageReceived(IDialogContext context, IAwaitable<IMessageActivity> item)
    {
        _originActivity = await item;
        await base.MessageReceived(context, item);
    }
}
Community
  • 1
  • 1
Kien Chu
  • 4,735
  • 1
  • 17
  • 31