Skip to content

Instantly share code, notes, and snippets.

@zdtsw
Created November 24, 2017 09:06
Show Gist options
  • Select an option

  • Save zdtsw/63049244f75e17f253eea26bc6aeec6f to your computer and use it in GitHub Desktop.

Select an option

Save zdtsw/63049244f75e17f253eea26bc6aeec6f to your computer and use it in GitHub Desktop.
a bit about hubot
We use mattermost along with hubot for some internal fun stuff
the settings requires:
1. a server has mattermost running on
2. a server had hubot running on (could be the same server as the one mattermost is, or a dedicated one) in my case, two different servers
3. a jenkins instance (this is only when you want to interact with jenkins for some more serious stuff)
in mattermost, it requires:
1. public channel which hubot can read from (as incoming) and write to (as outgoing)
* remember in mattermost it is not possible to convert a public to private or viceversa , this can be done in slack
2. token generated by outgoing webhook : (example is based on I have a public channel named "Jon"
Content Type: application/json
Channel: Jon
Trigger When: First word match a trigger exactly ( you can use another one as well, just make sure ppl do not like to say "yoda" that much , see my start-hubot.sh config below)
Callback URLs (One Per Line): http://<hostname of hubot server>:8080/hubot/incoming (8080 will be used for sending message from mattermost to hubot, and endpoint need to match start-hubot.sh config below)
After this webhook created, you will see a token "gzbesdbtzbg4jb5xeunrgobzda" (will be used in start-hubot.sh MATTERMOST_TOKEN below)
3. incoming webhook:
Channel: just choose one public channel (my feeling is, it does not really matter which one it is or if need to be the same one in the outgoing webhook)
4. install plugins > npm install hubot-reboot --save
5. get your hubot plugin installed and update package.json and external-scripts.json
6. If you wanna persistant data , can use redis as we set the dependencies below, or just ignor some plugins you do not need
7. to start > start-hubot.sh (have logs to STDOUT) or > nohup ./start-hubot.sh 2>&1 & ( logs in nohup.log)
8. file structure
bin/hubot
external-scripts.json
node_modules/
nohup.out
package.json
scripts/
start-hubot.sh
[
"hubot-diagnostics",
"hubot-help",
"hubot-suggest",
"hubot-google-translate",
"hubot-maps",
"hubot-standup-alarm",
"hubot-redis-brain",
"hubot-dev-excuse-reply",
"hubot-pandapanda",
"hubot-giphy",
"hubot-chhubot-jenkins",
"hubot-welcome",
"hubot-highfive",
"hubot-devopsreactions",
"hubot-rules",
"hubot-reboot"
]
{
"name": "hubot",
"version": "0.0.1",
"private": true,
"author": "R <r@mycompany.com>",
"maintainer": "W <w@mycompany.com>",
"description": "A simple helpful robot for your Company",
"dependencies": {
"coffee-script": "^1.12.7",
"hubot": "^2.19.0",
"hubot-chhubot-jenkins": "^0.1.0",
"hubot-dev-excuse-reply": "0.0.4",
"hubot-devopsreactions": "0.0.2",
"hubot-diagnostics": "0.0.2",
"hubot-giphy": "^0.6.1",
"hubot-google-translate": "^0.2.1",
"hubot-help": "^0.2.2",
"hubot-highfive": "^1.0.4",
"hubot-maps": "0.0.3",
"hubot-mattermost": "^1.0.7",
"hubot-pandapanda": "^0.9.3",
"hubot-reboot": "^1.2.0",
"hubot-redis-brain": "0.0.4",
"hubot-rules": "^0.1.2",
"hubot-scripts": "^2.17.2",
"hubot-standup-alarm": "^0.1.0",
"hubot-suggest": "^1.0.0",
"hubot-welcome": "0.0.3"
},
"engines": {
"node": "0.10.x"
}
}
#!/bin/bash
export MATTERMOST_ENDPOINT=/hubot/incoming
#I put my own jpg on my jenkins' server, coz it servers as web which hubot server can access this jpg, you can have it with any url from internal once "curl" works on it
export MATTERMOST_ICON_URL=https://mycompany.com/config/yoda.jpg
#make sure the url below works. if you have "mattermost.mycompany.com" as a cname, try to use the hostname or convert it
export MATTERMOST_INCOME_URL=http://mattermost.mycompany.com:8065/hooks/ayn7yhrtqtnyfguqz5cbbiuptr
#a bunch or outgoing tokens generated from mattermost webhooks, make sure these channels are public (writeable)
export MATTERMOST_TOKEN="4mk8cebm9prwiqjrjbi9z8pfdw,ws1y7i5qfidq5c7bkhjd17c8za,gzbesdbtzbg4jb5xeunrgobzda"
export HUBOT_WELCOME_MESSAGE="Hey {nick}, welcome to the channel by the awesome Wen! "
#help when debug error, do not really need to set this variable
export HUBOT_LOG_LEVEL="debug"
#if you have your hubot server behind proxy, remember to set these
export HTTP_PROXY="http://sproxy.mycompany.com:8080"
export HTTPS_PROXY="https://sproxy.mycompany.com:8080"
#adding jenkins.mycompany.com is for hubot to query jenkins master
export NO_PROXY="localhost,127.0.0.1,*.mycompany.com,jenkins.mycompany.com"
#I wanna my hubot to be called as "yoda" instead of default "hubot" and I use adapter for mattermost
#you need to type > yoda help rather than >hubot help
bin/hubot --name yoda --adapter mattermost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment