skip down to the 15 comments

BBC Programmes via Instant Messenger

I have been playing with ejabberd, Jabber, XMPP and the various client libraries, specifically the rather wonderfully simple Jabber::Simple and Jabber:Bot.

It all started because I was doing a Fireeagle integration job with a product at work, and was getting frustrated with the fact that it is still not super simple to update my location. It struck me as I stared at my desktop, that I always have Adium running. Wouldn’t it be great if I had a Fireeagle contact that I could just tell my location, and it would go off and update, letting me know when they’re done. Now that part is midway done (post to come), but before I started that, I wanted to research more the workings of a Chatterbot, a computer program that pretends to be a human and can answer basic commands. They have been around for a long time, I remember playing with an IRC bot a while back, getting it to display the last commit messages from Subversion.

So that research turned into a BBC Programmes bot. As I worked on BBC Programmes, I have good knowledge of the site and the data within, and building a bot that integrated with that data seemed a good example of using the restful API available.

If you just want to try this thing out, here are the details of what you need to do.

  1. You need a Gmail or Jabber compatible IM account
  2. You need a Jabber enabled client, I’ve listed a few:
  3. You need to add a new contact: im.bbcprogrammes@gmail.com

This should be it. You should have a new contact appear in your list (They have a BBC logo as an avatar). You can now begin a conversation with this contact. It’s probably best to start with:

-> ?
-> help

BBC Programmes IM BotThe help menu is your best starting point

You can get more detailed help on the various commands with:

-> ? upcoming
-> ? schedule

This should give you enough information to start making queries against the BBC Programmes data.

[NOTE] I should say at this point, that this service is running on my own little virtual box, and I don’t have the funds to have Deep Blue, so the service may well fall over, or be a bit flaky if many people use it. I’m hoping to persuade my bosses to let me host this on the BBC infrastructure at some point, but until then be aware. The beauty of this kind of service though is that if it dies, your contact just goes offline. When the service is brought up again, the contact comes online. Nothing too drastic in other words.

So here’s a few fun commands to get you going:

# show what's currently on 6music
-> now 6music
# show what's currently on radio4
-> next radio4:fm
# show the BBC One London schedule
-> schedule bbcone:london
# show the BBC One London schedule in detail
-> schedule bbcone:london in full
# show upcoming programmes in the format Films available on BBC One in detail
# you can get a full formats list from: http://add.url.com 
-> upcoming films on bbcone:london in full
# show upcoming programmes in the genre Drama/Soaps available in detail
# you can get a full genres list from: http://add.url.com 
-> upcoming drama:soaps in full

BBC Programmes IM botUpcoming films on BBC Two

Hopefully you get the idea, and like I said the help page should give you all the information you need, specifically around getting hold of all the network names available to the bot.

I have a few ideas for future development, specifically around asking for things that you can watch via iPlayer. So you could ask:

-> available films on bbcone:london
-> available eastenders

This is in the pipeline, and I’ll just add the functionality as I get it finished, so keep an eye on the help page for more commands.

Much of the heavy carrying is handled but the brilliant Jabber::Bot written by Brett Stimmerman. I’ve customised it slightly for my needs, by added the ability to deamonize it and also tweaks around the displaying of help information.

The work that remained was to build a ‘recipe’ script that defines and handles all the incoming commands. There is currently no caching or optimisations, but you can get a copy of this to use yourself from:

You can just add the relevant configuration entries at the top of the script and then start in a way that suits you best. I have moved over to using daemontools, but you can still uncomment the relevant lines in the script (see comments) and use:

-> ./bbcbot start

and bingo, you should now have your own BBC Programmes bot to communicate with.

There have been 15 responses to this post.

  1. Nuno Povoa

    Brilliant solution there!

    Did you think of implementing an alarm system?

    Some command like ‘warn ‘ and 10 minutes earlier it would send an IM message to the user that issued the command?

    (and wouldn’t that feature make it easier to persuade your bosses? wink wink)

  2. http://freelancesamurai.wordpress.com/

    Oops, the blog ate my example syntax there, it thought it was an html tag, it should read:

    “warn ┬┤name of the show┬┤”

    also, if that is far too much work to implement, how about a link on schedule times there to an ics that would add an even to ical or google calendar? (I believe the standard is rfc2445)

    if getting your bot to remember stuff is too much work for your virtual box, throw that to the client side. :)

  3. Duncan

    @Nuno you are not the first to ask about alarms :) Currently the bot has no persistent knowledge about the person asking for data, but I don’t think it would be too hard to implement. Watch this space.

    As for the iCal links, that’s now done! you now have an iCal link with every schedule

  4. http://freelancesamurai.wordpress.com/

    @Duncan Ha! Epic! Thanks. :D

  5. Jamie Tetlow

    hey Duncan, i’m gonna change the text ‘view schedule with synopses’ to ‘view schedule in detail’ on our schedules and thought it might be worth syncing the language. would it be ok to change the command to ‘schedule radio4:fm in detail’ rather than ‘schedule radio4:fm in full’?? yes it’s throwing two more key strokes into the world but keeps things nice and consistent for us sticklers.

  6. Duncan

    @jamiet Good plan! that’s all updated now too.

  7. AlansCoachDriver

    This is excellent. I have used this to create 2 calendars in Google for BBCHD and upcoming films.

    I can then use Busy Sync to enable me to see these calendars on my iPhone.

    Just wish I could see more than 1 days schedule for BBCHD and also I’m not getting any results back when looking for upcoming sport. I would expect to see MOTD returned at least.

    Would it be possible to search for specific programmes such as Heroes or Top Gear and also specify not a repeat ?

    Really impressed with it so far though.

  8. Duncan

    @AlansCoachDriver yeah I use BusySync too, really like it.

    Multi day schedules would have to be a multi-request as this is not available through the API. I agree about the sport thing. I think I may of introduced a bug and will look into it, Your final request is on my radar. I think I have a solution in mind, I just need to make it work in IM. I don’t want to make the interface to complex but want people to get to the data as simply as possible.

    Thanks for the comments though, and keep checking for updates.

  9. Tim Martin

    Hi there. I have been using the calendars which are returned from the IM queries for some months now. However since the clocks moved forward to BST I am having problems with 2 of them.

    From some investigation by the guys at BusyMac they have found the following:

    “We found the problem. The BBD sports schedule ics file at webcal://www.bbc.co.uk/bbcone/programmes/genres/sport/schedules/upcoming.ics has a malformed time zone declaration:

    X-WR-TIMEZONE;VALUE=TEXT:Europe/London)

    Note the extraneous parenthesis at the end. iCal ignores the X-WR-TIMEZONE property, so the problem doesn’t show up when you subscribe directly in iCal. Google tries to use the property and ends up thinking the times are in GMT instead of BST (British Summer Time, which is GMT+1).

    The conversion to GMT that Google is making throws off BusySync when syncing with Google. Since there is not a valid calendar time zone, they assume the times are in local time, which is the reason they are off by an hour in London and off by even more hours here.”

    I’d be grateful if you could check this out as it may affect several of your calendars.

    Thanks
    Tim

  10. Duncan

    @Tim, Thanks very much for this. I will pass this on to the team to look into, and try and get a fix in place ASAP

  11. Tim Martin

    That’s great thanks.

    The guys at Busymac have also said they reported the problem to Google as well

    http://code.google.com/p/gdata-issues/issues/detail?id=1151

  12. Duncan

    It’s been fixed, and they tell me there will be a new release this week some time.

  13. Tim Martin

    All looks to be OK now and I’m seeing the correct times now.

    Thanks very much for your assistance.

    Ti

  14. Tom

    Hey,

    The bot doesn’t seem to want to accept my request for presence. It’s not appearing online.

  15. Duncan

    @Tom, yeah sorry about that. I’m afraid the bot is running on my little virtual host, and it dies now and again due to lack of memory. I only restart it when I notice. I really need to move it somewhere else, or better still get the BBC to host. I think that would be best!


back to the top