Add message delivery receipts

This commit is contained in:
nioc 2019-11-22 00:20:04 +01:00
parent 7bdf392fc9
commit 2b09ac6767
2 changed files with 43 additions and 3 deletions

View file

@ -101,6 +101,28 @@ module.exports = (logger, config) => {
} }
} }
let message = body.text() 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.info(`Incoming ${type} message from ${from} (${fromJid.toString()}) to ${to}`)
logger.debug(`Message: "${message}"`) logger.debug(`Message: "${message}"`)
let xmppHook = config.getXmppHookAction(to.toString()) let xmppHook = config.getXmppHookAction(to.toString())

View file

@ -121,17 +121,22 @@ describe('XMPP component', () => {
}) })
describe('Bot receive a message from someone', () => { 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( simpleXmppEvents.emit('stanza', xml(
'message', { 'message', {
from: 'someone@domain-xmpp.ltd', from: 'someone@domain-xmpp.ltd',
to: 'bot@domain-xmpp.ltd', to: 'bot@domain-xmpp.ltd',
type: 'chat' type: 'chat',
id: 'fcdd3d8c'
}, },
xml( xml(
'body', { 'body', {
}, },
'This is the message text') 'This is the message text'),
xml(
'request', {
xmlns: 'urn:xmpp:receipts'
})
)) ))
sinon.assert.calledOnce(outgoingStub) sinon.assert.calledOnce(outgoingStub)
const args = outgoingStub.args[0] const args = outgoingStub.args[0]
@ -141,6 +146,19 @@ describe('XMPP component', () => {
args[5].should.equal('This is the message text') args[5].should.equal('This is the message text')
args[6].should.equal('chat') args[6].should.equal('chat')
args[7].should.equal('w1') 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() done()
}) })
}) })