0

我正在尝试向我们的 Slack 频道添加新的 hubot 集成。我在 Windows 机器上设置它并部署到 Heroku 服务器。我按照此处提供的安装说明进行操作:https ://github.com/slackhq/hubot-slack

我可以在本地计算机上创建并运行一个新的 hubot 实例(在 Powershell 提示符下调用“bin/hubot”),但是当我安装 hubot-slack 包并将“hubot-slack”添加到外部脚本文件时,我得到了一个错误。如果我从外部脚本文件中删除该值,一切都很好。

PS C:\hubot> bin/hubot
jarvis> [Tue Dec 22 2015 15:18:24 GMT-0800 (Pacific Standard Time)] ERROR Error loading scripts from npm package - TypeError: require(...) is not a function
  at Robot.loadExternalScripts (C:\hubot\node_modules\hubot\src\robot.coffee:399:11)
  at C:\hubot\node_modules\hubot\bin\hubot:128:26
  at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)

如果我包含 Slack 的适配器标志,我会得到一个不同的错误。我尝试将 HUBOT_SLACK_TOKEN 设置为系统环境变量。

PS C:\hubot> bin/hubot -a slack
[Tue Dec 22 2015 15:21:54 GMT-0800 (Pacific Standard Time)] ERROR No services token provided to Hubot

我能找到的每个示例都在对 hubot 的调用中包含 HUBOT_SLACK_TOKEN,但它对我不起作用(我一定遗漏了一些东西)。

PS C:\hubot> HUBOT_SLACK_TOKEN=xoxb-22211110000-123456781234ZZZZYYYYXXXX ./bin/hubot --adapter slack
HUBOT_SLACK_TOKEN=xoxb-17240119159-dBeAEc2X8M2O9vJBYzWj5KFW : The term
'HUBOT_SLACK_TOKEN=xoxb-17240119159-dBeAEc2X8M2O9vJBYzWj5KFW' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
At line:1 char:1
+ HUBOT_SLACK_TOKEN=xoxb-22211110000-123456781234ZZZZYYYYXXXX ./bin/hubot --adapte ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (HUBOT_SLACK_TOK...234ZZZZYYYYXXXX:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

为了在本地排除某些问题,我将应用程序部署到 Heroku,但出现了另一个错误。

2015-12-22T22:28:49.426496+00:00 heroku[web.1]: State changed from crashed to starting
2015-12-22T22:14:54.739959+00:00 heroku[web.1]: State changed from starting to up
2015-12-22T22:14:55.133113+00:00 app[web.1]: [Tue Dec 22 2015 22:14:55 GMT+0000 (UTC)] ERROR Error loading scripts from npm package - TypeError: object is not a function
2015-12-22T22:14:55.133117+00:00 app[web.1]:   at Robot.loadExternalScripts (/app/node_modules/hubot/src/robot.coffee:399:11, <js>:269:39)
2015-12-22T22:14:55.133119+00:00 app[web.1]:   at fs.js:272:14
2015-12-22T22:14:55.133121+00:00 app[web.1]:   at Object.oncomplete (fs.js:108:15)
2015-12-22T22:14:56.115333+00:00 heroku[web.1]: State changed from up to crashed

包.json:

{
  "name": "jarvis",
  "version": "0.0.0",
  "private": true,
  "author": "Me <email@domain.com>",
  "description": "A friendly robot",
  "dependencies": {
    "hubot": "^2.17.0",
    "hubot-diagnostics": "0.0.1",
    "hubot-google-images": "^0.2.6",
    "hubot-google-translate": "^0.2.0",
    "hubot-help": "^0.1.2",
    "hubot-heroku-keepalive": "^1.0.1",
    "hubot-maps": "0.0.2",
    "hubot-pugme": "^0.1.0",
    "hubot-redis-brain": "0.0.3",
    "hubot-rules": "^0.1.1",
    "hubot-scripts": "^2.16.2",
    "hubot-shipit": "^0.2.0",
    "requirejs": "^2.1.22",
    "hubot-slack": "^3.4.2"
  },
  "engines": {
    "node": "0.10.x"
  }
}

外部脚本.json

[
  "hubot-diagnostics",
  "hubot-help",
  "hubot-heroku-keepalive",
  "hubot-google-images",
  "hubot-google-translate",
  "hubot-pugme",
  "hubot-maps",
  "hubot-redis-brain",
  "hubot-rules",
  "hubot-shipit",
  "requirejs",
  "hubot-slack"
]
4

2 回答 2

1

在 Windows 上,该机制似乎与它在 Linux 中处理的机制略有不同。引发错误“HUBOT_SLACK_TOKEN 无法识别”,因为它会从 Windows 环境变量中读取“HUBOT_SLACK_TOKEN”的值。

手动创建环境变量“HUBOT_SLACK_TOKEN”并设置值,它将起作用。

你可以在 github repo 的源代码中查看它:slack.coffee。

options =
  token: process.env.HUBOT_SLACK_TOKEN
  autoReconnect: !exitProcessOnDisconnect
  autoMark: true
  exitOnDisconnect: exitProcessOnDisconnect
  proxyUrl: process.env.https_proxy
于 2016-06-21T02:04:54.110 回答
0

让我感兴趣的是这条特别的线:

Error loading scripts from npm package - TypeError: require(...) is not a function

您是否也添加了来自 repo 的其他脚本?

Windows 机器上的 node/npm/coffee 安装/版本也可能有问题。确保这些已安装且版本兼容。另一个线程存在不兼容版本的问题。请告诉我们您使用的版本并尝试将节点降级到 0.12.x。

您使用令牌的方式很好。

于 2015-12-23T09:16:50.193 回答