【问题标题】:Botframework emulator and 404 errorBotframework 模拟器和 404 错误
【发布时间】:2016-10-08 14:20:33
【问题描述】:

我正在尝试编写一个使用 LUIS 的简单机器人,但似乎在更新后遇到了问题。

所以在将 Botbuilder 更新到 1.1 之前,我遇到了找不到 Luis.Models 的问题。升级后,解析coding error,删除Microsoft.Bot.Connector.Utilities,可以编译运行成功,但无法通过模拟器连接。

这是我正在使用的代码。

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);
    }
}

当我运行该项目时,它启动时没有错误,并且我得到的网页显示:

MYBot 在此处描述您的机器人以及您的使用条款等。 访问 Bot Framework 以注册您的机器人。注册时,请记住将机器人的端点设置为 https://your_bots_hostname/api/messages

当我运行指向https://localhost/api/messages 的模拟器时,它会返回“发送请求时发生错误”。

JSON 在这里:

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() 

我也只尝试过 HTTP(而不是 HTTPS)。

【问题讨论】:

  • 我是否遗漏了一段基本代码?如果没有 LUIS,我将使用“公共类 MessagesController:ApiController”。不,我正在尝试使用“public class Mybot:LuisDialog”。
  • 你能把你的MessageController的代码贴出来吗?即使您使用 LUIS,您仍然需要 MessageController。
  • 谢谢。我已将代码放在原始帖子中。这就是我的 MessagesController.cs 的全部内容。
  • 我在使用 Bot Framework Emulator 时也遇到 407 错误!命令行版本虽然工作正常,但无法解释 JSON - 这既烦人又丑陋。

标签: botframework


【解决方案1】:

您能检查一下您为您的机器人使用了正确的网址吗?检查项目属性中的项目 url 并确保使用正确的端口号。默认情况下,Bot Framework 项目模板使用 http://localhost:3978/

【讨论】:

    【解决方案2】:

    我在这里看到了两件事:

    1. 您在 localhost 中使用 https,并且应该是 http(https 是在 Azure 中托管时)
    2. 端口正在发送消息

    此外,即使您使用 LUIS,您仍然需要 MessageController(这基于您添加的评论)。

    MessageController 将接收消息并通过“启动”一个对话框来开始对话。在这种情况下,您的 LUIS 对话框。

    【讨论】:

    • 谢谢。我已将代码放在原始帖子中。这就是我的 MessagesController.cs 的全部内容。我也尝试过 HTTP (localhost:3978/api/messages),并得到 404 Not Found。
    • 哦,所以您的 MessageController.cs 只包含 LUISDialog?如果是这样,那么这就是问题的根本原因。您需要一个接收消息的 MessageController(一个 webapi)。您的消息控制器应该像这样一个 github.com/Microsoft/BotBuilder/blob/master/CSharp/Samples/...。您只需将其启动的对话框替换为您的 LUIS 对话框。
    【解决方案3】:

    我认为在模拟器端点中您错过了端口号。通常它是 http (localhost),但在模拟器 url 中添加 's' 作为 'https',如下所示。 https://localhost:3978/api/messages

    【讨论】:

    • 谢谢。我试过HTTP、HTTPS,有端口,没有,有“/api/messages”,没有。
    猜你喜欢
    • 2016-11-13
    • 2017-07-28
    • 2015-03-23
    • 2018-05-29
    • 2020-09-11
    • 2020-04-25
    • 2021-06-25
    • 2015-08-02
    • 2021-11-06
    相关资源
    最近更新 更多