This is a simple IRC bot written using cinch. The motivation for writing this was so that people using the dublinjs IRC channel could address the bot to get a list of the current ideas for Javascript subject matter talks that are stored as cards in a Trello board.
This incarnation is generalized a little, and it can serve as a (simple) general purpose IRC bot that will communicate with Trello. Configuration of API key and secret, channel name and URLs are driven thru ENV.
The Trello API is used in readonly mode in this code, so all you need to access is your developer key, providing the board is public. Trellobot uses the Trello API Ruby wrapper for this purpose.
At some point in Trellobot's life, it will gain the capability to add cards to lists on a Trello board. That needs a little more development, with addition of Oauth capability to the Trellobot server.
Trellobot understands the commands help, lists and sync. Anything else it interprets as the name of a list on the target board that has been configured. If you send a private message containing quit, accompanied by a passphrase, then Trellobot will disconnect from the server (and exit). Depending on how you have it deployed, it may very well respawn at that point, for example if you run it as a Heroku dyno.
Trellobot has quite a few env vars that is uses. Some of these are optional:
ENV | Content |
---|---|
TRELLO_API_KEY | Your Trello developer API key |
TRELLO_API_SECRET | Your Trello developer API secret |
TRELLO_API_ACCESS_TOKEN_KEY | Your Trello API access token key |
TRELLO_BOARD_ID | The ID for your board |
TRELLO_BOT_CHANNEL | The channel that trellobot should join - form is #channel - don't forget quotes for shell protection! |
TRELLO_BOT_SERVER | The server the trellobot should connect to, defaults to irc.freenode.net |
TRELLO_BOT_NAME | The name the trellobot should use, defaults to trellobot |
TRELLO_BOT_QUIT_CODE | Passcode to cause trellobot to quit - defaults to empty |
Log in as a Trello user and visit this URL to get a key and secret allocated: https://trello.com/1/appKey/generate
You will need an access token to use ruby-trello 0.3.0 or higher, which trellobo depends on. To get it, you'll need to go to this URL:
At the end of this process, You'll be told to give some key to the app, this is what you want to put in the TRELLO_API_ACCESS_TOKEN_KEY
The simplest way to get the id of your board is to
- Browse to it on the trello website
- Observe the URL; it should look something like https://trello.com/board/welcome-board/4e6a8095efa69909ba007382
- The id of your board is the 24-digit hex number at the end of the URL. In this case, it's
4e6a8095efa69909ba007382
Initially, I used the magic of curl for this particular job of discovery. The Trello API covers a lot, as you can read in the beta docs and sometimes it's not immediately obvious where to grab on to find a particular piece of information.
If you know your username, you can list all your boards, with their ids. You then use the id to get API URL of the board. In this example, I'm listing all public boards of the dublinjavascript member and limiting the data returned on the boards to just the name field (nice idea on the filtering guys) of the board. The id comes back for free, of course.
61% curl https://api.trello.com/1/members/dublinjavascript?key=TRELLO_API_KEY\&boards=public\&board_fields=name
{
"id": _the id of the member_,
"fullName": "Dublin JavaScript",
"username": "dublinjavascript",
"gravatar": _the gravatar id for the profile pic_,
"bio": "",
"url": "https://trello.com/dublinjavascript",
"boards": [
{
"id": "4f05b412cf33c09c016a90df", ---- this is what you want
"name": "Dublin Javascript Talks"
}
]
}
The boards[0]['id'] up there is the piece you are looking for - put this into the TRELLO_BOARD_ID
environment variable.
I've seen one weirdness on Heroku where a dyno running Trellobot appeared to disappear off into the dyno grid and keep running, even after it was stopped. This resulted in duplicate bots on the channel. After a couple of days the zombie bot disappeared of its own accord.
Pull requests are welcome :)