在 Linux 上搭建 Hubot 聊天机器人服务器
1. 先确定安装了 Node.js
如果还没安装Node.js,就先安装Node.js。Node.js是绿色软件,只要解压安装包即可。这里假设已经在/data/node-v5.12.0/目录下安装了 node-v5.12.0 。
2. 安装 Hubot 框架
# npm install -g yo generator-hubot
3. 创建 Hubot 项目
# mkdir myHubot
# cd myHubot
# yo hubot
如果出现错误:
/usr/bin/node: No such file or directory
软连接解决:
# ln -s /data/node-v5.12.0/bin/node /usr/bin/node
# ln -s /data/node-v5.12.0/bin/npm /usr/bin/npm
再试:
# yo hubot
/data/node-v5.12.0/lib/node_modules/yo/node_modules/mkdirp/index.js:90
throw err0;
^
Error: EACCES: permission denied, mkdir '/root/.config'
at Error (native)
at Object.fs.mkdirSync (fs.js:842:18)
at sync (/data/node-v5.12.0/lib/node_modules/yo/node_modules/mkdirp/index.js:71:13)
at Function.sync (/data/node-v5.12.0/lib/node_modules/yo/node_modules/mkdirp/index.js:77:24)
at Object.create.all.get (/data/node-v5.12.0/lib/node_modules/yo/node_modules/configstore/index.js:38:13)
at Object.Configstore (/data/node-v5.12.0/lib/node_modules/yo/node_modules/configstore/index.js:27:44)
at new Insight (/data/node-v5.12.0/lib/node_modules/yo/node_modules/insight/lib/index.js:37:34)
at Object.<anonymous> (/data/node-v5.12.0/lib/node_modules/yo/lib/cli.js:172:11)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
如果出现上面错误,就执行:
# chmod g+rwx /root
然后再试:
# yo hubot
==========================================================================
We're constantly looking for ways to make yo better!
May we anonymously report usage statistics to improve the tool over time?
More info: https://github.com/yeoman/insight & http://yeoman.io
==========================================================================
_____________________________
/ \
//\ | Extracting input for |
\ _____ | self-replication process |
//\ /_____\ \ /
======= |[^_/\_]| /----------------------------
| | _|___@@__|__
+===+/ /// \_\
| |_\ /// HUBOT/\\
|___/\// / \\
\ / +---+
\____/ | |
| //| +===+
\// |xx|
? Owner Paul
? Bot name myhubot
? Description A simple helpful robot for your Company
? Bot adapter campfire
...
出现了上面安装提示界面,输入所有者、Hubot 名称和描述等。输好后会根据输入的创建对应的配置文件,然后进行处理,并且安装一些模块文件等。
等待安装完成就可以使用了,执行下面命令。
# ./bin/hubot
...
[Tue May 02 2017 22:11:16 GMT+0800 (CST)] ERROR Error: listen EADDRINUSE 0.0.0.0:8080
at Object.exports._errnoException (util.js:893:11)
at exports._exceptionWithHostPort (util.js:916:20)
at Server.__dirname.Server.Server._listen2 (net.js:1246:14)
at listen (net.js:1282:10)
at net.js:1391:9
at _combinedTickCallback (internal/process/next_tick.js:77:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
myhubot>
上面提示 8080 端口被占用了,可以指定端口执行,比如换 8100 端口:
# PORT=8100 ./bin/hubot
normalizeTree ?
loadCurrentTree
myhubot> [Sun May 07 2017 15:13:29 GMT+0800 (CST)] WARNING Loading scripts from hubot-scripts.json is deprecated and will be removed in 3.0 (https://github.com/github/hubot-scripts/issues/1113) in favor of packages for each script.
Your hubot-scripts.json is empty, so you just need to remove it.
[Sun May 07 2017 15:13:29 GMT+0800 (CST)] INFO hubot-redis-brain: Using default redis on localhost:6379
[Sun May 07 2017 15:13:29 GMT+0800 (CST)] INFO hubot-redis-brain: Data for hubot brain retrieved from Redis
myhubot>
出现上面显示,说明机器人正常启动。
4. 验证 Hubot 是否安装完成
在命令行里输入 myHubot ping ,如果能看到回复 PONG,说明 Hubot 就安装完成了。
如下:
myhubot> myHubot ping
myhubot> PONG
注:myHubot ping 中的 myHubot 是你的机器人名称。
5. 查看可以使用哪些命令
想查看可以使用哪些命令,在命令行里输入 myHubot help 。
如下:
myhubot> myHubot help
myhubot> Shell: myhubot adapter - Reply with the adapter
myhubot animate me <query> - The same thing as `image me`, except adds a few parameters to try to return an animated GIF instead.
myhubot echo <text> - Reply back with <text>
myhubot help - Displays all of the help commands that Hubot knows about.
myhubot help <query> - Displays all help commands that match <query>.
myhubot image me <query> - The Original. Queries Google Images for <query> and returns a random top result.
myhubot map me <query> - Returns a map view of the area returned by `query`.
myhubot mustache me <url|query> - Adds a mustache to the specified URL or query result.
myhubot ping - Reply with pong
myhubot pug bomb N - get N pugs
myhubot pug me - Receive a pug
myhubot the rules - Make sure hubot still knows the rules.
myhubot time - Reply with current time
myhubot translate me <phrase> - Searches for a translation for the <phrase> and then prints that bad boy out.
myhubot translate me from <source> into <target> <phrase> - Translates <phrase> from <source> into <target>. Both <source> and <target> are optional
ship it - Display a motivation squirrel
myhubot>
安装完毕。
参考:
1. http://blog.csdn.net/wang1144/article/details/53442155
2. http://blog.csdn.net/yaoyasong/article/details/51425601
3. http://www.tuicool.com/articles/IjmuIre