const smpp = require('smpp');
const session = smpp.connect({url: 'smpp://127.0.0.1:2775"', auto_enquire_link_period: 10000,});
session.bind_transceiver({system_id: "Y9Clav9OoiWu3I0", password: "wmpvI02g"}, function (pdu) {
if (pdu.command_status === 0) { //Successfully bound
console.log("Successfully bound!");
session.submit_sm({
destination_addr: "12345678911", // The destination phone number you want to send a message to
source_addr_ton: 1, // Type of number of the source address
source_addr_npi: 0, // 0 = Unknown, 1 = ISDN, 3 = Data, 4 = Telex, 5 = SMS, 6 = Radio, 7 = Fax, 8 = Videotelephony
dest_addr_ton: 1, // Type of number of the destination phone number
dest_addr_npi: 1, // 0 = Unknown, 1 = ISDN, 3 = Data, 4 = Telex, 5 = SMS, 6 = Radio, 7 = Fax, 8 = Videotelephony
source_addr: '9929', // The Sender ID or Address, This will be displayed to the destination phone number
registered_delivery: 1, // Set registered delivery (0 = no, 1 = yes)
// message_id: ID, // Message ID
short_message: "Hello world!",
data_coding: 8
}, function(pdu) {
if(pdu.command_status === 0){
console.log("The message successfully sent!");
session.close();
}else {
console.log("Message didn't sent");
session.close();
}
})
}
})
//Error Handling
session.on('error', (e) => {
if(e.code === 'ETIMEOUT') {
console.log("Connection to SMS-C Timeout");
}else if(e.code === 'ECONNREFUSED'){
console.log("Connection to SMS-C Refused")
}else if(e.code === 'EAI_AGAIN'){
console.log("Connection to internet is lost!");
}else {
console.log(`There is something wrong connecting to SMS-C ${e.code}` );
}
})