Categories
Python

Building a Jabber Bot (Google Talk) with Python and Google App Engine

To develop a Jabber / Google Talk Bot, we first need to enable the XMPP inbound service for the application. Just add the lines:

to your app.yaml file. That would activate the service for our application. Have a look at my application’s app.yaml file:

Now, we have the app configured, we need to do the actual coding. Every GAE app has it’s own IM id: [application_id]@appspot.com 🙂 There are other extensive IDs also available but for this task we will use this format. So, my app has the ID: masnun-test@appspot.com as it’s Jabber / Google Talk ID. If the user adds this ID to his/her contact list, it’ll auto accept the friend invitation and appear online. Now when he/she sends a message, the message is sent as a POST request to the url: /_ah/xmpp/message/chat/ . This URL is not publicly accessible without admin rights. Our app can handle this URL like any other URL. So we need to setup a request handler for any POST request to this URL.

GAE has a nice API for it’s XMPP service which lets us build a Message object directly from the POSTed data. We will do that. Extract the message parts and send a response back. Here is source code for “masnun.py”:

5 replies on “Building a Jabber Bot (Google Talk) with Python and Google App Engine”

Thank, can you help me some code to bot chat can reply from excel or txt file database

Comments are closed.