Skip to content
Back to top
View this page

# Message Stanza

class slixmpp.stanza.Message(*args, recv=False, **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.

  chat()

    Set the message type to ‘chat’.

  del_mucnick()

    Dummy method to prevent deletion.

  del_mucroom()

    Dummy method to prevent deletion.

  del_parent_thread()

    Delete the message thread’s parent reference.

  get_mucnick()

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

    Read-only stanza interface.

    Return type:

      `str`

  get_mucroom()

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

    Read-only stanza interface.

    Return type:

      str

  get_parent_thread()

    Return the message thread’s parent thread.

    Return type:

      str

  get_type()

    Return the message type.

    Overrides default stanza interface behavior.

    Returns ‘normal’ if no type attribute is present.

    Return type:

      `Literal`[`'chat'`, `'error'`, `'groupchat'`, `'headline'`, `'normal'`]

  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', 'thread'}

    Added 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()

    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'>, 'failure': <class 'slixmpp.plugins.xep_0323.stanza.sensordata.Failure'>, 'fields': <class 'slixmpp.plugins.xep_0323.stanza.sensordata.Fields'>, 'pubsub_event': <class 'slixmpp.plugins.xep_0060.stanza.pubsub_event.Event'>, 'set': <class 'slixmpp.plugins.xep_0325.stanza.control.ControlSet'>, 'started': <class 'slixmpp.plugins.xep_0323.stanza.sensordata.Started'>}

    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)

    Added 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'>, '{urn:xmpp:iot:control}set': <class 'slixmpp.plugins.xep_0325.stanza.control.ControlSet'>, '{urn:xmpp:iot:sensordata}failure': <class 'slixmpp.plugins.xep_0323.stanza.sensordata.Failure'>, '{urn:xmpp:iot:sensordata}fields': <class 'slixmpp.plugins.xep_0323.stanza.sensordata.Fields'>, '{urn:xmpp:iot:sensordata}started': <class 'slixmpp.plugins.xep_0323.stanza.sensordata.Started'>}

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

  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.

    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)

    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.

    Parameters:

      value (str) – identifier of the thread

  sub_interfaces: ClassVar[set[str]] = {'body', '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.