测试部署到 Azure 的机器人时的 http 500

http 500 when testing bot deployed to azure

已将机器人从本地 git 存储库部署到 Azure - https://docs.microsoft.com/en-us/bot-framework/deploy-bot-local-git

代码:

var restify = require('restify');
var builder = require('botbuilder');

var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () { });

// Create the chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
    appId: "app-id",
    appPassword: "app-password"
});

// Listen for messages from users
server.post('/api/messages', connector.listen());

// Create your bot with a function to receive messages from the user
var bot = new builder.UniversalBot(connector, function (session) {
    // echo the user's message
    session.send("You said: %s", session.message.text);
});

https://dev.botframework.com -

的网络聊天中收到 http 500 错误和消息

There was an error sending this message to your bot: HTTP status code InternalServerError

我可以使用本地主机 url 以及 App Id 和密码从 Bot Framework Emulator 连接到 bot。

也许我需要指定 web 应用程序是 nodejs?我在应用程序设置中看不到任何关于应用程序入口点或 nodejs 选项的信息。

编辑: 将 "main": "index.js" 更改为 "main": "app.js" 但仍然无法发送测试消息。

EDIT2:我将 web.config 添加到项目中(没有对建议代码进行任何更改),之后我在 bot 页面上收到消息 (http://it-perf-bot.azurewebsites.net/api/messages) - 该页面无法显示,因为内部服务器发生错误。然后我添加了 IISnode.yml

loggingEnabled: true
devErrorsEnabled: true

并收到此消息 - http://prntscr.com/gc8vww 将 bot 推送到 azure 时记录 - http://prntscr.com/gc8wia,

The package.json file does not specify node.js engine version constraints.

我将 "engines":{"node": "8.1.4"} 添加到 package.json 并得到

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. My bot - https://github.com/lavandil/skypeBot1.

EDIT3:在制作 edit2 时我测试了 url http://it-perf-bot.azurewebsites.net/api/messages 并得到了不同的警告

The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.

然后我在 dev.botframework.com 测试机器人和 Bot Framework Emulator - 在将节点版本添加到程序包 json 后一切正常。感谢回复!

Maybe I need to specify that web application is nodejs? I don't see in application settings anything about entry point of app or nodejs option.

您需要做的是在 Node.js 应用程序的根目录中创建一个 web.config 文件(如果不存在)。作为参考,以下是使用 app.js 作为入口点的应用程序的默认值 web.config

<?xml version="1.0" encoding="UTF-8"?>
<!--
       This configuration file is required if iisnode is used to run node processes behind
       IIS or IIS Express.  For more information, visit:

       https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
  -->
<configuration>
  <system.webServer>
    <!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
    <webSocket enabled="false" />
    <handlers>
      <!-- Indicates that the server.js file is a node.js web app to be handled by the iisnode module -->
      <add name="iisnode" path="app.js" verb="*" modules="iisnode" />
    </handlers>
    <rewrite>
      <rules>
        <!-- Do not interfere with requests for node-inspector debugging -->
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^app.js\/debug[\/]?" />
        </rule>
        <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
        <rule name="StaticContent">
          <action type="Rewrite" url="public{REQUEST_URI}" />
        </rule>
        <!-- All other URLs are mapped to the node.js web app entry point -->
        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" />
          </conditions>
          <action type="Rewrite" url="app.js" />
        </rule>
      </rules>
    </rewrite>
    <!--
        You can control how Node is hosted within IIS using the following options:
          * watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
          * node_env: will be propagated to node as NODE_ENV environment variable
          * debuggingEnabled - controls whether the built-in debugger is enabled

        See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
      -->
    <!--<iisnode watchedFiles="web.config;*.js"/>-->
  </system.webServer>
</configuration>

此外,对于 500 错误,您需要启用 stdout 和 stderr 的日志记录以进行故障排除并查看日志内容。要启用调试,请参考

在制作 edit2 时我测试 url http://it-perf-bot.azurewebsites.net/api/messages 并收到不同的警告

您正在查找的页面无法显示,因为使用了无效的方法(HTTP 动词)。 然后我在 dev.botframework.com 测试机器人和 Bot Framework Emulator - 在将节点版本添加到包 json 后一切正常。感谢回复!