【发布时间】: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