Skip to content

Commit

Permalink
feat: enable support for custom SMS reminder text (#8)
Browse files Browse the repository at this point in the history
* feat: enable custom SMS reminder text

* 0.5.52

* fix(sms-department): declare custom-reminder support

* 0.5.53
  • Loading branch information
LarsSelbekk authored Jan 18, 2024
1 parent b642ca9 commit 130cf2e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@boklisten/bl-post-office",
"version": "0.5.51",
"version": "0.5.53",
"description": "a single module for sending messages to a customer",
"main": "dist/index.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/message-options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export type MessageType =
| "reminder"
| "custom-reminder"
| "receipt"
| "generic"
| "match"
Expand Down Expand Up @@ -27,6 +28,7 @@ export interface MessageOptions {
sequence_number?: number;
mediums?: MessageMediums;
htmlContent?: string;
customContent?: string;
subject?: string;
textBlocks?: TextBlock[];
}
1 change: 1 addition & 0 deletions src/post-office.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export class PostOffice {

switch (options.type) {
case "reminder":
case "custom-reminder":
return await this.delegateToDepartments(
recipients,
options,
Expand Down
12 changes: 11 additions & 1 deletion src/settings/post-office-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export const POST_OFFICE_SETTINGS = {
reminder: {
mediums: ["email", "sms"]
},
"custom-reminder": {
mediums: ["sms"]
},
generic: {
mediums: ["email"]
},
Expand All @@ -13,5 +16,12 @@ export const POST_OFFICE_SETTINGS = {
mediums: ["email"]
}
},
supportedTypes: ["receipt", "reminder", "generic", "match", "booking"]
supportedTypes: [
"receipt",
"reminder",
"custom-reminder",
"generic",
"match",
"booking"
]
};
20 changes: 16 additions & 4 deletions src/sms/handlers/sms.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,25 @@ export class SmsHandler implements DepartmentHandler {
recipient: Recipient,
messageOptions: MessageOptions
): Promise<any> {
let seqNum = messageOptions.sequence_number
? messageOptions.sequence_number
: 0;
let text: string;

if (messageOptions.type === "custom-reminder") {
if (messageOptions.customContent == null) {
throw "custom-reminder type used but messageOptions.customContent not set";
}
text = messageOptions.customContent;
} else {
const seqNum = messageOptions.sequence_number
? messageOptions.sequence_number
: 0;
text =
SMS_SETTINGS.text[messageOptions.type][messageOptions.subtype][seqNum];
}

return await this._smsBroker.send(
recipient.phone as string,
SMS_SETTINGS.fromNumber,
SMS_SETTINGS.text[messageOptions.type][messageOptions.subtype][seqNum],
text,
recipient.message_id
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/sms/sms.department.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { logger } from "../logger";

@injectable()
export class SmsDepartment implements Department {
private supportedTypes = ["reminder", "match"];
private supportedTypes = ["reminder", "custom-reminder", "match"];
private supportedSubtypes = ["partly-payment", "rent", "loan", "none"];

constructor(private _smsHandler: SmsHandler) {}
Expand Down

0 comments on commit 130cf2e

Please sign in to comment.