diff --git a/lib/xmpp/index.js b/lib/xmpp/index.js index 301156e..8bdef27 100644 --- a/lib/xmpp/index.js +++ b/lib/xmpp/index.js @@ -101,6 +101,28 @@ module.exports = (logger, config) => { } } let message = body.text() + // handle message delivery receipts for chat + if (type === 'chat') { + let request = stanza.getChild('request') + if (request && + request.attrs.xmlns && + request.attrs.xmlns === 'urn:xmpp:receipts' && + stanza.attrs.id) { + logger.debug(`Message delivery receipt is requested and will be processed`) + const receiptStanza = xml( + 'message', { + to: fromJid + }, + xml( + 'received', { + xmlns: 'urn:xmpp:receipts', + id: stanza.attrs.id + } + ) + ) + xmppClient.send(receiptStanza) + } + } logger.info(`Incoming ${type} message from ${from} (${fromJid.toString()}) to ${to}`) logger.debug(`Message: "${message}"`) let xmppHook = config.getXmppHookAction(to.toString()) diff --git a/test/xmpp.js b/test/xmpp.js index b3e145f..bb8dd08 100644 --- a/test/xmpp.js +++ b/test/xmpp.js @@ -121,17 +121,22 @@ describe('XMPP component', () => { }) describe('Bot receive a message from someone', () => { - it('Should trigger outgoing webhook with valid arguments', (done) => { + it('Should trigger outgoing webhook with valid arguments and send a message delivery receipt', (done) => { simpleXmppEvents.emit('stanza', xml( 'message', { from: 'someone@domain-xmpp.ltd', to: 'bot@domain-xmpp.ltd', - type: 'chat' + type: 'chat', + id: 'fcdd3d8c' }, xml( 'body', { }, - 'This is the message text') + 'This is the message text'), + xml( + 'request', { + xmlns: 'urn:xmpp:receipts' + }) )) sinon.assert.calledOnce(outgoingStub) const args = outgoingStub.args[0] @@ -141,6 +146,19 @@ describe('XMPP component', () => { args[5].should.equal('This is the message text') args[6].should.equal('chat') args[7].should.equal('w1') + sinon.assert.calledOnce(xmppSendStub) + const receiptStanza = xml( + 'message', { + to: 'someone@domain-xmpp.ltd' + }, + xml( + 'received', { + xmlns: 'urn:xmpp:receipts', + id: 'fcdd3d8c' + } + ) + ) + xmppSendStub.args[0][0].should.deep.equal(receiptStanza) done() }) })