3
votes

I am trying to write a simple bot that uses LUIS, but seem to have an issue with after an update.

So before updating the Botbuilder to 1.1, I was having issues where Luis.Models couldn't be found. After the upgrade, and resolving a coding error, and removing Microsoft.Bot.Connector.Utilities, I can compile and run successfully, but I can't connect via the emulator.

This is the code I am using.

using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Description;
using System.Collections.Generic;
using Microsoft.Bot.Connector;
using Microsoft.Bot.Builder.Dialogs;
//using Microsoft.Bot.Connector.Utilities;
using Microsoft.Bot.Builder.Luis;
using Microsoft.Bot.Builder.Luis.Models;
using Newtonsoft.Json;

[LuisModel("c413b2ef-382c-45bd-8ff0-f76d60e2a821", "6d0966209c6e4f6b835ce34492f3e6d9")]
[Serializable]
public class Mybot : LuisDialog<object>
{

    [LuisIntent("")]
    public async Task None(IDialogContext context, LuisResult result)
    {
        string message = "I'm sorry I didn't understand. Try asking about your bill.";
        await context.PostAsync(message);
        context.Wait(MessageReceived);
    }

    [LuisIntent("NextInvoiceDate")]
    public async Task NextInvoiceDate(IDialogContext context, LuisResult result)
    {
        string message = "Your next payment will go out on the 17th of the month.";
        await context.PostAsync(message);
        context.Wait(MessageReceived);
    }

    [LuisIntent("NextAmount")]
    public async Task NextAmount(IDialogContext context, LuisResult result)
    {
        string message = $"Your next amount is expected to be around £29.72.";
        await context.PostAsync(message);
        context.Wait(MessageReceived);
    }
}

When I run the project, it starts without errors, and I get the webpage that says:

MYBot Describe your bot here and your terms of use etc. Visit Bot Framework to register your bot. When you register it, remember to set your bot's endpoint to https://your_bots_hostname/api/messages

When I run the emulator pointing to https://localhost/api/messages, it retuns "an error occurred while sending the request".

The JSON is here:

System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:443
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
   at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
   --- End of inner exception stack trace ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.Bot.Connector.Emulator.ConversationModel.<SendMessageAsync>d__50.MoveNext() 

I have also tried just HTTP (rather than HTTPS).

3
Am I missing a fundamental piece of code? Without LUIS, I would use "public class MessagesController : ApiController". No I am trying to use "public class Mybot : LuisDialog<object>". - Greg Heywood
Can you post the code of your MessageController? You still need the MessageController even if you use LUIS. - Ezequiel Jadib
Thanks. I have put the code in the original post. That is the entire content of my MessagesController.cs. - Greg Heywood
I am also getting a 407 error when using the Bot Framework Emulator! The command line version works fine though, but can't interpret JSON - which is annoying and ugly. - blueprintchris

3 Answers

1
votes

Can you check you are using the correct url for your bot? Check the project url in your project properties and make sure you are using the correct port number. By default the Bot Framework project template uses http://localhost:3978/

Project Properties

1
votes

Two things I'm seeing here:

  1. You are using https with localhost and should be http (https is when is hosted in Azure)
  2. The port is mssing

Also, you still need the MessageController even if you use LUIS (this based on the comment you added).

The MessageController will receive the message and start the conversation by "launching" a Dialog. In this case, your LUIS dialog.

0
votes

I think in the emulator endpoint you missed the port number. And normally it is http (localhost), but add 's' as 'https' for emulator url as below. https://localhost:3978/api/messages