Skip to content
Back to top
View this page

# XEP-0313: Message Archive Management

XEP-0313 on xmpp.org

class slixmpp.plugins.xep_0313.XEP_0313(xmpp, config=None)

  XEP-0313 Message Archive Management

  get_archive_metadata(jid=None, **iqkwargs)

    Get the archive metadata from a JID.

    Parameters:

      jid (`JID` | `None`) – JID to get the metadata from.

    Return type:

      `Future`[`Iq`]

  async get_configuration_commands(jid, **discokwargs)

    Get the list of MAM advanced configuration commands.

    Changed in version 1.8.0.

    Parameters:

      jid (`JID` | `str` | `None`) – JID to get the commands from.

    Return type:

      `Future`[`Iq`]

  async get_fields(jid=None, **iqkwargs)

    Get MAM query fields.

    Added in version 1.8.0.

    Parameters:

      jid (`JID` | `None`) – JID to retrieve the policy from.

    Return type:

      `Form`

    Returns:

      The Form of allowed options

  async iterate(jid=None, start=None, end=None, with_jid=None, ifrom=None, reverse=False, rsm=None, total=None)

    Iterate over each message of MAM query.

    Added in version 1.8.0.

    Parameters:

      - jid (`JID` | `None`) – Entity holding the MAM records

      - start (`datetime` | `None`) – MAM query start time

      - end (`datetime` | `None`) – MAM query end time

      - with_jid (`JID` | `None`) – Filter results on this JID

      - ifrom (`JID` | `None`) – To change the from address of the query

      - reverse (`bool`) – Get the results in reverse order

      - rsm (`dict`[`str`, `Any`] | `None`) – RSM custom options

      - total (`int` | `None`) – A number of messages received after which the query should stop.

    Return type:

      `AsyncGenerator`[`Message`, `None`]

  retrieve(jid=None, start=None, end=None, with_jid=None, ifrom=None, reverse=False, timeout=None, callback=None, iterator=False, rsm=None)

    Send a MAM query and retrieve the results.

    Parameters:

      - jid (`JID` | `None`) – Entity holding the MAM records

      - start,end (datetime) – MAM query temporal boundaries

      - with_jid (`JID` | `None`) – Filter results on this JID

      - ifrom (`JID` | `None`) – To change the from address of the query

      - reverse (`bool`) – Get the results in reverse order

      - timeout (`int` | `None`) – IQ timeout

      - callback (`Callable`[[`Iq`], `None`] | `None`) – Custom callback for handling results

      - iterator (`bool`) – Use RSM and iterate over a paginated query

      - rsm (`dict`[`str`, `Any`] | `None`) – RSM custom options

    Return type:

      `Awaitable`[`Iq`]

## Stanza elements

class slixmpp.plugins.xep_0313.stanza.End(xml=None, parent=None)

  Metadata about the end of an archive.

      <iq type='result' id='jui8921rr9'>
        <metadata xmlns='urn:xmpp:mam:2'>
          <start id='YWxwaGEg' timestamp='2008-08-22T21:09:04Z' />
          <end id='b21lZ2Eg' timestamp='2020-04-20T14:34:21Z' />
        </metadata>
      </iq>

  get_timestamp()

    Get the timestamp.

    Return type:

      `datetime` | `None`

    Returns:

      The timestamp.

  interfaces: ClassVar[set[str]] = {'id', 'timestamp'}

    Available interfaces:

    - `id`: ID of the first message of the archive

    - `timestamp` (`datetime`): timestamp of the first message of the archive

  name: ClassVar[str] = 'end'

    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 = 'urn:xmpp:mam:2'

    The XML namespace for the element. Given `<foo xmlns="bar" />`, then `namespace = "bar"` should be used. The default namespace is `jabber:client` since this is being used in an XMPP library.

  plugin_attrib: ClassVar[str] = 'end'

    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']

  set_timestamp(value)

    Set the timestamp.

    Parameters:

      value (`datetime` | `str`) – Value of the timestamp (either a datetime or a XEP-0082 timestamp string.

class slixmpp.plugins.xep_0313.stanza.Fin(xml=None, parent=None)

  A MAM fin element (end of query).

      <iq type='result' id='juliet1'>
        <fin xmlns='urn:xmpp:mam:2'>
          <set xmlns='http://jabber.org/protocol/rsm'>
            <first index='0'>28482-98726-73623</first>
            <last>09af3-cc343-b409f</last>
          </set>
        </fin>
      </iq>

  del_results()
  get_results()
    Return type:

      `list`[`Message`]

  interfaces: ClassVar[set[str]] = {'complete', 'results', 'stable'}

    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.

  name: ClassVar[str] = 'fin'

    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 = 'urn:xmpp:mam:2'

    The XML namespace for the element. Given `<foo xmlns="bar" />`, then `namespace = "bar"` should be used. The default namespace is `jabber:client` since this is being used in an XMPP library.

  plugin_attrib: ClassVar[str] = 'mam_fin'

    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']

  set_results(values)
  setup(xml=None)

    Initialize the stanza’s XML contents.

    Will return `True` if XML was generated according to the stanza’s definition instead of building a stanza object from an existing XML object.

    Parameters:

      xml – An existing XML object to use for the stanza’s content instead of generating new XML.

class slixmpp.plugins.xep_0313.stanza.MAM(xml=None, parent=None)

  A MAM Query element.

      <iq type='set' id='juliet1'>
        <query xmlns='urn:xmpp:mam:2'>
          <x xmlns='jabber:x:data' type='submit'>
            <field var='FORM_TYPE' type='hidden'>
              <value>urn:xmpp:mam:2</value>
            </field>
            <field var='with'>
              <value>juliet@capulet.lit</value>
            </field>
          </x>
        </query>
      </iq>

  del_results()
  get_after_id()
  get_before_id()
  get_custom_field(fieldname)
    Return type:

      `str` | `None`

  get_end()
    Return type:

      `datetime` | `None`

  get_fields()
  get_flip_page()
  get_ids()
  get_results()
    Return type:

      `list`[`Message`]

  get_start()
    Return type:

      `datetime` | `None`

  get_with()
    Return type:

      `JID` | `None`

  interfaces: ClassVar[set[str]] = {'after_id', 'before_id', 'end', 'flip_page', 'ids', 'queryid', 'results', 'start', 'with'}

    Available interfaces:

    - `queryid`: The MAM query id

    - `start` and `end`: Temporal boundaries of the query

    - `with`: JID of the other entity the conversation is with

    - `after_id`: Fetch stanzas after this specific ID

    - `before_id`: Fetch stanzas before this specific ID

    - `ids`: Fetch the stanzas matching those IDs

    - `results`: pseudo-interface used to accumulate MAM results during fetch, not relevant for the stanza itself.

  name: ClassVar[str] = 'query'

    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 = 'urn:xmpp:mam:2'

    The XML namespace for the element. Given `<foo xmlns="bar" />`, then `namespace = "bar"` should be used. The default namespace is `jabber:client` since this is being used in an XMPP library.

  plugin_attrib: ClassVar[str] = 'mam'

    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']

  set_after_id(value)
  set_before_id(value)
  set_custom_field(fieldname, value)
  set_end(value)
  set_ids(value)
  set_results(values)
  set_start(value)
  set_with(value)
  setup(xml=None)

    Initialize the stanza’s XML contents.

    Will return `True` if XML was generated according to the stanza’s definition instead of building a stanza object from an existing XML object.

    Parameters:

      xml – An existing XML object to use for the stanza’s content instead of generating new XML.

  sub_interfaces: ClassVar[set[str]] = {'after_id', 'before_id', 'end', 'flip_page', 'ids', 'start', 'with'}

    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.

class slixmpp.plugins.xep_0313.stanza.Metadata(xml=None, parent=None)

  Element containing archive metadata

      <iq type='result' id='jui8921rr9'>
        <metadata xmlns='urn:xmpp:mam:2'>
          <start id='YWxwaGEg' timestamp='2008-08-22T21:09:04Z' />
          <end id='b21lZ2Eg' timestamp='2020-04-20T14:34:21Z' />
        </metadata>
      </iq>

  name: ClassVar[str] = 'metadata'

    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 = 'urn:xmpp:mam:2'

    The XML namespace for the element. Given `<foo xmlns="bar" />`, then `namespace = "bar"` should be used. The default namespace is `jabber:client` since this is being used in an XMPP library.

  plugin_attrib: ClassVar[str] = 'mam_metadata'

    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']

class slixmpp.plugins.xep_0313.stanza.Result(xml=None, parent=None)

  A MAM result payload.

      <message id='aeb213' to='juliet@capulet.lit/chamber'>
        <result xmlns='urn:xmpp:mam:2' queryid='f27' id='28482-98726-73623'>
          <forwarded xmlns='urn:xmpp:forward:0'>
            <delay xmlns='urn:xmpp:delay' stamp='2010-07-10T23:08:25Z'/>
            <message xmlns='jabber:client' from="witch@shakespeare.lit"
                     to="macbeth@shakespeare.lit">
              <body>Hail to thee</body>
            </message>
          </forwarded>
        </result>
      </message>

  interfaces: ClassVar[set[str]] = {'id', 'queryid'}

    Available interfaces:

    - `queryid`: MAM queryid

    - `id`: ID of the result

  name: ClassVar[str] = 'result'

    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 = 'urn:xmpp:mam:2'

    The XML namespace for the element. Given `<foo xmlns="bar" />`, then `namespace = "bar"` should be used. The default namespace is `jabber:client` since this is being used in an XMPP library.

  plugin_attrib: ClassVar[str] = 'mam_result'

    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']

class slixmpp.plugins.xep_0313.stanza.Start(xml=None, parent=None)

  Metadata about the start of an archive.

      <iq type='result' id='jui8921rr9'>
        <metadata xmlns='urn:xmpp:mam:2'>
          <start id='YWxwaGEg' timestamp='2008-08-22T21:09:04Z' />
          <end id='b21lZ2Eg' timestamp='2020-04-20T14:34:21Z' />
        </metadata>
      </iq>

  get_timestamp()

    Get the timestamp.

    Return type:

      `datetime` | `None`

    Returns:

      The timestamp.

  interfaces: ClassVar[set[str]] = {'id', 'timestamp'}

    Available interfaces:

    - `id`: ID of the first message of the archive

    - `timestamp` (`datetime`): timestamp of the first message of the archive

  name: ClassVar[str] = 'start'

    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 = 'urn:xmpp:mam:2'

    The XML namespace for the element. Given `<foo xmlns="bar" />`, then `namespace = "bar"` should be used. The default namespace is `jabber:client` since this is being used in an XMPP library.

  plugin_attrib: ClassVar[str] = 'start'

    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']

  set_timestamp(value)

    Set the timestamp.

    Parameters:

      value (`datetime` | `str`) – Value of the timestamp (either a datetime or a XEP-0082 timestamp string.