Get Scamp for Campfire Running on Heroku
From the archive. This was written in 2012 and is kept here unchanged. Some of it has aged better than the rest. It originally lived at /blog/2012/01/16/get-scamp-for-campfire-running-on-heroku/.
Scamp is a great bot framework for Campfire, and here’s how to get a bot up and running in no time on Heroku.
First up, create a new directory for the project and make sure
bundler and heroku gems are installed.
mkdir scampbot;cd scampbot
gem install bundler heroku
Then create a Gemfile
# Gemfile
source :rubygems
gem 'rack'
gem 'scamp'
bundle, set up a git repo, and then create a new Heroku app
bundle
git init
git commit -a -m "boom"
heroku create
As Heroku is happy running Rack based apps, all we need to do here is include a rackup file named config.ru in the root directory.
# config.ru
#!/usr/bin/env ruby
require 'bundler/setup'
require 'rack'
require 'scamp'
# respond to something
run lambda { |env| [200, {'Content-Type'=>'text/plain'}, StringIO.new("It's Alive!\n")] }
This tiny Rack app will just respond to any request with “It’s Alive!” - handy for stopping Heroku apps sleeping on the job. Push it up to Heroku and try it out.
git add .
git commit -m "Adding config.ru"
git push heroku master
heroku open
Next grab your Campfire API key - rather than checking this into the repo create some config vars instead
heroku config:add CAMPFIRE_KEY=your_api_key SUBDOMAIN=your_subdomain
With those variables in place start on Scamp
# config.ru
# do the robot
scamp = Scamp.new(:api_key => ENV['CAMPFIRE_KEY'],
:subdomain => ENV['SUBDOMAIN'])
# add some rooms, can be ID numbers or room names
rooms = ['My awesome room', 1234 ]
Now the basics are in place all that’s left to do is define some simple behaviour and connect to the rooms
# config.ru
scamp.behaviour do
match /^blame (?<scapegoat>.+)$/ do
say "Damnit #{scapegoat}!"
end
end
scamp.connect!(rooms)
And that’s it, push it up to Heroku!
git commit -m "adding scamp"
git push heroku master
Or for the super quick version, clone my example app.
When you’ve got the basic setup in place I highly recommend checking out the Scamp Readme to learn about some of Scamp’s other moves.