Open niteshtripathi1234 opened 4 years ago
Hi I can help you in this My Whatsapp no +91-7999452711
Hi @niteshtripathi1234 could you paste the piece of code that generates the call?
Actual Message short_message= 'Hello this is Gary at T-Mobile can you please tell me if you are able to view the emojis I sent.Hello this is Gary at T-Mobile can you please tell me if you are able to view the emojis I sent.Hello this is Gary at T-Mobile can you please tell me if you are able to view the emojis I sent.'
const calculateMessageUHD = (sms) => {
//GSM IS NPM Liberary
const info = gsm(sms);
const cref = Math.floor(Math.random() * 255);
return info.parts.map((part, i) => {
const udh = Buffer.alloc(6);
udh.write(String.fromCharCode(0x5), 0);
udh.write(String.fromCharCode(0x0), 1);
udh.write(String.fromCharCode(0x3), 2);
udh.write(String.fromCharCode(cref), 3);
udh.write(String.fromCharCode(info.sms_count), 4);
udh.write(String.fromCharCode(i + 1), 5);
// const message = toUtf8.convert(part);
return {
udh: udh,
message: part // + ''
};
});
};
const UDH = calculateMessageUHD(msg.short_message);
UDH.forEach(part => {
msg.short_message = {
udh: part.udh,
message: part.message,
};
if (sessions[mid % sessions.length]) {
sessions[mid % sessions.length].send(msg);
} else {
console.log('[SESSION broken]');
airbrake.notify({
error: ATL / DEN session broken,
context: {
severity: 'error'
}
});
}
});
// This is my SMPP Session
import * as jackrabbit from 'jackrabbit';
import * as smpp from 'smpp';
import {
config
} from '../config';
import {
IMessage,
IPDU,
SessionProp
} from '../interfaces';
import {
airbrake
} from './airbrake';
import {
WinstonLogger
} from './winston';
export default class Session {
counter: number;
maxCount: number;
timeout: number;
session: any;
submit_sm: Function;
logger: WinstonLogger;
constructor(props: SessionProp) {
this.counter = 0;
this.maxCount = 3;
this.timeout = 20000;
delete smpp.encodings.ASCII;
delete smpp.encodings.LATIN1;
smpp.encodings.default = 'UCS2';
this.session = smpp.connect(props.url);
this.logger = new WinstonLogger({
filename: `session-${+new Date()}.log`,
level: 'info'
});
this.session.on('connect', () => {
console.log('[SMPP client connected]');
this.session.bind_transceiver({
system_id: props.systemId,
password: props.password
}, (pdu) => {
if (pdu.command_status != 0) {
airbrake.notify({
error: `Can't auth in ATL/DEN: ${props.url}`,
context: {
severity: 'error'
}
});
console.log('SMPP bind transceiver error: ' + pdu.command_status);
this.session.close();
this.exitApp(1);
} else {
console.log('[Connected]');
this.enquireLink();
}
});
});
this.session.on('enquire_link', (pdu) => {
this.session.send(pdu.response());
console.log('Responded an enquire link');
});
this.session.on('enquire_link_resp', (pdu) => {
this.counter = 0;
console.log('Received a response to an enquire link');
});
this.session.on('error', (error: Error) => {
console.log('SMPP connection error: ' + error);
airbrake.notify({
error: `ATL/DEN session error: ${props.url}, ${JSON.stringify(error)}`,
context: {
severity: 'error'
}
});
this.session.close();
this.exitApp(1);
});
this.session.on('close', () => {
airbrake.notify({
error: `ATL/DEN session close: ${props.url}`,
context: {
severity: 'error'
}
});
console.log('SMPP connection is closed');
this.exitApp();
});
this.session.on('destroy', () => {
airbrake.notify({
error: `ATL/DEN session destroyed: ${props.url}`,
context: {
severity: 'error'
}
});
console.log('SMPP connection is destroy');
this.exitApp();
});
this.session.on('pdu', (pdu) => {
this.logger.log(pdu);
if (pdu.command === 'deliver_sm') {
const rabbit = jackrabbit(config.rabbitMQUrl);
const task = {
user_message_reference: pdu.user_message_reference,
message_state: pdu.message_state
};
rabbit.default().publish([task], {
key: 'deliver_report'
});
this.session.deliver_sm_resp({
sequence_number: pdu.sequence_number
});
}
});
}
enquireLink = () => {
if (this.counter < this.maxCount) {
this.session.enquire_link();
this.counter++;
console.log('Enquired a link');
setTimeout(() => {
this.enquireLink();
}, this.timeout);
} else {
console.log('The SMPP connection is dead.');
this.session.close();
this.exitApp();
}
}
exitApp = (code = 0) => {
setTimeout(() => {
if (code > 0) {
process.exit(code);
} else {
process.exit();
}
}, 2000);
}
send = (msg: IMessage) => {
console.log(`[SEND SMS]`, msg);
this.session.submit_sm(msg, (pdu: IPDU) => {
console.log('pdu', pdu);
this.logger.log(pdu);
});
}
}
[SEND SMS] { source_addr: '14043341185',
destination_addr: '12062257133',
short_message:
{ udh: <Buffer 05 00 03 c3 02 01>,
message:
'Hello this is Gary at T-Mobile can you please tell me if you are able to view the emojis I sent.Hello this is Gary at T-Mobile can you please tell me if ' },
source_addr_ton: 1,
source_addr_npi: 1,
dest_addr_ton: 1,
dest_addr_npi: 1,
registered_delivery: 1 }
(node:16256) UnhandledPromiseRejectionWarning: RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= 0 and <= 255. Received 312
at writeU_Int8 (internal/buffer.js:555:11)
at Buffer.writeUInt8 (internal/buffer.js:565:10)
[EDIT] I've edited the comment to properly format code, it was really difficult to read
@niteshtripathi1234 I have to say the problem is not apparent, some part is trying to store a value longer than 1 byte as an 8bit integer, though I feel it has something to do with encoding, I can't see where
Could you provide a stack trace for the unhandled rejection? looking at the stack would really clarify it
I have the same issue RangeError: The value of "value" is out of range. It must be >= 0 and <= 255. Received 445 at new NodeError (node:internal/errors:372:5) at writeU_Int8 (node:internal/buffer:738:11) at Buffer.writeUInt8 (node:internal/buffer:748:10) at Object.write (....\sms\node_modules\smpp\lib\defs.js:87:11) at PDU.toBuffer (....\sms\node_modules\smpp\lib\pdu.js:194:20) at Session.send (....\sms\node_modules\smpp\lib\smpp.js:247:19) at Session.submit_sm (....\sms\node_modules\smpp\lib\smpp.js:317:15) { code: 'ERR_OUT_OF_RANGE' }
I was trying to see if i could submit a message length more than 255. I know my smpp server can accept it and handle it
{ source_addr: '14043341185', destination_addr: '11201233213', short_message: { udh: <Buffer 05 00 03 0c 02 01>, message: 'Message and data rates may apply.\nReply STOP to end or HELP for more options.\nMessage and data rates may apply.\nReply STOP to end or HELP for more option' }, source_addr_ton: 1, source_addr_npi: 1, dest_addr_ton: 1, dest_addr_npi: 1, registered_delivery: 1 } (node:10820) UnhandledPromiseRejectionWarning: RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= 0 and <= 255. Received 312 at writeU_Int8 (internal/buffer.js:555:11)