SleekXMPP classes

class sleekxmpp.Message(*args, **kwargs)

XMPP’s <message> stanzas are a “push” mechanism to send information to other XMPP entities without requiring a response.

Chat clients will typically use <message> stanzas that have a type of either “chat” or “groupchat”.

When handling a message event, be sure to check if the message is an error response.

Example <message> stanzas:
<message to=”user1@example.com” from=”user2@example.com“>
<body>Hi!</body>

</message>

<message type=”groupchat” to=”room@conference.example.com“>
<body>Hi everyone!</body>

</message>

Stanza Interface:
body – The main contents of the message. subject – An optional description of the message’s contents. mucroom – (Read-only) The name of the MUC room that sent the message. mucnick – (Read-only) The MUC nickname of message’s sender.
Attributes:
types – May be one of: normal, chat, headline, groupchat, or error.
Methods:
setup – Overrides StanzaBase.setup. chat – Set the message type to ‘chat’. normal – Set the message type to ‘normal’. reply – Overrides StanzaBase.reply get_type – Overrides StanzaBase interface get_mucroom – Return the name of the MUC room of the message. set_mucroom – Dummy method to prevent assignment. del_mucroom – Dummy method to prevent deletion. get_mucnick – Return the MUC nickname of the message’s sender. set_mucnick – Dummy method to prevent assignment. del_mucnick – Dummy method to prevent deletion.
chat()

Set the message type to ‘chat’.

delMucnick()

Dummy method to prevent deletion.

delMucroom()

Dummy method to prevent deletion.

del_mucnick()

Dummy method to prevent deletion.

del_mucroom()

Dummy method to prevent deletion.

del_parent_thread()

Delete the message thread’s parent reference.

getMucnick()

Return the nickname of the MUC user that sent the message.

Read-only stanza interface.

getMucroom()

Return the name of the MUC room where the message originated.

Read-only stanza interface.

getType()

Return the message type.

Overrides default stanza interface behavior.

Returns ‘normal’ if no type attribute is present.

get_mucnick()

Return the nickname of the MUC user that sent the message.

Read-only stanza interface.

get_mucroom()

Return the name of the MUC room where the message originated.

Read-only stanza interface.

get_parent_thread()

Return the message thread’s parent thread.

get_type()

Return the message type.

Overrides default stanza interface behavior.

Returns ‘normal’ if no type attribute is present.

normal()

Set the message type to ‘normal’.

reply(body=None, clear=True)

Create a message reply.

Overrides StanzaBase.reply.

Sets proper ‘to’ attribute if the message is from a MUC, and adds a message body if one is given.

Arguments:

body – Optional text content for the message. clear – Indicates if existing content should be removed

before replying. Defaults to True.
setMucnick(value)

Dummy method to prevent modification.

setMucroom(value)

Dummy method to prevent modification.

set_mucnick(value)

Dummy method to prevent modification.

set_mucroom(value)

Dummy method to prevent modification.

set_parent_thread(value)

Add or change the message thread’s parent thread.

class sleekxmpp.Presence(*args, **kwargs)

XMPP’s <presence> stanza allows entities to know the status of other clients and components. Since it is currently the only multi-cast stanza in XMPP, many extensions add more information to <presence> stanzas to broadcast to every entry in the roster, such as capabilities, music choices, or locations (XEP-0115: Entity Capabilities and XEP-0163: Personal Eventing Protocol).

Since <presence> stanzas are broadcast when an XMPP entity changes its status, the bulk of the traffic in an XMPP network will be from <presence> stanzas. Therefore, do not include more information than necessary in a status message or within a <presence> stanza in order to help keep the network running smoothly.

Example <presence> stanzas:

<presence />

<presence from=”user@example.com“>
<show>away</show> <status>Getting lunch.</status> <priority>5</priority>

</presence>

<presence type=”unavailable” />

<presence to=”user@otherhost.com” type=”subscribe” />

Stanza Interface:
priority – A value used by servers to determine message routing. show – The type of status, such as away or available for chat. status – Custom, human readable status message.
Attributes:
types – One of: available, unavailable, error, probe,
subscribe, subscribed, unsubscribe, and unsubscribed.

showtypes – One of: away, chat, dnd, and xa.

Methods:
setup – Overrides StanzaBase.setup reply – Overrides StanzaBase.reply set_show – Set the value of the <show> element. get_type – Get the value of the type attribute or <show> element. set_type – Set the value of the type attribute or <show> element. get_priority – Get the value of the <priority> element. set_priority – Set the value of the <priority> element.
delType()

Return the value of the <presence> stanza’s type attribute, or the value of the <show> element.

del_type()

Remove both the type attribute and the <show> element.

exception(e)

Override exception passback for presence.

getPriority()

Return the value of the <presence> element as an integer.

getType()

Return the value of the <presence> stanza’s type attribute, or the value of the <show> element.

get_priority()

Return the value of the <presence> element as an integer.

get_type()

Return the value of the <presence> stanza’s type attribute, or the value of the <show> element.

reply(clear=True)

Set the appropriate presence reply type.

Overrides StanzaBase.reply.

Arguments:
clear – Indicates if the stanza contents should be removed
before replying. Defaults to True.
setPriority(value)

Set the entity’s priority value. Some server use priority to determine message routing behavior.

Bot clients should typically use a priority of 0 if the same JID is used elsewhere by a human-interacting client.

Arguments:
value – An integer value greater than or equal to 0.
setShow(show)

Set the value of the <show> element.

Arguments:
show – Must be one of: away, chat, dnd, or xa.
setType(value)

Set the type attribute’s value, and the <show> element if applicable.

Arguments:
value – Must be in either self.types or self.showtypes.
set_priority(value)

Set the entity’s priority value. Some server use priority to determine message routing behavior.

Bot clients should typically use a priority of 0 if the same JID is used elsewhere by a human-interacting client.

Arguments:
value – An integer value greater than or equal to 0.
set_show(show)

Set the value of the <show> element.

Arguments:
show – Must be one of: away, chat, dnd, or xa.
set_type(value)

Set the type attribute’s value, and the <show> element if applicable.

Arguments:
value – Must be in either self.types or self.showtypes.
class sleekxmpp.Iq(*args, **kwargs)

XMPP <iq> stanzas, or info/query stanzas, are XMPP’s method of requesting and modifying information, similar to HTTP’s GET and POST methods.

Each <iq> stanza must have an ‘id’ value which associates the stanza with the response stanza. XMPP entities must always be given a response <iq> stanza with a type of ‘result’ after sending a stanza of type ‘get’ or ‘set’.

Most uses cases for <iq> stanzas will involve adding a <query> element whose namespace indicates the type of information desired. However, some custom XMPP applications use <iq> stanzas as a carrier stanza for an application-specific protocol instead.

Example <iq> Stanzas:
<iq to=”user@example.com” type=”get” id=”314”>
<query xmlns=”http://jabber.org/protocol/disco#items” />

</iq>

<iq to=”user@localhost” type=”result” id=”17”>
<query xmlns=’jabber:iq:roster’>
<item jid='otheruser@example.net
name=’John Doe’ subscription=’both’>

<group>Friends</group>

</item>

</query>

</iq>

Stanza Interface:
query – The namespace of the <query> element if one exists.
Attributes:
types – May be one of: get, set, result, or error.
Methods:
__init__ – Overrides StanzaBase.__init__. unhandled – Send error if there are no handlers. set_payload – Overrides StanzaBase.set_payload. set_query – Add or modify a <query> element. get_query – Return the namespace of the <query> element. del_query – Remove the <query> element. reply – Overrides StanzaBase.reply send – Overrides StanzaBase.send
delQuery()

Remove the <query> element.

del_query()

Remove the <query> element.

getQuery()

Return the namespace of the <query> element.

get_query()

Return the namespace of the <query> element.

reply(clear=True)

Send a reply <iq> stanza.

Overrides StanzaBase.reply

Sets the ‘type’ to ‘result’ in addition to the default StanzaBase.reply behavior.

Arguments:
clear – Indicates if existing content should be
removed before replying. Defaults to True.
send(block=True, timeout=None, callback=None, now=False, timeout_callback=None)

Send an <iq> stanza over the XML stream.

The send call can optionally block until a response is received or a timeout occurs. Be aware that using blocking in non-threaded event handlers can drastically impact performance. Otherwise, a callback handler can be provided that will be executed when the Iq stanza’s result reply is received. Be aware though that that the callback handler will not be executed in its own thread.

Using both block and callback is not recommended, and only the callback argument will be used in that case.

Overrides StanzaBase.send

Arguments:
block – Specify if the send call will block until a response
is received, or a timeout occurs. Defaults to True.
timeout – The length of time (in seconds) to wait for a response
before exiting the send call if blocking is used. Defaults to sleekxmpp.xmlstream.RESPONSE_TIMEOUT
callback – Optional reference to a stream handler function. Will
be executed when a reply stanza is received.
now – Indicates if the send queue should be skipped and send
the stanza immediately. Used during stream initialization. Defaults to False.
timeout_callback – Optional reference to a stream handler function.
Will be executed when the timeout expires before a response has been received with the originally-sent IQ stanza. Only called if there is a callback parameter (and therefore are in async mode).
setPayload(value)

Set the XML contents of the <iq> stanza.

Arguments:
value – An XML object to use as the <iq> stanza’s contents
setQuery(value)

Add or modify a <query> element.

Query elements are differentiated by their namespace.

Arguments:
value – The namespace of the <query> element.
set_payload(value)

Set the XML contents of the <iq> stanza.

Arguments:
value – An XML object to use as the <iq> stanza’s contents
set_query(value)

Add or modify a <query> element.

Query elements are differentiated by their namespace.

Arguments:
value – The namespace of the <query> element.
unhandled()

Send a feature-not-implemented error if the stanza is not handled.

Overrides StanzaBase.unhandled.

Previous topic

Event Index

Next topic

XEP

This Page