fritzy / SleekXMPP

Python 2.6+/3.1+ XMPP Library
http://groups.google.com/group/sleekxmpp-discussion
Other
1.1k stars 299 forks source link

How to use XEP-0313 (Message Archive Management) #440

Open Ape opened 7 years ago

Ape commented 7 years ago

I found a plugin for XEP-0313 (Message Archive Management / mam) in SleekXMPP. However, I cannot find any examples or documentation about how it should be used.

I tried the following program, but I cannot retrieve the archived messages. My server supports XEP-0313 and it works with Gajim ja Conversations.

#!/usr/bin/env python3

import sleekxmpp

def test(*args, **kwargs):
    print("test", args, kwargs)

class Bot(sleekxmpp.ClientXMPP):
    def __init__(self, jid, password):
        print("Connecting...")
        super().__init__(jid, password)

        self.add_event_handler("session_start", self.session_start)

    def session_start(self, event):
        print("Connected!")

        self.send_presence()
        self.get_roster()

        self["xep_0313"].retrieve(block=False, callback=test)

xmpp = Bot("user@server.com", "secret")
xmpp.register_plugin("xep_0313")

if xmpp.connect():
    xmpp.process(block=True)

If I run the program I get this error:

(<iq id="f1fab832-9589-4942-8844-9fb4a3653ab4-4" type="error" to="user@server.com/2cbd8a95-902e-4a1c-b992-f8376db5c001"><error type="cancel"><service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /></error></iq>,)
mariohock commented 7 years ago

Hi,

I ran into the same problem. The current plugin only supports an old version of the MAM standard that is most likely not supported by your server.

I updated the plugin code in order to work with current XMPP servers and prepared a pull request (see https://github.com/fritzy/SleekXMPP/pull/456). There is also an example how to use it.

I hope the patch can be applied soon to the "develop" branch.