-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
267 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const PATTERN = /^id:(?<messageId>[\w-]+)\ssub:(?<sub>\d+)\sdlvrd:(?<dlvrd>\d+).+stat:(?<stat>\w+)/; | ||
|
||
class InvalidMessageFormatError extends Error {} | ||
class UnsupportedDeliveryStatusError extends Error {} | ||
|
||
class SMPPDeliveryReceipt { | ||
constructor(params) { | ||
this.messageId = params.messageId; | ||
this.status = params.status; | ||
} | ||
|
||
static parse(message) { | ||
const matches = message.match(PATTERN); | ||
|
||
if (matches === null) { | ||
throw new InvalidMessageFormatError("Invalid Delivery Message Format"); | ||
} | ||
|
||
let result = { messageId: matches.groups.messageId }; | ||
if (matches.groups.stat === "DELIVERED" || matches.groups.stat === "DELIVRD") { | ||
result.status = "delivered"; | ||
} else if (matches.groups.stat === "ENROUTE" || matches.groups.stat === "ENROUTE") { | ||
result.status = "sent"; | ||
} else if (matches.groups.stat === "UNDELIVERABLE" || matches.groups.stat === "UNDELIV") { | ||
result.status = "failed"; | ||
} else { | ||
throw new UnsupportedDeliveryStatusError("Unsupported Delivery Status Error"); | ||
} | ||
|
||
return new SMPPDeliveryReceipt(result); | ||
} | ||
} | ||
|
||
export { SMPPDeliveryReceipt, InvalidMessageFormatError, UnsupportedDeliveryStatusError }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.