mirror of
https://github.com/nioc/xmpp-bot.git
synced 2024-12-04 14:23:35 +01:00
Add message delivery receipts
This commit is contained in:
parent
7bdf392fc9
commit
2b09ac6767
2 changed files with 43 additions and 3 deletions
|
@ -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())
|
||||
|
|
24
test/xmpp.js
24
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()
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue