OKC.rb Lita Notes
slides: https://gifcannon.s3.us-west-2.amazonaws.com/ReplacingYourFriendsWithRobots.pdf
lita new briankobot-dr
cd briankobot
bundle
lita
Inside Lita:
lita> lita info
lita> lita help
Don't forget to commit!
git init
git add .
git commit -m "Checkpoint 1"
// you could do some fancy git submodule thing here
lita help
lita handler hello-world
cd lita-hello-world
https://docs.lita.io/plugin-authoring/
- try to run
- notice dumb issues in gemspec
- Silly bundler version issue
Basic implementation
Inside the main lib file!
...
route(/^ping/, :pong)
def pong(response)
response.reply("PONG")
end
...
Basic test
https://docs.lita.io/plugin-authoring/testing/#testing-routes
context "When trying to PONG" do
it { is_expected.to route("ping").to(:pong) }
end
Smore tests
it { is_expected.to route("PING").to(:pong) }
it { is_expected.to route("Can I get a PING?").to(:pong) }
it "returns pong" do
send_message("ping")
expect(replies.last).to eq("PONG")
end
module Lita
module Handlers
class OffAndOn < Handler
route(/\s*down\s*/, :off_and_on, command: true)
def off_and_on(response)
response.reply("Have you tried turning it off and on again?")
end
Lita.register_handler(self)
end
end
end
describe Lita::Handlers::OffAndOn, lita_handler: true do
context "something is down" do
it { is_expected.not_to route("something something down something something").to(:off_and_on) }
it { is_expected.to route("#{Lita.config.robot.name} something something down something something").to(:off_and_on) }
it { is_expected.to route("#{Lita.config.robot.name} Heroku's down").to(:off_and_on) }
it "asks you to turn it off an on again" do
send_message("#{Lita.config.robot.name} Heroku's down")
expect(replies.last).to eq("Have you tried turning it off and on again?")
end
end
end
lita heroku's down
change name in config and install the gems
gem "lita-hello-world", path: "./lita-hello-world"
gem "lita-off-and-on", path: "./lita-off-and-on"
gem "lita-slack"
https://github.com/litaio/lita-slack
Lita.configure do |config|
config.robot.adapter = :slack
config.adapters.slack.token = "boooop"
end