0

I am trying to add a new hubot integration to our Slack channels. I am setting this up on a Windows machine and am deploying to a Heroku server. I followed the installation instructions provided here: https://github.com/slackhq/hubot-slack

I can create and run a new hubot instance on my local computer (calling "bin/hubot" in a Powershell prompt), but when I install the hubot-slack package and add "hubot-slack" to the external-scripts file I get an error. If I remove the value from the external-scripts file everything is fine.

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)

If I include the adapter flag for Slack I get a different error. I tried setting HUBOT_SLACK_TOKEN as a System Environment variable.

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

Every example I can find is including the HUBOT_SLACK_TOKEN in the call to hubot, but it doesn't work for me (I must be missing something).

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

To rule out something locally I deployed the application to Heroku, but I got a different error.

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

package.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"
  }
}

external-scripts.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"
]
codingintherain
  • 263
  • 4
  • 10

2 Answers2

1

On Windows, it seems that the mechanism is a little different from what it processes in Linux. The error 'HUBOT_SLACK_TOKEN is not recognized' is raised because it would read the value of 'HUBOT_SLACK_TOKEN' from environment variables in windows.

Create an environment variable 'HUBOT_SLACK_TOKEN' manually and set the value, it will work.

You could check it out in the source code in the github repo: slack.coffee.

options =
  token: process.env.HUBOT_SLACK_TOKEN
  autoReconnect: !exitProcessOnDisconnect
  autoMark: true
  exitOnDisconnect: exitProcessOnDisconnect
  proxyUrl: process.env.https_proxy
Lapfed255
  • 40
  • 2
  • 6
Summer
  • 259
  • 3
  • 3
  • `[Environment]::SetEnvironmentVariable("HUBOT_SLACK_TOKEN","xoxb-22211110000-123456781234ZZZZYYYYXXXX")` worked for me. Or `[Environment]::SetEnvironmentVariable("HUBOT_SLACK_TOKEN","xoxb-22211110000-123456781234ZZZZYYYYXXXX", "Machine")` if it's running under a service account. – jpvantuyl Jul 20 '17 at 21:59
0

What intrigues me is this particular line:

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

Did you add the other scripts from the repo aswell?

There also might be something wrong with the node/npm/coffee installation/version on your windows machine. Make sure that those are installed and in a compatible version. Another thread had an issue with incompatible versions. Please tell us about the versions you use and try downgrading node to 0.12.x.

The way you use the token is fine.

Community
  • 1
  • 1
michaelbahr
  • 4,837
  • 2
  • 39
  • 75
  • I uninstalled node.js and reinstalled node v0.12.7, npm v2.11.3, coffee v1.10.0. Now when I try to run bin\hubot I get ERROR Error loading scripts from npm package - TypeError: object 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 fs.js:334:14 at FSReqWrap.oncomplete (fs.js:95:15) – codingintherain Jan 04 '16 at 16:52
  • 1
    It turns out the issue was caused because I included hubot-slack in my external-scripts.json file. After I removed it, I was able to run hubot. https://github.com/slackhq/hubot-slack/issues/197 – codingintherain Jan 04 '16 at 17:35
  • 1
    Please put that up as the answer if it solved your question. And maybe explain a bit why ;) – michaelbahr Jan 05 '16 at 08:44