Having problems retrieving messages: Using StropheJS and MAM on ejabberd. Returns 403.

Hello, we've been working on an in-browser chat client and have been having difficulty in retrieving message history.

It seems like it would be quite a trivial thing to do but after all the trouble-shooting, I'm still getting the same error, so wondering if anyone could assist with what the problem might be.

I'm using StopheJS and we have ejabberd setup on an EC2 instance. We have the mod_mam module enabled in ejabberd.

The code I'm using to get messages looks like: ----

JS Code

The code below builds the stanza to be sent to the server

          var date, messages = [];
          var options = {
            with  : recipient,
            start : new Date('December 17, 1995 03:24:00').toISOString(),
            end   : new Date().toISOString(),
            max   : 10
          };

          var id = CONNECTION.getUniqueId();

          var attrs = { 'type' : 'set'};
          attrs.to = options['with'];

          var stanza = $iq(attrs).c('query', { 'xmlns' : Strophe.NS.MAM } );

          stanza.c('x',
            {
              'xmlns': Strophe.NS.XFORM,
              'type': 'submit'
            })
            .c('field',
              {
                'var':'FORM_TYPE',
                'type': 'hidden'
              }
            )
            .c('value').t(Strophe.NS.MAM).up().up();

          stanza.c('field', {'var':'with'}).c('value').t(options['with']).up().up();

          $.each(['start', 'end'], function (i, t) {
              if (options[t]) {
                  date = moment(options[t]);
                  if (date.isValid()) {
                      stanza.c('field', {'var':t}).c('value').t(date.format()).up().up();
                  } else {
                      throw new TypeError('archive.query: invalid date provided for: '+t);
                  }
              }
          });

          stanza.up();

          if (options instanceof Strophe.RSM) {
            stanza.cnode(options.toXML());
          } else if (_.intersection(RSM_ATTRIBUTES, _.keys(options)).length) {
            stanza.cnode(new Strophe.RSM(options).toXML());
          }

          CONNECTION.addHandler(function (message) {
            var $msg = $(message), $fin, rsm, i;

            if (typeof callback == "function") {
              $fin = $msg.find('fin[xmlns="'+Strophe.NS.MAM+'"]');

              if ($fin.length) {
                  rsm = new Strophe.RSM({xml: $fin.find('set')[0]});
                  _.extend(rsm, _.pick(options, ['max']));
                  _.extend(rsm, _.pick(options, MAM_ATTRIBUTES));
                  callback(messages, rsm);

                  return false; // We've received all messages, decommission this handler
              } else if (queryid == $msg.find('result').attr('queryid')) {
                  messages.push(message);
              }
              return true;
            } else {
              return false; // There's no callback, so no use in continuing this handler.
            }
          }, Strophe.NS.MAM);

          CONNECTION.sendIQ(stanza, null, function (e) {
            console.error('e', e);
          });

Output

The JS code above creates the following:

<iq type="set" to="kim@xxx-xx-xxx-xxx-xxx.compute-1.amazonaws.com" xmlns="jabber:client" id="3:sendIQ">
  <query xmlns="urn:xmpp:mam:0">
    <x xmlns="jabber:x:data" type="submit">
      <field var="FORM_TYPE" type="hidden">
        <value>urn:xmpp:mam:0</value>
      </field>
      <field var="with">
        <value>kim@xxx-xx-xxx-xxx-xxx.compute-1.amazonaws.com</value>
      </field>
      <field var="start">
        <value>1995-12-17T03:24:00+00:00</value>
      </field>
      <field var="end">
        <value>2015-07-28T10:04:03+01:00</value>
      </field>
    </x>
    <set xmlns="http://jabber.org/protocol/rsm">
      <max>10</max
    </set>
  </query>
</iq>

Response from server

The response from the server.

<iq type="set" to="kim@xx-xx-xxx-xxx-xxx.compute-1.amazonaws.com" xmlns="jabber:client" id="3:sendIQ">
  <query xmlns="urn:xmpp:mam:0">
    // ... Same as above
  </query>
  <error xmlns="jabber:client" code="403" type="auth">
    <forbidden xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
   </error>
</iq>

Again not sure what I'm doing wrong. But everything that I've tried results in a 403. Any ideas?

Hi, Did you succeed this

Hi,

Did you succeed this history with another jabber client? Like Gajim.

I also trying to configure mod_mam on Amazon Machine, but i do not know to test. My topic: https://www.ejabberd.im/forum/25028/how-configure-and-test-modmam-messag...

Hi, Have you succeded with

Hi,

Have you succeded with this? If not, you can try this,

http://stackoverflow.com/questions/31454673/retrieve-messages-on-page-lo...

Syndicate content