File: README.markdown

package info (click to toggle)
strophejs-plugin-mam 0.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 96 kB
  • sloc: javascript: 48; makefile: 12
file content (59 lines) | stat: -rw-r--r-- 2,099 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 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");
      }
		});