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

后端 未结 4 1626
孤城傲影
孤城傲影 2021-02-14 11:00

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

The documentation shows these

4条回答
  •  爱一瞬间的悲伤
    2021-02-14 11:06

    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
    {
        private readonly Dictionary alarmByWhat = new Dictionary();
    
        [Serializable]
        public class PartialMessage
        {
            public string Text { set; get; }
        }
    
        private PartialMessage message;
    
        protected override async Task MessageReceived(IDialogContext context, IAwaitable 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);
        }
    }
    
        

    提交回复
    热议问题