English ▼
Skip to page content Skip to main navigation
e.g. "templates" or "datastore"

# The Message Class

The Message class represents an incoming XMPP message.

`Message` is provided by the `google.appengine.api.xmpp` module.

- Introduction
- Message()
- Properties:
  - sender
  - to
  - body
  - command
  - arg
- Instance methods:
  - reply()

## Introduction

The Message class constructor takes as an argument a dict-like object with data representing an incoming XMPP message. The keys of the dict must be `from`, `to`, and `body`. For most web application frameworks, the dict can be an object the framework provides that represents form fields parsed from the HTTP POST request initiated by App Engine.

Here is a simple example using the webapp framework:

    from google.appengine.api import xmpp
    from google.appengine.ext import webapp
    from google.appengine.ext.webapp.util import run_wsgi_app

    class XMPPHandler(webapp.RequestHandler):
        def post(self):
            message = xmpp.Message(self.request.POST)
            if message.body[0:5].lower() == 'hello':
                message.reply("Greetings!")

    application = webapp.WSGIApplication([('/_ah/xmpp/message/chat/', XMPPHandler)],
                                         debug=True)

    def main():
        run_wsgi_app(application)

    if __name__ == "__main__":
        main()

## Constructor

The constructor of the Message class is defined as follows:

class Message(vars)

  An incoming XMPP message.

  Arguments:

  vars

    A dict-like object containing the message data, such as an object representing the fields of the POST request for an incoming message. The object must have the following members:

    - `from`: the XMPP address of the sender
    - `to`: the XMPP address of the recipient (an address for the application)
    - `body`: the body content of the XMPP message

## Properties

The Message class provides the following read-only properties:

sender

  The XMPP address of the sender of the message.

to

  The XMPP address of the recipient of the message, an address for the application.

body

  The body content of the XMPP message.

command

  Provided by `google.appengine.ext.webapp.xmpp_handlers`: the "command" of the XMPP message.

arg

  Provided by `google.appengine.ext.webapp.xmpp_handlers`: the "command" argument.

## Instance Methods

Message instances have the following method:

reply(body, message_type=MESSAGE_TYPE_CHAT, raw_xml=False)

  Reply to this message. This is similar to calling the send_message() function using the Message's sender as the sole recipient of the reply, and the Message's recipient address as the sender.

  Arguments:

  body
    The body content of the message.
  message_type

    The type of the message, one of the types allowed by RFC 3921. See send_message() for more information.

  raw_xml
    If `True`, the body is expected to be valid XML that is included verbatim in the XMPP message stanza. If `False`, the body is treated as plain text (XML characters are escaped before being inserted into the XMPP message).

  Returns a status value. See send_message() for more information on possible status values.