Hubot with Slack(1) — Install

安裝主程式

啊遠
verybuy-dev
4 min readSep 24, 2017

--

cd ~
npm install -g yo generator-hubot

初始化專案

% mkdir ~/hubot/first
% cd ~/hubot/first
% yo hubot

這邊可以加上 git 或其他你習慣的版本控制套件

% git init
% git add .
% git commit -m "Initial commit"

安裝 slack adapter

cd ~/hubot/first
npm install hubot-slack --save

slack 申請 hubot app

https://slack.com/apps/A0F7XDU93-hubot 點 Install

如果連結失效請自行 google

申請完會拿到一組 token ( example: xoxb-246795757414-xxxxxxxxxx)

寫測試 script

cd ~/hubot/first/scrips
vim hello.js

然後貼上

module.exports = function(robot){
robot.respond(/hello/, function(res){
res.send('world');
});
}

測試執行

cd ~/hubot/first
HUBOT_SLACK_TOKEN=xoxb-246795757414-xxxxxxxxxx ./bin/hubot --adapter slack

token 請換成你自己的

接著到 slack 找到 你設定的 hubot 對他說 hello

看有沒有回應 world

有就是基本上設定成功了!

遇到問題

  1. 沒有安裝 coffee script
npm WARN hubot-help@0.2.2 requires a peer of coffee-script@^1.12.6 but none was installed.

解:就安裝他

npm install coffee-script

2. 有警告文字

Your hubot-scripts.json is empty, so you just need to remove it.

就照著指示刪除空的檔案 hubot-scripts.json 即可

3. Error 但有自動修正的樣子

ERROR hubot-heroku-keepalive included, but missing HUBOT_HEROKU_KEEPALIVE_URL. `heroku config:set HUBOT_HEROKU_KEEPALIVE_URL=$(heroku apps:info -s | grep web.url | cut -d= -f2)`

看起來應該是少了什麼設定,我也不知道這是啥,也還不知道怎麼設定

但目前還能跑,先跳過

4. redis 錯誤

INFO hubot-redis-brain: Using default redis on localhost:6379

似乎是我沒有安裝 redis,hubot 把資料存在 redis

安裝完之後重新執行,就會多了一行

[Sun Sep 24 2017 15:05:43 GMT+0800 (CST)] INFO hubot-redis-brain: Using default redis on localhost:6379
[Sun Sep 24 2017 15:05:43 GMT+0800 (CST)] INFO hubot-redis-brain: Initializing new data for hubot brain

好,第一步先到這

參考資料:

http://huli.logdown.com/posts/417258-hubot-a-bot-framework

https://medium.com/@petehouston/install-and-config-redis-on-mac-os-x-via-homebrew-eb8df9a4f298

--

--