Message Stanza#

class slixmpp.stanza.Message(*args, recv=False, **kwargs)[source]#

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.

chat()[source]#

Set the message type to ‘chat’.

del_mucnick()[source]#

Dummy method to prevent deletion.

del_mucroom()[source]#

Dummy method to prevent deletion.

del_parent_thread()[source]#

Delete the message thread’s parent reference.

get_mucnick()[source]#

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

Read-only stanza interface.

Return type:

str

get_mucroom()[source]#

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

Read-only stanza interface.

Return type:

str

get_parent_thread()[source]#

Return the message thread’s parent thread.

Return type:

str

get_type()[source]#

Return the message type.

Overrides default stanza interface behavior.

Returns ‘normal’ if no type attribute is present.

Return type:

str

interfaces: ClassVar[Set[str]] = {'body', 'from', 'id', 'mucnick', 'mucroom', 'parent_thread', 'subject', 'thread', 'to', 'type'}#

The set of keys that the stanza provides for accessing and manipulating the underlying XML object. This set may be augmented with the plugin_attrib value of any registered stanza plugins.

lang_interfaces: ClassVar[Set[str]] = {'body', 'subject', 'thread'}#

New in version 1.1.2.

name: ClassVar[str] = 'message'#

The XML tag name of the element, not including any namespace prefixes. For example, an ElementBase object for <message /> would use name = 'message'.

namespace: str = 'jabber:client'#

The default XMPP client namespace

normal()[source]#

Set the message type to ‘normal’.

plugin_attrib: ClassVar[str] = 'message'#

For ElementBase subclasses which are intended to be used as plugins, the plugin_attrib value defines the plugin name. Plugins may be accessed by using the plugin_attrib value as the interface. An example using plugin_attrib = 'foo':

register_stanza_plugin(Message, FooPlugin)
msg = Message()
msg['foo']['an_interface_from_the_foo_plugin']
plugin_attrib_map: ClassVar[Dict[str, Type[ElementBase]]] = {'error': <class 'slixmpp.stanza.error.Error'>, 'pubsub_event': <class 'slixmpp.plugins.xep_0060.stanza.pubsub_event.Event'>}#

A mapping of the plugin_attrib values of registered plugins to their respective classes.

plugin_iterables: ClassVar[Set[Type[ElementBase]]] = {}#

The set of stanza classes that can be iterated over using the ‘substanzas’ interface. Classes are added to this set when registering a plugin with iterable=True:

register_stanza_plugin(DiscoInfo, DiscoItem, iterable=True)

New in version 1.0-Beta5.

plugin_overrides: ClassVar[Dict[str, str]] = {}#

A map of interface operations to the overriding functions. For example, after overriding the set operation for the interface body, plugin_overrides would be:

{'set_body': <some function>}
plugin_tag_map: ClassVar[Dict[str, Type[ElementBase]]] = {'{http://jabber.org/protocol/pubsub#event}event': <class 'slixmpp.plugins.xep_0060.stanza.pubsub_event.Event'>, '{jabber:client}error': <class 'slixmpp.stanza.error.Error'>}#

A mapping of root element tag names (in '{namespace}elementname' format) to the plugin classes responsible for them.

reply(body=None, clear=True)[source]#

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.

Parameters:
  • body (str) – Optional text content for the message.

  • clear (bool) – Indicates if existing content should be removed before replying. Defaults to True.

Return type:

Message

set_mucnick(value)[source]#

Dummy method to prevent modification.

set_mucroom(value)[source]#

Dummy method to prevent modification.

set_parent_thread(value)[source]#

Add or change the message thread’s parent thread.

Parameters:

value (str) – identifier of the thread

sub_interfaces: ClassVar[Set[str]] = {'body', 'subject', 'thread'}#

A subset of interfaces which maps interfaces to direct subelements of the underlying XML object. Using this set, the text of these subelements may be set, retrieved, or removed without needing to define custom methods.