Google Code offered in: English - Español - 日本語 - 한국어 - Português - Pусский - 中文(简体) - 中文(繁體)
The Message class represents an incoming XMPP message.
Message
is provided by the google.appengine.api.xmpp
module.
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()
The constructor of the Message class is defined as follows:
An incoming XMPP message.
Arguments:
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 senderto
: the XMPP address of the recipient (an address for the application)body
: the body content of the XMPP messageThe Message class provides the following read-only properties:
The XMPP address of the sender of the message.
The XMPP address of the recipient of the message, an address for the application.
The body content of the XMPP message.
Provided by google.appengine.ext.webapp.xmpp_handlers
: the "command" of the XMPP message.
Provided by google.appengine.ext.webapp.xmpp_handlers
: the "command" argument.
Message instances have the following method:
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:
The type of the message, one of the types allowed by RFC 3921. See send_message() for more information.
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.