opensoul.org

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.

37signals, api, campfire, gem, ruby, and tinder January 27, 2007

15 Comments

  1. Jesse Newland Jesse Newland January 27, 2007

    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.

  2. Adam Roth Adam Roth February 22, 2007

    Having no luck with listen…

    room.listen do |m|
    room.speak “Test”
    end

    …nothing happens.

  3. Brandon Brandon February 22, 2007

    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.

  4. Josh Owens Josh Owens February 23, 2007

    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.

  5. Josh Owens Josh Owens February 23, 2007

    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.

  6. Tim Blair Tim Blair March 9, 2007

    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).

    :person => msg.gsub(/<(\/)?span>/, '').scan(/<td class=\\"person\\">([^<]+)<\/td>/).to_s

    Tim.

  7. Tammer Saleh Tammer Saleh April 8, 2007

    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

  8. Jesse Newland Jesse Newland December 17, 2007

    Here’s a patch against 0.1.4 that keeps Tinder alive for longer than a couple minutes:

    http://pastie.caboo.se/129632

  9. Brandon Brandon December 17, 2007

    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.

  10. Ken Mayer Ken Mayer December 20, 2007

    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?

  11. Korny Korny March 30, 2008

    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.

  12. Gary Levitt Gary Levitt April 25, 2008

    We just deployed chat using this wonderful API on madmimi.com Thank you, thank you! It rocks.

  13. Alan Alan September 23, 2008

    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!

  14. Anthony Anthony August 27, 2009

    Can someone verify for me that the listen method is currently working properly? I cant seem to make it function as above.

  15. Brandon Brandon August 27, 2009

    Looks like 37Signals deployed some changes to campfire. I’ve pushed a fix:

    http://github.com/collectiveidea/tinder/commit/5f74df202acd22444c8990af963d9d1db0144d80

    The 1.2.1 gem should be available shortly.

Post a Comment

Comments use textile. Anonymous comments will be deleted.

My name is Brandon Keepers. I like to build things, usually in Ruby or JavaScript. I work at GitHub and live in Holland, MI.

Popular Posts