【问题标题】:http 500 when testing bot deployed to azure测试部署到 azure 的机器人时的 http 500
【发布时间】:2018-01-31 08:11:35
【问题描述】:

将机器人从本地 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 错误和消息 -

向您的机器人发送此消息时出错:HTTP 状态代码 InternalServerError

我可以使用 localhost url 和 App Id 和密码从 Bot Framework Emulator 连接到机器人。

也许我需要指定 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 将机器人推送到天蓝色时记录 - http://prntscr.com/gc8wia

package.json 文件未指定 node.js 引擎版本约束。

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

您要查找的资源已被删除、名称已更改或暂时不可用。 我的机器人 - https://github.com/lavandil/skypeBot1

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

您正在查找的页面无法显示,因为正在使用无效的方法(HTTP 动词)。

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

【问题讨论】:

标签: node.js azure botframework skype


【解决方案1】:

也许我需要指定 Web 应用程序是 nodejs?我在应用程序设置中没有看到有关应用程序入口点或 nodejs 选项的任何内容。

您需要做的是在您的 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 的日志记录以进行故障排除并查看日志的内容。开启调试请参考my earlier answer here

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-20
      • 2019-10-12
      • 1970-01-01
      • 2020-03-02
      • 1970-01-01
      • 1970-01-01
      • 2020-11-30
      相关资源
      最近更新 更多