botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

[Question] Unable to connect the Luis from the Bot Emulator

Open maheshksingh opened this issue 9 years ago • 11 comments

Steps to Reproduce the Issue

1 . I created the intents on Luis and published the app 2. Got the app Id and key and used them in the bot 3. When I run the emulator I get an error message and it does not hit the intent functions

Expected Behavior

Based on the text, the control shud flow to appropriate intent function

Actual Results

From the emulator it fails to connect,

Please help as I am not sure what am doing wrong here...

maheshksingh avatar Jun 28 '17 17:06 maheshksingh

When I type the published Luis uri on the browser, I do get the json response, so I think my bot is unable to reach you that uri and could be its trying some other uri... Just a thought... Not sure

Please help

maheshksingh avatar Jun 28 '17 17:06 maheshksingh

Are you using the .NET SDK or the NodeJS SDK? Can you provide code that replicates your issue?

When you connect to a bot in the emulator, you provide the appId and key for the bot itself; not for LUIS. The LUIS information is to go inside of your code. Depending on the SDK being used you either have to supply the LUIS App ID and LUIS Key as separate parameters, or you can just give the published endpoint to the bot.

stevengum avatar Jun 28 '17 17:06 stevengum

@stevengum97, I am using the .Net SDK

And I am supplying the LUIS App ID and key using the attributes in the BOT

The BOT ID and Password are blank in the config since I am just using the Emulator and using the Localhost

namespace SimpleTaskAutomationBot.Dialogs
{
    [LuisModel("3760f5e301e74da6a6f32698992b0246", "06550db2-6b03-4bb7-8ef3-b5533b253d0d")]
    [Serializable]
    public class LUISDialog: LuisDialog<object>
    {
        [LuisIntent("")]
        [LuisIntent("None")]
        public async Task None(IDialogContext context, LuisResult result)
        {
            await context.PostAsync("I am sorry, I dont understand u!!");
            context.Wait(MessageReceived);
        }

        [LuisIntent("Greeting")]
        public async Task Greeting(IDialogContext context, LuisResult result)
        {
            await context.PostAsync("Hello There!!");
            context.Wait(MessageReceived);
        }
    }
}

And to call this in the MessageController I have following:

public class MessagesController : ApiController
    {
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
        {
            if (activity.Type == ActivityTypes.Message)
            {
                await Conversation.SendAsync(activity, () => new LUISDialog());
            }
            else
            {
                this.HandleSystemMessage(activity);
            }

            var response = Request.CreateResponse(HttpStatusCode.OK);
            return response;
        }

I tried attaching the ZIP file of the code, for some reason its taking time, please let me know for queststions. Thanks.

maheshksingh avatar Jun 28 '17 18:06 maheshksingh

https://drive.google.com/file/d/0Bye0RkOToURlX25TTTFOZmw5alE/view

Please use the above Google drive link to get the complete code,

Please help

maheshksingh avatar Jun 28 '17 18:06 maheshksingh

Following is the endpoint from LUIS, it all works on Browser, but how do I use this to automatically trigger the Task Intent in my BOT

https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/1589fc3a-7fc8-4ed3-8b6b-5c4fc7075e0b?subscription-key=2e80de1f1a724caa8a92fd29f481cebb&verbose=true&timezoneOffset=0&q=Hello

maheshksingh avatar Jun 28 '17 18:06 maheshksingh

OK, I got to know what was wrong:

  1. The Luis App Id and Programmatic API Key were incorrect
  2. Even when I correct the App ID and Key, it won't work in my Office Network. It could be something to do with security
  3. It only works when I am outside my Office network

But I wonder how the endpoint works both at office and outside netwrok [https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/1589fc3a-7fc8-4ed3-8b6b-5c4fc7075e0b?subscription-key=2e80de1f1a724caa8a92fd29f481cebb&verbose=true&timezoneOffset=0&q=Hello]

maheshksingh avatar Jun 28 '17 19:06 maheshksingh

so my last question is there a way to use the Endpoint mentioned above, and append the incoming message, then get the JSON response, check the Intent and then trigger the corresponding Intent Task in the BOT?

any code to refer, that would be a great help for my Demonstration of my Demo this Friday. Thanks.

maheshksingh avatar Jun 28 '17 19:06 maheshksingh

I checked your LUISDialog.cs to see if there were any differences from the code you posted; there weren't any differences so I'll address the issues I see here.

    [LuisModel("3760f5e301e74da6a6f32698992b0246", "06550db2-6b03-4bb7-8ef3-b5533b253d0d")]
    [Serializable]
    public class LUISDialog: LuisDialog<object>

This is wrong, the order is in reverse and they don't match the endpoint you've provided.

Going off the endpoint you provided in your comment, we've changed the code above to below.

    [LuisModel("1589fc3a-7fc8-4ed3-8b6b-5c4fc7075e0b", "2e80de1f1a724caa8a92fd29f481cebb")]
    [Serializable]
    public class LUISDialog: LuisDialog<object>

You indicated that you changed your code, is this what you changed it to? Regarding the endpoint not working from the bot, but working when pasted into a browser, that is strange. As you said, it sounds like a security issue, but I could be wrong.

stevengum avatar Jun 28 '17 20:06 stevengum

You are right, I changed the code as you mentioned above, and it all works if I am on the Internet and Once I login my office Intranet, it doesn't connect at all.

So I will not use the LUISDialog and its attributes as they dont work instead use the IDialog and try to get the intent using HTTP post using the endpoint. so now I am trying to use the endpoint to get the JSON response, and then extract the intent and use that to determine which intent handler to execute.

While appending the "OriginalText" to the endpoint, I am unable to extract the "OriginalText" from the IDialogContext context. Is there a way to do that in IDialog?

maheshksingh avatar Jun 28 '17 20:06 maheshksingh

When are you trying to call LUIS in your RootDialog (I'm assuming you're calling it from here)? If in MessageReceivedAsync then attaching result.text to the end of your endpoint should work.

stevengum avatar Jun 28 '17 22:06 stevengum

Hello all

I am all good now, following are the issues which I faced,

  • I was unable to connect to LUIS using the Key and AppID in the attributes from the BOT, it was throwing issue like (unable to contact https://westus.api.cognitive.microsoft.com)

The issue was with the Proxy setting at my office intranet, outside I can very well reach that URI.

so I changed the prxy settings in my program and sent the HTTPRequest to LUIS manually and got the HTTPReposponse and then deseralized that to a LUIS object. Then used the (LUISResult.topScoringIntent.intent) to decide which logic to execute.

Proxy Setting Help: https://stackoverflow.com/questions/1938990/c-sharp-connecting-through-proxy

Thanks for all the help:)

maheshksingh avatar Jun 30 '17 10:06 maheshksingh