XMPP is soon finding it’s way into real time applications other than just chat. I have combined JAXL (Jabber XMPP client library written in PHP) and the API from lyricsfly.com to build a real time chat bot which can assist you with lyrics for any song. You can start using it by simply adding [email protected] to your IM account (e.g. Gtalk, Jabber etc). In this blog post, I will explain in brief the working of lyricsfly bot and how you can integrate XMPP into your own application.
Try out [email protected]
Follow the following steps to get the bot working for you:
- Login to your gtalk account using any of the IM available
- Press Add Contact
[email protected]as your chat buddy
- Send a chat message in following format “Song Title – Song Artist” e.g. “one – metallica”
- You should see something like this:
Working of [email protected]alkbots.com with Jaxl
Here is in brief the working of lyricsfly bot using Jaxl client library:
- When someone sends a message like “one – metallica” to the bot,
eventMessage()method is called inside
- eventMessage then extracts the song title and artist name from the message using PHP explode. Filter the title and artist names for allowed characters.
- eventMessage also calls lyricsfly API and fetch the lyrics. Finally it sends the lyrics as message to requester.
- eventMessage also uses memcached to cache the lyrics. It decreases both response time and load on lyricsfly servers
- Bot also keeps a count of number of queries from a particular user. Since it is still under development, currently there is a limit on number of lyrics you can fetch in a single day.
Making your own custom bot
- Checkout latest from the trunk
sabhinav$ svn checkout http://jaxl.googlecode.com/svn/trunk/ jaxl-read-only
- Edit config file with your bot username, password and jabber servers
- Run from command like
- To customize the bot modify
eventPresencemethods of Jaxl class inside
For a full fledged running bot example code, edit index.php and include jaxl4dzone.class.php instead of jaxl.class.php and re-run the bot.
Have fun and enjoy singing songs along with the lyrics.