https://github.com/strophe/strophejs-plugin-mam
A Strophe.js plugin for message archive management (XEP-0313)
https://github.com/strophe/strophejs-plugin-mam
Last synced: 7 months ago
JSON representation
A Strophe.js plugin for message archive management (XEP-0313)
- Host: GitHub
- URL: https://github.com/strophe/strophejs-plugin-mam
- Owner: strophe
- License: mit
- Created: 2017-01-25T13:41:22.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-09-26T21:28:01.000Z (over 1 year ago)
- Last Synced: 2024-12-10T01:10:34.081Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 18.6 KB
- Stars: 7
- Watchers: 15
- Forks: 12
- Open Issues: 4
-
Metadata Files:
- Readme: README.markdown
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# strophe.mam.js
Plugin for [strophe.js](https://www.npmjs.com/package/strophe.js) to provide Message Archiving Management ([XEP-0313]( http://xmpp.org/extensions/xep-0313.html)).
This plugin requires the [Strophe.RSM](https://github.com/strophe/strophejs-plugin-rsm)
plugin to be loaded as well.
## Install
npm install strophejs-plugin-mam
## Usage
### Querying an archive
`connection.mam.query(where, parameters)`
`where` is the JID hosting the archive. In most cases you will want to
set this to your own bare JID in order query your personal archive, but
it could also be a MUC room, an archiving component or a bot.
`parameters` is an object containing parameters for the query. This can
have properties from two and a half categories:
**Handlers**: `onMessage` which gets called for each message received,
and `onComplete` which is called when the query is completed.
**Filtering**: Half of this is the parameters defined by MAM; `with`,
`start` or `end`, which allow you to filter the results on who the
conversation was *with*, and the time range.
Additionally, parameters from [Result Set Management][RSM] can be
supplied. You would probably be most interested in the `after` and
`before` properties, which allow you to do pagination of the result set,
and the `max` property, which allow you to limit the number of items in
each page. *Note:* Better RSM integration is on the TODO, you currently
have to pick out the `last` or `first` items yourself and pass
those as `after` or `before` respectively.
[RSM]: http://xmpp.org/extensions/xep-0059.html
### Example
To query, for example, your personal archive for conversations with
`juliet@capulet.com` you could do:
connection.mam.query("you@example.com", {
"with": "juliet@capulet.com",
onMessage: function(message) {
console.log("Message from ", $(message).find("forwarded message").attr("from"),
": ", $(message).find("forwarded message body").text());
return true;
},
onComplete: function(response) {
console.log("Got all the messages");
}
});