Tinder: Listening is just as important as speaking
I just released an update to Tinder, the really unofficial Campfire API, that allows listening in on a room:
campfire = Tinder::Campfire.new 'mysubdomain'
campfire.login 'myemail@example.com', 'mypassword'
room = campfire.find_room_by_name 'Room 1'
messages = room.listen
#=> [{:person=>"Brandon", :message=>"I'm getting very sleepy", :user_id=>"148583", :id=>"16434003"}]
#listen takes an option block, which causes it to poll for new messages every 5 seconds and call the block for each message. It works great for heckling (ok, maybe that’s not the intent):
room.listen do |m|
room.speak "You're dumb!" if m[:person] == 'Brandon'
end
Check out my original post for more information about Tinder. Feedback and patches are welcome!
Thanks to Jesse Newland for the listening code.
12 comments
Excellent work Brandon! Our Campfire Bot, which we’ve lovingly named Elsington, is quite a good heckler. I’m interested to see what else comes of this.
Having no luck with listen…
room.listen do |m| room.speak “Test” end
...nothing happens.
Adam,
Hmm, I wonder if 37s deployed something that change how the polling works.
I’m not going to have time to look into it for a while, but patches are appreciated.
Brandon & Adam,
37signals indeed did change something. I spoke to DHH a few minutes ago and he said they deployed a new build of campfire recently. My bot was working fine up until two days ago when they must have made the change.
Huzzah!
I found the issue and I have emailed Brandon about it. I also found some other interesting stuff while digging around in the code.
I added a ping command in my version of tinder, that way if you set the bot to listen, he will ping every 60 seconds to stay logged in.
Josh,
I modified line 121 of room.rb (0.1.3 via gems) so it returns the person name for enter/leave messages too, so now my bot can personally respond to anyone joining the room (or insult them for leaving).
Tim.
Josh,
Did you figure out what has changed in the campfire API to break the marshmallow ‘watch’ command? I’d like to fix our scripts :)
Thanks, Tammer
Here’s a patch against 0.1.4 that keeps Tinder alive for longer than a couple minutes:
http://pastie.caboo.se/129632
Jesse,
Thanks for the patch. This was actually fixed in svn a few weeks ago, I just haven’t released a new version of the gem. Check it out and let me know how it works for you.
I’m stumped on this one: I just added tinder as a publisher to cerberus and I want to be a good little programmer and include a functional test. How do I create a mock for Tinder?
It’d be good if Tinder supported http authenticating proxies – one of the big benefits of campfire is that it works from inside corporate firewalls, but Tinder doesn’t handle this without modifications.
We just deployed chat using this wonderful API on madmimi.com Thank you, thank you! It rocks.
Brandon, This is a lot of fun to play with, and was incredibly easy to get working, but my Ruby isn’t up to par. I’ve begun work on what is effectively a Java port of your approach and put it on Google Code
My grandiose idea is that with a robust-enough Campfire client, and some more tinkering, one might “proxy translate” Campfire API calls into another chat protocol, like Jabber or IRC. The proxy might accept say, IRC connections, and open up a a connection to Campfire with some API and translate back and forth. This way jabber or IRC clients might connect to Campfire rooms. I think this would be useful for say, integrating Campfire into Adium, or running any number of IRC bots.
Anyways thanks for the great software, and cheers!
Speak your mind: