我正在尝试将Microsoft Bot Emulator连接到Azure中的远程bot。
当我在本地运行我的机器人它按预期工作但是当我设置一个新配置连接到Azure中的“Web应用程序机器人”我得到如下错误
[16:05:17]Error: The bot is remote, but the service URL is localhost.
Without tunneling software you will not receive replies.
[16:05:17]Connecting to bots hosted remotely
[16:05:17]Edit ngrok settings
[16:05:17]->messagehi
[16:05:17] POST 500 directline.postActivity
我在ngrok设置中尝试了不同的选项,并按照这篇文章(Bot Emulator gets POST 500 directline.postActivity)。但是,我仍然收到错误。下面是模拟器inspector-json中的日志详细信息。
"{\r\n \"message\": \"An error has occurred.\",\r\n \"exceptionMessage\":
\"An error occurred while sending the request.\",\r\n \"exceptionType\":
\"System.Net.Http.HttpRequestException\",\r\n \"stackTrace\": \" at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task <>c__DisplayClass11_0.<<SendAsync>b__1>d.MoveNext()\\r\\n--- End of stack
trace from previous location where exception was thrown ---\\r\\n at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)\\r\\n
预期:
您无法在Emulator中为您的bot(“xxxxxx.azurewebsites.ner / api / messages”)使用Azure提供的消息传递端点。模拟器用于测试本地存储的机器人。但是,您可以通过ngrok隧道将本地bot连接到Azure托管的bot,以访问外部服务和渠道。这允许您在将bot发布到Azure之前测试代码。
首先,使用ngrok创建隧道(您可以根据需要更改端口)。要创建该隧道,请运行以下cli命令:
ngrok http 3978 -host-header="localhost:3978"
这将产生一个转发(即隧道)地址,如下所示:
https://h8g56dq.ngrok.io
复制“https”地址。
接下来,使用上面的地址替换Azure托管机器人中的消息传递端点,并附加“api / messages”。输入后应该看起来像这样:
https://h8g56dg.ngrok.io/api/messages
在模拟器中,将地址设置为上述。同时输入您的AppId和AppPassword,否则您将收到401 Unauthorized状态代码。
此时,在本地bot运行的情况下,您将可以通过Emulator进行连接。
希望有所帮助!