Receiving Instant Messages

So far, we’ve written some code, signed up for services, and launched applications, but nothing we’ve done involves sending or receiving instant messages from our users. However, getting all that set up will make those two actions much easier. Since we’re forcing people to log in with their Google accounts, we know that all of the users have an XMPP account that can send and receive messages from the application. In this case, we’re starting with accepting incoming instant messages from users. Accepting messages via XMPP opens up the door to very interesting ways of interacting with users. Building in accepting messages before sending them also helps us get around a security and usability issue without much effort.

The XMPP protocol does not allow users to send messages to other users unless the receiving user has allowed it to happen. This is generally done through an “invitation.” In practice, one user would request a chat session, or invitation, and if the other user accepted it, the chat session would begin. Within our application, we don’t want to be sending chat messages or requests to any unsuspecting users, so to prevent that, we’re going to ensure they send us a message first. Once they do that, our application can send messages freely to the user.

To deal with XMPP in App Engine, we must first announce that we’re going to use XMPP services. This is one of the services that is configured by editing the app.yaml file. Open that file and add the following ...

Get Building the Realtime User Experience now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.