基于Hubot打造自己的聊天机器人服务(一)

本地运行Hubot

Hubot

Hubot是Github开发并开源的chatbot,但它并不仅仅是一个聊天机器人,Hubot已经广泛应用于Github的日常运维工作,被称为最忙碌的员工。

安装Hubot

Hubot是基于node.js、npm技术体系,使用CoffeeScript语言开发的开源chatbot,github地址:https://github.com/github/hubot

安装 node.js & npm

直接去官网下载安装:https://nodejs.org/

安装Hubot生成器

要运行自己的Hubot,需要通过生成器生成,首先安装generator-hubot

npm install -g yo generator-hubot

生成自己的hubot

mkdir myhubot
cd myhubot
yo hubot

启动myhubot

windows下直接执行hubot命令即可

bin\hubot.cmd

控制台应该可以看到如下信息:

loadDep:basic-auth        ▌ 
loadDep:base64-url        ▌ 
loadDep:debug             ▌ 
loadAllDepsIntoIdealTree  ? 
build:. → linkMans        ▄ 
runTopLevelLifecycles     ? 
myhubot> [Mon May 16 2016 14:55:09 GMT+0800 (中国标准时间)] WARNING Loading scripts from hubot-scripts.json is deprecated and will be remove
d 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.
[Mon May 16 2016 14:55:09 GMT+0800 (中国标准时间)] ERROR hubot-heroku-alive included, but missing HUBOT_HEROKU_KEEPALIVE_URL. `heroku config
:set HUBOT_HEROKU_KEEPALIVE_URL=$(heroku apps:info -s  | grep web-url | cut -d= -f2)`
[Mon May 16 2016 14:55:10 GMT+0800 (中国标准时间)] INFO hubot-redis-brain: Using default redis on localhost:6379

myhubot>

出现的错误信息是因为默认情况下,hubot使用redis做持久化存储,并支持heroku部署。

为了方便起见,我们可以去掉redis和heroku配置,在./external-scripts.json文件中找到”hubot-heroku-keepalive”和”hubot-redis-brain”并删除即可。

也可以忽略这些错误信息,继续使用hubot。

如何使用myhubot

可以通过help查看hubot支持的指令

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> myhubot pug me
myhubot> http://26.media.tumblr.com/tumblr_lteebc0WeC1qb08qmo1_500.jpg

接下来

至此,本地的myhubot已经可以运行起来,下一步就是扩展myhubot,编写自定义scripts来支持自定义指令。

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值