google.appengine.api.xmpp package

Summary

XMPP API.

This module allows AppEngine apps to interact with a bot representing that app on the Google Talk network.

Functions defined in this module:

send_message: Sends a chat message to any number of JIDs. send_invite: Sends an invitation to chat to a JID. send_presence: Sends a presence to a JID.

get_presence: Method to get the presence for a JID.

Classes defined in this module:

Message: A class to encapsulate received messages.

Contents

exception google.appengine.api.xmpp.Errorsource

Bases: exceptions.Exception

Base error class for this module.

exception google.appengine.api.xmpp.InvalidJidErrorsource

Bases: google.appengine.api.xmpp.Error

Error that indicates a request for an invalid JID.

exception google.appengine.api.xmpp.InvalidMessageErrorsource

Bases: google.appengine.api.xmpp.Error

Error that indicates a received message was invalid or incomplete.

exception google.appengine.api.xmpp.InvalidShowErrorsource

Bases: google.appengine.api.xmpp.Error

Error that indicates a send presence request has an invalid show.

exception google.appengine.api.xmpp.InvalidStatusErrorsource

Bases: google.appengine.api.xmpp.Error

Error that indicates a send presence request has an invalid status.

exception google.appengine.api.xmpp.InvalidTypeErrorsource

Bases: google.appengine.api.xmpp.Error

Error that indicates a request has an invalid type.

exception google.appengine.api.xmpp.InvalidXmlErrorsource

Bases: google.appengine.api.xmpp.Error

Error that indicates a send message request has invalid XML.

class google.appengine.api.xmpp.Message(vars)source

Bases: object

Encapsulates an XMPP message received by the application.

arg
body
command
reply(body, message_type='chat', raw_xml=False, send_message=send_message)source

Convenience function to reply to a message.

Parameters
  • body -- str: The body of the message

  • raw_xml (message_type,) -- As per send_message.

  • send_message -- Used for testing.

Returns

A status code as per send_message.

Raises

See send_message.

sender
to
exception google.appengine.api.xmpp.NoBodyErrorsource

Bases: google.appengine.api.xmpp.Error

Error that indicates a send message request has no body.

exception google.appengine.api.xmpp.NondefaultModuleErrorsource

Bases: google.appengine.api.xmpp.Error

Error that indicates the XMPP API was used from a non-default module.

google.appengine.api.xmpp.get_presence(jid, from_jid=None, get_show=False)source

Gets the presence for a JID.

Parameters
  • jid -- The JID of the contact whose presence is requested. This may also be a list of JIDs, which also implies get_show (below).

  • from_jid -- The optional custom JID to use for sending. Currently, the default is <appid>@appspot.com. This is supported as a value. Custom JIDs can be of the form <anything>@<appid>.appspotchat.com.

  • get_show -- if True, return a tuple of (is_available, show). If a list of jids is given, this will always be True.

Returns

At minimum, a boolean is_available representing whether the requested JID is available.

If get_show is specified, a tuple (is_available, show) will be given.

If a list of JIDs is given, a list of tuples will be returned, including is_available, show, and an additional boolean indicating if that JID was valid.

Raises
  • InvalidJidError -- Raised if no JID passed in is valid.

  • Error -- if an unspecified error happens processing the request.

google.appengine.api.xmpp.send_invite(jid, from_jid=None)source

Sends an invitation to chat to a JID.

Parameters
  • jid -- The JID of the contact to invite.

  • from_jid -- The optional custom JID to use for sending. Currently, the default is <appid>@appspot.com. This is supported as a value. Custom JIDs can be of the form <anything>@<appid>.appspotchat.com.

Raises
  • InvalidJidError if the JID passed is invalid.

  • Error if an unspecified error happens processing the request.

google.appengine.api.xmpp.send_message(jids, body, from_jid=None, message_type='chat', raw_xml=False)source

Sends a chat message to a list of JIDs.

Parameters
  • jids -- A list of JIDs to send the message to, or a single JID to send the message to.

  • from_jid -- The optional custom JID to use for sending. Currently, the default is <appid>@appspot.com. This is supported as a value. Custom JIDs can be of the form <anything>@<appid>.appspotchat.com.

  • body -- The body of the message.

  • message_type -- Optional type of the message. Should be one of the types specified in RFC 3921, section 2.1.1. An empty string will result in a message stanza without a type attribute. For convenience, all of the valid types are in the MESSAGE_TYPE_* constants in this file. The default is MESSAGE_TYPE_CHAT. Anything else will throw an exception.

  • raw_xml -- Optionally specifies that the body should be interpreted as XML. If this is false, the contents of the body will be escaped and placed inside of a body element inside of the message. If this is true, the contents will be made children of the message.

Returns

list, A list of statuses, one for each JID, corresponding to the result of

sending the message to that JID. Or, if a single JID was passed in, returns the status directly.

Raises
  • InvalidJidError if there is no valid JID in the list.

  • InvalidTypeError if the type argument is invalid.

  • InvalidXmlError if the body is malformed XML and raw_xml is True.

  • NoBodyError if there is no body.

  • Error if another error occurs processing the request.

google.appengine.api.xmpp.send_presence(jid, status=None, from_jid=None, presence_type='', presence_show='')source

Sends a presence to a given JID.

Parameters
  • jid -- A JID to send the presence to.

  • status -- The optional status message. Size is limited to 1KB.

  • from_jid -- The optional custom JID to use for sending. Currently, the default is <appid>@appspot.com. This is supported as a value. Custom JIDs can be of the form <anything>@<appid>.appspotchat.com.

  • presence_type -- Optional type of the presence. This accepts a subset of the types specified in RFC 3921, section 2.2.1. An empty string will result in a presence stanza without a type attribute. For convenience, all of the valid types are in the PRESENCE_TYPE_* constants in this file. The default is PRESENCE_TYPE_AVAILABLE. Anything else will throw an exception.

  • presence_show -- Optional show value for the presence. Should be one of the values specified in RFC 3921, section 2.2.2.1. An empty string will result in a presence stanza without a show element. For convenience, all of the valid types are in the PRESENCE_SHOW_* constants in this file. The default is PRESENCE_SHOW_NONE. Anything else will throw an exception.

Raises
  • InvalidJidError if there is no valid JID in the list.

  • InvalidTypeError if the type argument is invalid.

  • InvalidShowError if the show argument is invalid.

  • InvalidStatusError if the status argument is too large.

  • Error if another error occurs processing the request.

Send feedback about...