farhadi / node-smpp

SMPP client and server implementation in node.js
MIT License
419 stars 180 forks source link

Support for user-defined TLVs #231

Open aguerrieri opened 1 year ago

aguerrieri commented 1 year ago

It would be a great feature to add support for user-defined TLVS. From what I could see testing the code –and assuming I'm not doing something wrong–, only pre-defined TLVs are supported.

From what I could see, the library recognizes the TLVs and includes them in the PDUs with the HEX value converted to a number and passed as a string. But if I try to use the same approach when sending a message, the TLV is not passed downstream.

EXAMPLE 1 – Sent a message using a server instance, passing a custom TLV, 0x3C02 with the value "TEST" and in the PDU dump I've got:

'15362': <Buffer 41 4c 45 58>

Then I tried to send it using a client instance like this:

import smpp from 'smpp'

const session = smpp.connect({
    url: 'smpp://127.0.0.1:2775',
    auto_enquire_link_period: 30000,
    debug: true
}, function () {
    session.bind_transceiver({
        system_id: 'test',
        password: 'test'
    }, function (pdu) {
        if (pdu.command_status === 0) {
            session.submit_sm({
                destination_addr: '11234567890',
                short_message: 'Test TLV',
                '15362': Buffer.from('TEST')
            }, function (pdu) {
                if (pdu.command_status === 0) {
                    console.log(pdu.message_id)
                }
            })
        }
    })
})

The TLV is not in the MT PDU:

example_1

Then I edited the "tlvs" variable in defs.js and added this at the end:

//Adding my own TLV.
my_own_tlv: {
    id: 0x3c02,
    type: types.tlv.buffer
}

Then tried again using the added TLV:

import smpp from 'smpp'

const session = smpp.connect({
    url: 'smpp://127.0.0.1:2775',
    auto_enquire_link_period: 30000,
    debug: true
}, function () {
    session.bind_transceiver({
        system_id: 'test',
        password: 'test'
    }, function (pdu) {
        if (pdu.command_status === 0) {
            session.submit_sm({
                destination_addr: '11234567890',
                short_message: 'Test TLV',
                my_own_tlv: Buffer.from('TEST')
            }, function (pdu) {
                if (pdu.command_status === 0) {
                    console.log(pdu.message_id)
                }
            })
        }
    })
})

Now the TLV shows up on the packet capture:

example_2