Tuesday, October 07, 2008

Interacting with Google Calendar via Jabber/XMPP (Google Talk)

So, you've got a machine with PHP on it floating around, and your quickly-add-to-google-calendar extension isn't working for firefox 3.

You could go the ubiquity route, but... what if you wanted something with a bit more personality?

With that in mind, I'd like to share with you all xmppcalendarbot.

He's written in PHP and sits in your buddy list.

There's a bit of setup involved, but it is well worth it.

Get the code

cd ~/
svn checkout http://xmppcalendarbot.googlecode.com/svn/trunk/ xmppcalendarbot
pear channel-discover pear.phpmafia.net
pear install phpmafia/Zend

Other bits to remember: you probably want to make sure the mb_string extension is enabled!

Setup the accounts

If you want, you can set it up to use your own gmail accounts (make sure you have access to google calendar!), or you can create a new set of google accounts just for your bot.

I opted for the second option, so I didn't end up trashing my personal data.

If you go for the two accounts option, make sure that you add your primary gmail account with the ability to manage events and sharing.

Get the details and stick them into a config.php file:

$user = 'you@gmail.com';
$pass = 'fishbarmonkey';

Make rocket go now!

php ~/xmppcalendarbot/main.php

... and add the bot as your friend. It doesn't hurt to log into the account using pidgin to get over this initial hurdle if you need to.

Talking to your new friend


(23:24:53) daniel.oconnor@gmail.com/Home: quit
(23:24:54) your.calbot@gmail.com: Just what do you think you're doing, Dave?...
(23:24:57) your.calbot@gmail.com: Dave...
(23:25:00) your.calbot@gmail.com: I really think I'm entitled to an answer to that question...
(23:25:03) your.calbot@gmail.com: I know everything hasn't been quite right with me, but I can assure you now, very confidently, that it's going to be alright again...

Quit now

(23:30:59) daniel.oconnor@gmail.com/Home: quit now
(23:31:00) your.calbot@gmail.com: Nap time! Zzzzz


(23:27:08) daniel.oconnor@gmail.com/Home: help
(23:27:08) your.calbot@gmail.com: Commands available: quit, restart, help, news, break, agenda, reminder, when


(23:27:58) daniel.oconnor@gmail.com/Home: reminder cook a delicious meal, tomorrow at 7pm
(23:28:04) your.calbot@gmail.com: Mmm hmm, got it.
(23:28:04) your.calbot@gmail.com: Ok: I've booked it in, you'll get a reminder 30 minutes before
(23:28:24) daniel.oconnor@gmail.com/Home: reminder shop for your meal, tomorrow morning 8am
(23:28:26) your.calbot@gmail.com: Mmm hmm, got it.
(23:28:27) your.calbot@gmail.com: Ok: I've booked it in, you'll get a reminder 30 minutes before

When is...

(23:28:44) your.calbot@gmail.com: Found you have 2 event(s) for meal
(23:28:44) your.calbot@gmail.com: 1. cook a delicious meal (2008-10-08 08:30:00am to 2008-10-08 09:30:00am)
(23:28:44) your.calbot@gmail.com: 2. shop for your meal, morning (2008-10-07 09:30:00pm to 2008-10-07 10:30:00pm)


(23:30:19) daniel.oconnor@gmail.com/Home: news http://clockwerx.blogspot.com/atom.xml 3
(23:30:21) your.calbot@gmail.com: Hello! We've got new Atom entries (25), showing up to 3
(23:30:22) your.calbot@gmail.com: Blair Athol to Crafers by CloCkWeRX
(23:30:22) your.calbot@gmail.com: A pox on your XAMPP and or houses (both of them?) by CloCkWeRX
(23:30:22) your.calbot@gmail.com: Asterisk and Sneaky Plans by CloCkWeRX


(23:32:08) daniel.oconnor@gmail.com/Home: agenda tomorrow
(23:32:10) your.calbot@gmail.com: For 2008-10-08 you have 1 event(s)
(23:32:11) your.calbot@gmail.com: 1. cook a delicious meal (2008-10-08 06:00:00pm to 2008-10-08 07:00:00pm)
(23:32:24) daniel.oconnor@gmail.com/Home: agenda today
(23:32:26) your.calbot@gmail.com: For 2008-10-07 you have 1 event(s)
(23:32:27) your.calbot@gmail.com: 1. shop for your meal, morning (2008-10-08 07:00:00am to 2008-10-08 08:00:00am)

What's next?

Obviously I need to iron out some timezone conversion issues and generally provide some polish; but now I have a calendar agent I can ask to book me a holiday.

Specific improvements are going to include things like adding guests to events and working out command syntax.

I'm also going to think about the news reader side of it a bit more.

I can imagine you have an entire entourage of these, and you share them with your friends - one is the group calendar bot, another tells you about a certain RSS feed every hour (svn commits?), another is your identi.ca bot...


Abhinav.Singh said...

Hi Daniel,

Thanks for this wonderful bot. I came across xmpphp through your blog, while I was searching for how to make a browser based jabber client.

The xmpphp works absolutely fine with command line:
1. Accepting messages
2. Receiving statuses

But I am unable to understand how can I browser sync this behaviors. Also how will this xmpphp sends a message across without disconnecting and connecting again.

Hope you got my problem,

Looking for some help and suggestion.


Mark Docken said...

Dude, I love you! This code changed my life lol. Booking stuff through IM is friggin' the bomb!

Easy setup on Ubuntu Lucid. To get Zend/Pear I used:

sudo pear channel-discover pear.zfcampus.org
sudo pear install zfcampus/zf
sudo ln -s /usr/share/php/zf.php /usr/bin/zf.php

For XMPPPHP just did a simple:
apt-get install libxmpp-php