Call LUIS outside of MessageController and after Authentication

喜你入骨 提交于 2019-12-11 04:13:35

问题


Working on a Bot that authenticates using ADAL (AuthBot) and then post-Auth takes the user input and sends to LUIS to gather intents/entities. I use what's returned to build a URI that I send to Sharepoint Online REST API. If user input is valid, Sharepoint returns JSON that I parse and return to user.

The trouble is getting the user input to my LUIS class after authentication. I call AuthBot ActionDialog from my MessageController.

        if (message.Type == "Message")
        {
            return await Conversation.SendAsync(message, () => new ActionDialog());
        }           

Within ActionDialog, I'm not sure how to move move the Message to the LUIS Class

   public async Task MessageReceivedAsync(IDialogContext context, IAwaitable<Message> item)
    {
        var message = await item;
        if (message.Text == "logon")
        {
            if (string.IsNullOrEmpty(await context.GetAccessToken(ConfigurationManager.AppSettings["ActiveDirectory.ResourceId"])))
            {
                await context.Forward(new AzureAuthDialog(ConfigurationManager.AppSettings["ActiveDirectory.ResourceId"]), this.ResumeAfterAuth, message, CancellationToken.None);
            }
            else
            {
                context.Wait(MessageReceivedAsync);
            }
        }
        else if (string.IsNullOrEmpty(await context.GetAccessToken(ConfigurationManager.AppSettings["ActiveDirectory.ResourceId"])))
        {
            await context.Forward(new AzureAuthDialog(ConfigurationManager.AppSettings["ActiveDirectory.ResourceId"]), this.ResumeAfterAuth, message, CancellationToken.None);
        }
        else
        {
            //this is where I want to send the next user input from bot to LUIS class.                
        }
    }    

The LUIS Class is standard and looks like this:

//Define the LuisModel that will be used.  The LuisModel JSON file can be found at ~/json/letseat.json
[LuisModel("ModelID", "ModelSecret")]
[Serializable]
public class LuisDialog : LuisDialog<object>

Any Ideas? Thanks.


回答1:


I assume that you are using AuthBot (by looking at the code).

What you need to add is the following:

 await base.MessageReceived(context, item);

That will just pass the message to LUISDialog's MessageReceived implementation; which will issue a query to LUIS to understand which intent should be executed.



来源:https://stackoverflow.com/questions/38010375/call-luis-outside-of-messagecontroller-and-after-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!