Skip to content

johnakers/virgil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

virgil

virgil

It was created with the help of maxdeviant and the work on Nouvion

Wrriten up as of May 2, 2015

Named after the Roman poet... Virgil is a Slack bot, created in Ruby, that you can incorporate into your Slack.

2022 note

THIS IS DEPRECATED. THERE ARE BETTER WAYS TO DO SLACK BOTS. THIS WAS LIKE ONE OF THE FIRST THINGS I EVER DID, AND IS KEPT FOR NOSTALGIA ONLY


######Structure ######Getting Started ######ForecastIO ######Adding on / contributing ######Deployment


Structure

.
|-- Gemfile
|-- Gemfile.lock
|-- LICENSE
|-- README.md
|-- Rakefile
|-- app.rb
|-- lib
|   |-- interpreter.rb
|   |-- modules
|       |-- module.calc.rb
|       |-- module.forecast.rb
|       |-- module.help.rb
|       |-- module.pathfind.rb
|       |-- module.recite.rb
|       |-- module.reference.rb
|       |-- module.self.rb
|       |-- module.whois.rb
|   |-- slack.rb
|   |-- virgil.rb
|-- spec
|   |-- slack
|       |-- slack_spec.rb
|   |-- spec_helper.rb
|   |-- virgil

4 directories, 19 files

Virgil is actually pretty simple. He runs out of app.rb at the root level. interpreter.rb is effectively your controller. It parses the message and acts accordingly, telling Virgil how to respond. slack.rb is what is doing the leg work in connecting to Slack's API.

When you boot the app up and get your server going, virgil is effectively listening and able to connect to Slack's RTM API via a Faye websocket.

Under lib in the modules folder is where things are broken out (e.g. module.forecast.rb is relevant to forecasting weather, module.calc.rb pertains to mathematical calculations and so on).

See Adding on / contributing for more on this.

Getting Started

For now, to get Virgil up and running locally, you're going to need a few things.

  • Ensure that Ruby 2.2.1 is installed, this repo runs that locally.
  • You need to set up the bot user on your Slack. Obviously, name your bot virgil. Yes, it MUST be virgil.

* You'll now see virgil as a team member on [your team directory](https://my.slack.com/team).

* **Click on him and then on configure** and you can give virgil a description, an icon but more importantly, this is where his **API Token** is... it should look something like `xxxx-0123456789-someOTHERnumbers&letters`. Take note of that API token as you'll need it in a bit. * `git clone git@github.com:johnakers/virgil.git` * `cd virgil` * create a new file at the root level called `.env`, refence the [dotenv guide](https://github.com/bkeepers/dotenv) if need be. ```Ruby # in here, you'll need SLACK_TOKEN="xxxx-0123456789-someOTHERnumbers&letters" ``` * `bundle` * You should be able to then run `ruby app.rb` and a [Thin server](http://code.macournoyer.com/thin/) will start. * Head over to `http://localhost:4567/` and you'll notice your terminal will start displaying the messages as they occur. Virgil should say that he's awake in whatever channel as listed as your `is_general` channel. If you do not have one, he may not work (never tested it). You can change this by [going into his code](https://github.com/johnakers/virgil/blob/master/lib/virgil.rb#L21-L32) and altering his `awake` and `sleep` messages, hide them, or alter the channel ids. * in your `#general` channel, type `virgil` and he should respond * `virgil help` will give a list of things he can do

ForecastIO

To get Virgil's virgil forecast [city] working... you'll need a ForecastIO key. To get one, head over to their API and sign up, which will give you a key. It looks something like 380xxxxxa3xxxxx17xxxxxcb9.

In your .env that you previously made

FORECAST_TOKEN="380xxxxxa3xxxxx17xxxxxcb9"

And you should be good to go.

Adding on / contributing

Hypothetically, you have Virgil up and running on your own. Now, you're wondering how to add on to him or, make him something else to work on your own.

First, figure out what term(s) and what text you expect. For instance virgil [method] [relevant text] is the format for pretty much everything.

Once you have a method, add that method to the case statement in interpreter.rb under lib. The [relevant text] is text[1..-1].join(' '). Looking at the other cases is a good idea for reference. As noted in the comments above the case statement, keep your code here concise, with most of the work going on in your module.

Create another file under modules with the relevant name (e.g. forecast.rb is for forecasting the weather). Add the correct require_relative in references.rb under modules as well.

Test it out... prove it works... and you're good to go. If you really want to commit to this, a pull request will suffice.

Deployment

At time of writing this, I do not have virgil deployed anywhere. einhorn, recommneded by maxdeviant paired with deploying via Linode (or another 99.9% up service) seems to be the way to go. If you ping virgil multiple times while its running, you can potentially create multiple instances. einhorn allows you to push code while live and Linode has a good reputation for staying up and a relatively cheap cost. Heroku apps, while popular for deploying with Ruby, go to sleep and using something like kaffeine, could have negative effects as mentioned before.

Fortune favors the bold

About

a Slack-bot like Siri/Cortana ⛔️

Resources

License

Stars

Watchers

Forks

Languages