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

来源:互联网 发布:淘宝买家怎么刷信誉 编辑:程序博客网 时间:2024/06/05 18:20

本地运行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 myhubotcd myhubotyo 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 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.[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:6379myhubot>

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

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

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

如何使用myhubot

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

myhubot helpmyhubot> Shell: myhubot adapter - Reply with the adaptermyhubot 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 memyhubot> http://26.media.tumblr.com/tumblr_lteebc0WeC1qb08qmo1_500.jpg

接下来

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

0 0
原创粉丝点击