This module stores messages in per-user archives, and allows clients that implement XEP-0313 to access the archive.

This can be used to synchronize conversations between multiple clients even if they are offline when the conversation happened, or for clients to display a conversation history browser to the user.

mod_carbons is a related module that is used for synchronization of conversations between online clients.


Add "mam" to your modules_enabled list:

modules_enabled = {
    -- ...
    -- ...


Option summary

option type default
default_archive_policy boolean or "roster" true
archive_expires_after string "1w"
archive_cleanup_interval number 4*60*60
max_archive_query_results number 50
archive_store string "archive"
dont_archive_namespaces set { "" }

Configuring a storage backend

mod_mam uses the store "archive". See Prosodys data storage documentation for information on how to configure storage.

For example, to use mod_storage_sql only for MAM archives:

storage = {
  archive = "sql";

If no archive-capable storage backend can be opened then an in-memory one will be used as fallback.

Legacy message archive

Early versions of mod_mam (which were available in prosody-modules) stored data in a store called 'archive2'. This store is now just called 'archive' in 0.10.

mod_mam in 0.10 can be instructed to use the older store name if you still have data there.

archive_store = "archive2"; -- the old data
storage = {
  archive2 = "sql";

Memory-only storage

For performance and privacy reasons, you might prefer to keep messages in memory only. This works best on smaller servers, and obviously if Prosody restarts then it is possible that some clients may not receive messages. Note that if all clients are offline, messages will still be stored via mod_offline.

-- Example to use memory storage for archives, and sql for everything else
default_storage = "sql"
storage = {
    archive = "memory"

Message matching policy

The MAM protocol includes a way for clients to control what messages should be stored. This allows users to enable or disable archiving by default or for specific contacts.

The server can specify a default policy using default_archive_policy.

default_archive_policy = true
default_archive_policy = Meaning
false Store no messages.
"roster" Store messages to/from contacts in the users roster.
true Store all messages. This is the default.

Archive expiry

Messages in the archive will expire after some time, by default one week. This can be changed by setting archive_expires_after:

archive_expires_after = "1d" -- one day
archive_expires_after = "1w" -- one week, the default
archive_expires_after = "2m" -- two months
archive_expires_after = "1y" -- one year
archive_expires_after = 60 * 60 -- one hour
archive_expires_after = "never" -- keep messages forever

The format is an integer number of seconds or a multiple of a period given by a suffix that can be one of d (day), w (week), m (month) or y (year). No multiplier means seconds.

Query size limits

max_archive_query_results = 20;

This is the largest number of messages that are allowed to be retrieved in one request page. A query that does not fit in one page will include a reference to the next page, letting clients page through the result set. Setting large number is not recommended, as Prosody will be blocked while processing the request and will not be able to do anything else.

doc/modules/mod_mam.txt · Last modified: 2017/09/22 11:55 by Matthew Wild