Sunday, October 2, 2011

Since my last post, I had a really hard time making XMPP work using XMPP severs for Linux. Luckily, there was an easier way of doing things without the messy details of installing and hosting your own XMPP server. From this post, How to Write Your Own IM Bot in Less Than 5 Minutes (http://www.labnol.org/internet/tutorial-create-bot-for-gtalk-yahoo-messenger/4354/) I found out that there is a service called IMified which 'hosts' your bots and calls a specific page to do all the processing. As an overview, below is a simple diagram on how IMified works.

So going back to our previous problem, how do we create a location monitoring application which accepts user input thru IM and then displays it to a screen? So with my IMified bot in place, what I did was to code a simple PHP page which accepts POST parameters from IMified and processes it accordingly. Below is the source code for the page which accepts the values sent from IMified

If we would trace what is happening between the user, the IMified service and the webserver you may refer to the steps below:

1.) ymuser sends "currently at the office" to the ymchatbot hosted by IMified
2.) IMified processes the message and then passes the POST values to the page located in our webserver
$_POST['user']; now contains the value ymuser
$_POST['msg']; now contains "currently at the office"
3.) The accepting page now processes the POST values sent which is then saved to a database along with a timestamp generated from the PHP code.
4.) The accepting page replies with "Hi ymuser! Your current location has been logged!"

So now, the values are saved into our MySQL database which is then picked up by another page which is just a regular PHP page. The source code could be found below:

The database schema contains the following fields: uid, ymuser, dlsuuser, time, location, team. All of which are text values save for uid and time which are integer values. So, you might be wondering why I opted having a ymuser field and a dlsuuser field. The two fields just does a mapping of the persons YM id with its corresponding work userid. Its just for formalization.

From our infrastructure monitoring screen, I just added an iframe which just calls the page where the results are displayed.

I have a draft post to the part 2 of my previous post about creating a chatbot, it seems like it has been stuck in draft for quite some time since I was looking for a solution on how to post source code here in Blogger. After trying out some stuff and having failed attempts, I went out for a while and shelved the whole thing.

After trying it out, I've seen a more proper and elegant solution. By enabling the "Show HTML literally" and adding a <pre> </pre> tag on the HTML source of the post one could obtain the formatting above. Hopefully I could finalize my previous post about setting up a chatbot.

About Me

Pogz was the founder of the now defunct PogzNet group and has worked as a SysAd for De La Salle Philippines then at De La Salle University. Currently a Systems Engineer for Cascadeo Corporation. A tech enthusiast, loves reading, silent musician, networking guru, anime buff, cross platform gamer, run-of-the-mill athlete, free form writer and frustrated artist.