Fully implement delivery reports
This commit is contained in:
@@ -3,7 +3,7 @@ import Job from "../Job/Job";
|
|||||||
import Logger from "../Logger";
|
import Logger from "../Logger";
|
||||||
import PduProcessor from "../PDUProcessor/PduProcessor";
|
import PduProcessor from "../PDUProcessor/PduProcessor";
|
||||||
import BindTranscieverReplyProcessor from "../PDUProcessor/Postprocessor/Center/BindTranscieverReplyProcessor";
|
import BindTranscieverReplyProcessor from "../PDUProcessor/Postprocessor/Center/BindTranscieverReplyProcessor";
|
||||||
import DebugPduProcessor from "../PDUProcessor/Postprocessor/Center/DebugPduProcessor";
|
import EnquireLinkReplyProcessor from "../PDUProcessor/Postprocessor/Center/EnquireLinkReplyProcessor";
|
||||||
import SubmitSmReplyProcessor from "../PDUProcessor/Postprocessor/Center/SubmitSmReplyProcessor";
|
import SubmitSmReplyProcessor from "../PDUProcessor/Postprocessor/Center/SubmitSmReplyProcessor";
|
||||||
import ProcessorManager from "../PDUProcessor/ProcessorManager";
|
import ProcessorManager from "../PDUProcessor/ProcessorManager";
|
||||||
import SmppSession from "../SmppSession";
|
import SmppSession from "../SmppSession";
|
||||||
@@ -42,7 +42,7 @@ export default class Center extends SmppSession {
|
|||||||
|
|
||||||
ProcessorManager.attachProcessor(this, ProcessorManager.getProcessor(SubmitSmReplyProcessor.name));
|
ProcessorManager.attachProcessor(this, ProcessorManager.getProcessor(SubmitSmReplyProcessor.name));
|
||||||
ProcessorManager.attachProcessor(this, ProcessorManager.getProcessor(BindTranscieverReplyProcessor.name));
|
ProcessorManager.attachProcessor(this, ProcessorManager.getProcessor(BindTranscieverReplyProcessor.name));
|
||||||
ProcessorManager.attachProcessor(this, ProcessorManager.getProcessor(DebugPduProcessor.name));
|
ProcessorManager.attachProcessor(this, ProcessorManager.getProcessor(EnquireLinkReplyProcessor.name));
|
||||||
|
|
||||||
this.logger = new Logger(`Center-${id}`);
|
this.logger = new Logger(`Center-${id}`);
|
||||||
|
|
||||||
|
|||||||
17
src/MessageIdManager.ts
Normal file
17
src/MessageIdManager.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import {PDU} from "./CommonObjects";
|
||||||
|
|
||||||
|
export default class MessageIdManager {
|
||||||
|
private static messages: {[key: string]: number} = {};
|
||||||
|
|
||||||
|
static addMessageId(message: PDU, id: number): void {
|
||||||
|
this.messages[this.getMessageHash(message)] = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
static getMessageId(message: PDU): number | undefined {
|
||||||
|
return this.messages[this.getMessageHash(message)];
|
||||||
|
}
|
||||||
|
|
||||||
|
private static getMessageHash(message: PDU): string {
|
||||||
|
return btoa(`${message.source_addr}:${message.destination_addr}:${message.short_message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
import SmppSession from "../../../SmppSession";
|
|
||||||
import Postprocessor from "../Postprocessor";
|
|
||||||
|
|
||||||
export default class DebugPduProcessor extends Postprocessor {
|
|
||||||
constructor(type: string) {
|
|
||||||
super(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
|
||||||
return new Promise<any>((resolve, reject) => {
|
|
||||||
if (!!pdu.command && pdu.command === "submit_sm") {
|
|
||||||
session.send(pdu.response(), (replyPdu: any) => {
|
|
||||||
resolve(replyPdu);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import MessageIdManager from "../../../MessageIdManager";
|
||||||
import SmppSession from "../../../SmppSession";
|
import SmppSession from "../../../SmppSession";
|
||||||
import Postprocessor from "../Postprocessor";
|
import Postprocessor from "../Postprocessor";
|
||||||
|
|
||||||
@@ -11,48 +12,35 @@ export default class DeliveryReceiptProcessor extends Postprocessor {
|
|||||||
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
||||||
return new Promise<any>((resolve, reject) => {
|
return new Promise<any>((resolve, reject) => {
|
||||||
if (!!pdu.command && pdu.command === "submit_sm" && pdu.registered_delivery) {
|
if (!!pdu.command && pdu.command === "submit_sm" && pdu.registered_delivery) {
|
||||||
session.send(pdu.response());
|
let drMessage: string = "";
|
||||||
|
let date: string = new Date().toISOString().replace(/T/, '').replace(/\..+/, '').replace(/-/g, '').replace(/:/g, '').substring(2, 12);
|
||||||
|
|
||||||
|
let relatedMessageId: number | undefined = MessageIdManager.getMessageId(pdu);
|
||||||
|
if (relatedMessageId) {
|
||||||
|
drMessage += "id:" + relatedMessageId + " ";
|
||||||
|
drMessage += "sub:001 ";
|
||||||
|
drMessage += "dlvrd:001 ";
|
||||||
|
drMessage += "submit date:" + date + " ";
|
||||||
|
drMessage += "done date:" + date + " ";
|
||||||
|
drMessage += "stat:DELIVRD ";
|
||||||
|
drMessage += "err:000 ";
|
||||||
|
drMessage += "text:";
|
||||||
|
|
||||||
let DRPdu = new smpp.PDU('deliver_sm', {
|
let DRPdu = new smpp.PDU('deliver_sm', {
|
||||||
source_addr: pdu.destination_addr,
|
source_addr: pdu.source_addr,
|
||||||
destination_addr: pdu.source_addr,
|
destination_addr: pdu.destination_addr,
|
||||||
short_message: pdu.short_message
|
short_message: drMessage,
|
||||||
|
esm_class: 4,
|
||||||
});
|
});
|
||||||
console.log(pdu);
|
|
||||||
session.send(DRPdu);
|
session.send(DRPdu);
|
||||||
|
|
||||||
resolve(pdu);
|
resolve(pdu);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private padLeft(str: string, pad: string, length: number): string {
|
||||||
|
return (new Array(length + 1).join(pad) + str).slice(-length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// private void sendDeliveryReceipt(Address mtDestinationAddress, Address mtSourceAddress, String messageId, String text) {
|
|
||||||
// SmppSession session = sessionRef.get();
|
|
||||||
//
|
|
||||||
// DeliverSm deliver = new DeliverSm();
|
|
||||||
// deliver.setEsmClass(SmppConstants.ESM_CLASS_MT_SMSC_DELIVERY_RECEIPT);
|
|
||||||
// deliver.setSourceAddress(mtSourceAddress);
|
|
||||||
// deliver.setDestAddress(mtDestinationAddress);
|
|
||||||
// deliver.setDataCoding(SmppConstants.DATA_CODING_GSM);
|
|
||||||
//
|
|
||||||
// DeliverReportStatus delivered = DeliverReportStatus.DELIVERED;
|
|
||||||
//
|
|
||||||
// DeliveryReceipt deliveryReceipt = new DeliveryReceipt();
|
|
||||||
// deliveryReceipt.setDeliveredCount(1);
|
|
||||||
// deliveryReceipt.setDoneDate(DateTime.now());
|
|
||||||
// deliveryReceipt.setRawErrorCode(delivered.getErrorCode());
|
|
||||||
// deliveryReceipt.setMessageId(messageId);
|
|
||||||
// deliveryReceipt.setStateText(delivered.getStateText());
|
|
||||||
// deliveryReceipt.setSubmitCount(1);
|
|
||||||
// deliveryReceipt.setSubmitDate(DateTime.now());
|
|
||||||
// deliveryReceipt.setText(text);
|
|
||||||
// try {
|
|
||||||
// deliver.setShortMessage(deliveryReceipt.toShortMessage().getBytes());
|
|
||||||
// } catch (SmppInvalidArgumentException e) {
|
|
||||||
// //should not be reached
|
|
||||||
// //ignore
|
|
||||||
// }
|
|
||||||
// sendRequestPdu(session, deliver);
|
|
||||||
// }
|
|
||||||
@@ -11,20 +11,13 @@ export default class EchoPduProcessor extends Postprocessor {
|
|||||||
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
||||||
return new Promise<any>((resolve, reject) => {
|
return new Promise<any>((resolve, reject) => {
|
||||||
if (!!pdu.command && pdu.command === "submit_sm") {
|
if (!!pdu.command && pdu.command === "submit_sm") {
|
||||||
let promises = [];
|
let sentPdu = new smpp.PDU('deliver_sm', {
|
||||||
let replyPromise = session.send(pdu.response());
|
|
||||||
let sendPromise = session.send(new smpp.PDU('deliver_sm', {
|
|
||||||
source_addr: pdu.destination_addr,
|
source_addr: pdu.destination_addr,
|
||||||
destination_addr: pdu.source_addr,
|
destination_addr: pdu.source_addr,
|
||||||
short_message: pdu.short_message
|
short_message: pdu.short_message
|
||||||
}));
|
|
||||||
promises.push(replyPromise);
|
|
||||||
promises.push(sendPromise);
|
|
||||||
Promise.all(promises).then((replyPdus: any) => {
|
|
||||||
resolve(replyPdus);
|
|
||||||
}).catch((error: any) => {
|
|
||||||
reject(error);
|
|
||||||
});
|
});
|
||||||
|
session.send(sentPdu);
|
||||||
|
resolve(sentPdu);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import SmppSession from "../../../SmppSession";
|
||||||
|
import Postprocessor from "../Postprocessor";
|
||||||
|
|
||||||
|
export default class EnquireLinkReplyProcessor extends Postprocessor {
|
||||||
|
constructor(type: string) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!!pdu.command && pdu.command === 'enquire_link') {
|
||||||
|
session.send(pdu.response());
|
||||||
|
resolve(pdu);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
|
import MessageIdManager from "../../../MessageIdManager";
|
||||||
import SmppSession from "../../../SmppSession";
|
import SmppSession from "../../../SmppSession";
|
||||||
import Postprocessor from "../Postprocessor";
|
import Postprocessor from "../Postprocessor";
|
||||||
|
|
||||||
export default class SubmitSmReplyProcessor extends Postprocessor {
|
export default class SubmitSmReplyProcessor extends Postprocessor {
|
||||||
|
private messageIdIterator: number = 0;
|
||||||
|
|
||||||
constructor(type: string) {
|
constructor(type: string) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
@@ -9,7 +12,11 @@ export default class SubmitSmReplyProcessor extends Postprocessor {
|
|||||||
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!!pdu.command && pdu.command === 'submit_sm') {
|
if (!!pdu.command && pdu.command === 'submit_sm') {
|
||||||
session.send(pdu.response());
|
// Add an ID here!
|
||||||
|
let response = pdu.response();
|
||||||
|
response.message_id = this.messageIdIterator++;
|
||||||
|
MessageIdManager.addMessageId(pdu, response.message_id);
|
||||||
|
session.send(response);
|
||||||
resolve(pdu);
|
resolve(pdu);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import Logger from "../Logger";
|
|||||||
import SmppSession from "../SmppSession";
|
import SmppSession from "../SmppSession";
|
||||||
import PduProcessor from "./PduProcessor";
|
import PduProcessor from "./PduProcessor";
|
||||||
import BindTranscieverReplyProcessor from "./Postprocessor/Center/BindTranscieverReplyProcessor";
|
import BindTranscieverReplyProcessor from "./Postprocessor/Center/BindTranscieverReplyProcessor";
|
||||||
import DebugPduProcessor from "./Postprocessor/Center/DebugPduProcessor";
|
|
||||||
import DeliveryReceiptProcessor from "./Postprocessor/Center/DeliveryReceiptProcessor";
|
import DeliveryReceiptProcessor from "./Postprocessor/Center/DeliveryReceiptProcessor";
|
||||||
import EchoPduProcessor from "./Postprocessor/Center/EchoPduProcessor";
|
import EchoPduProcessor from "./Postprocessor/Center/EchoPduProcessor";
|
||||||
|
import EnquireLinkReplyProcessor from "./Postprocessor/Center/EnquireLinkReplyProcessor";
|
||||||
import SubmitSmReplyProcessor from "./Postprocessor/Center/SubmitSmReplyProcessor";
|
import SubmitSmReplyProcessor from "./Postprocessor/Center/SubmitSmReplyProcessor";
|
||||||
import DeliverSmReplyProcessor from "./Postprocessor/Client/DeliverSmReplyProcessor";
|
import DeliverSmReplyProcessor from "./Postprocessor/Client/DeliverSmReplyProcessor";
|
||||||
import Postprocessor from "./Postprocessor/Postprocessor";
|
import Postprocessor from "./Postprocessor/Postprocessor";
|
||||||
@@ -24,7 +24,7 @@ export default class ProcessorManager {
|
|||||||
// This is an IDIOTIC solution, but it works
|
// This is an IDIOTIC solution, but it works
|
||||||
// Try running eb22a43 to find out what's wrong with the previous approach
|
// Try running eb22a43 to find out what's wrong with the previous approach
|
||||||
ProcessorManager.postprocessors = [
|
ProcessorManager.postprocessors = [
|
||||||
new DebugPduProcessor(Center.name),
|
new EnquireLinkReplyProcessor(Center.name),
|
||||||
new EchoPduProcessor(Center.name),
|
new EchoPduProcessor(Center.name),
|
||||||
new DeliverSmReplyProcessor(Client.name),
|
new DeliverSmReplyProcessor(Client.name),
|
||||||
new SubmitSmReplyProcessor(Center.name),
|
new SubmitSmReplyProcessor(Center.name),
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ async function main() {
|
|||||||
|
|
||||||
main();
|
main();
|
||||||
|
|
||||||
// process.on('exit', cleanup);
|
process.on('exit', cleanup);
|
||||||
// process.on('SIGINT', cleanup);
|
process.on('SIGINT', cleanup);
|
||||||
// process.on('SIGUSR1', cleanup);
|
process.on('SIGUSR1', cleanup);
|
||||||
// process.on('SIGUSR2', cleanup);
|
process.on('SIGUSR2', cleanup);
|
||||||
Reference in New Issue
Block a user