Torben
Torben

Reputation: 11

How to fetch message history(archive_msg) from Ejabberd server through Node.js?

I am making a chat system that uses ejabberd, and when a chat window is opened i would like to fetch the archived messages between the two chatting people. Right now all messages are archived with mod_mam in the archive_msg on the ejabberd server, but i dont know how to fetch that using Node.js. I would like to fetch it like some sort of array like you would do with a Json array, from an RestAPI.

I know i am supposed to be following this: https://xmpp.org/extensions/xep-0313.html

But i just dont understand how to implement this practically in node.js, i just see a lot of XML snippets

Can someone give me an idea, maybe some pseudo code to help me?

Upvotes: 0

Views: 542

Answers (1)

Badlop
Badlop

Reputation: 4120

If you are writting a XMPP client that uses an existing XMPP library (like https://github.com/xmppjs/xmpp.js ), maybe that library already includes support to query the MAM archive: some function you can run and returns the archived messages.

If your XMPP library doesn't include MAM support, then it seems you will have to send the XMPP stanzas yourself. For example, sending a stanza like the one in Example 2 of https://xmpp.org/extensions/xep-0313.html#query and when it receives the response of Example 3, parse them.

Hopefully your XMPP library already has functions to help you send and receive such stanzas.

BTW, when you are debugging your client, and you wonder if your client is sending "the right thing"... you can install another well know XMPP client (like Gajim), and compare what they send and what they receive. Gajim has a "XML console" that shows you in realtime what XML he sends and receives.

Upvotes: 1

Related Questions