Using Elixir to write Ybot plugins

Ybot - is a customizable bot which was inspired by GitHub's Hubot and written with Erlang programming language. You can create pligin for Ybot in one of following languages:
  • Python
  • Ruby
  • Shell
  • Perl
  • Erlang/OTP
  • Elixir
  • Scala
In this post i will tell you to create Ybot plugin with Elixir. For example we need to create Ybot's plugin which will get information about commits from the Github's repository and will send it to chat if somebody updated your repository. We will use Github API v3. For getting info about Github repository commits we must send request:
GET /repos/:owner/:repo/commits
Let's create Elixir module and send request to the Github API:

Here you can see simple Elixir module with some attributes (@repo, @author and etc...), and sending http 'GET' request to the Github commits API. We must get response like this:

Now we must get some fields from this response, like a commit's author, commit message and etc...:

Ybot has an own storage with REST API, thank you to @tajgur. You can find documentation for it - here. And also Ybot has notifications support, in other words you can set up Ybot that it will execute your plugin by timeout and send result to you. For example you can configure Ybot that it will send to you status of your system every hour and etc... We have memory API in Ybot and we can get last information about repository commits, check it, save last commit if it changed and will send update to the chat. Remeber that Ybot's plugin must write it's result to the STDOUT in the end of execution. Here is the full source code of this plugin:

Put this plugin to Ybot's notifications directory and set up it in configuration file:

Where:
  • github_commits_notifications - plugin name
  • [irc, twitter] - list of transports in which Ybot will send report
  • 600 - timeout in seconds
You can set up any transport which Ybot supports:
  • IRC
  • XMPP
  • Campfire
  • HipChat
  • Skype
  • HTTP
  • FlowDock
  • SMTP
  • Twitter
After running Ybot with this plugin you can receive information about repository commits every 10 minutes if somebody will update repository. Links: @0xAX

Comments