Skip to content

Commit

Permalink
remove non-mop sms services, point sms.errors to postman-sms.errors
Browse files Browse the repository at this point in the history
  • Loading branch information
KenLSM committed May 29, 2024
1 parent 18d6e37 commit 6a68b77
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 230 deletions.
5 changes: 4 additions & 1 deletion src/app/modules/bounce/bounce.errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { InvalidNumberError, SmsSendError } from '../../services/sms/sms.errors'
import {
InvalidNumberError,
SmsSendError,
} from '../../services/postman-sms/postman-sms.errors'
import { ApplicationError } from '../core/core.errors'

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { MailSendError } from 'src/app/services/mail/mail.errors'
import {
InvalidNumberError,
SmsSendError,
} from 'src/app/services/sms/sms.errors'
} from 'src/app/services/postman-sms/postman-sms.errors'
import { HashingError } from 'src/app/utils/hash'
import * as OtpUtils from 'src/app/utils/otp'
import {
Expand Down
6 changes: 4 additions & 2 deletions src/app/modules/verification/verification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import formsgSdk from '../../config/formsg-sdk'
import { createLoggerWithLabel } from '../../config/logger'
import { MailSendError } from '../../services/mail/mail.errors'
import MailService from '../../services/mail/mail.service'
import {
InvalidNumberError,
SmsSendError,
} from '../../services/postman-sms/postman-sms.errors'
import PostmanSmsService from '../../services/postman-sms/postman-sms.service'
import { InvalidNumberError, SmsSendError } from '../../services/sms/sms.errors'
import { SmsFactory } from '../../services/sms/sms.factory'
import { transformMongoError } from '../../utils/handle-mongo-error'
import { compareHash, HashingError } from '../../utils/hash'
import {
Expand Down
5 changes: 4 additions & 1 deletion src/app/modules/verification/verification.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import {
SmsLimitExceededError,
} from '../../modules/verification/verification.errors'
import { MailSendError } from '../../services/mail/mail.errors'
import { InvalidNumberError, SmsSendError } from '../../services/sms/sms.errors'
import {
InvalidNumberError,
SmsSendError,
} from '../../services/postman-sms/postman-sms.errors'
import { HashingError } from '../../utils/hash'
import {
DatabaseConflictError,
Expand Down
16 changes: 0 additions & 16 deletions src/app/services/sms/sms.errors.ts

This file was deleted.

49 changes: 2 additions & 47 deletions src/app/services/sms/sms.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ import { useMockTwilio } from '../../config/config'
import { ISms, smsConfig } from '../../config/features/sms.config'

import { PrismClient } from './sms.dev.prismclient'
import {
sendAdminContactOtp,
sendBouncedSubmissionSms,
sendFormDeactivatedSms,
sendVerificationOtp,
} from './sms.service'
import { BounceNotificationSmsParams, TwilioConfig } from './sms.types'
import { sendVerificationOtp } from './sms.service'
import { TwilioConfig } from './sms.types'

interface ISmsFactory {
sendVerificationOtp: (
Expand All @@ -20,40 +15,6 @@ interface ISmsFactory {
formId: string,
senderIp: string,
) => ReturnType<typeof sendVerificationOtp>
sendAdminContactOtp: (
recipient: string,
otp: string,
userId: string,
senderIp: string,
) => ReturnType<typeof sendAdminContactOtp>
/**
* Informs recipient that the given form was deactivated. Rejects if SMS feature
* not activated in app.
* @param params Data for SMS to be sent
* @param params.recipient Mobile number to be SMSed
* @param params.recipientEmail The email address of the recipient being SMSed
* @param params.adminId User ID of the admin of the deactivated form
* @param params.adminEmail Email of the admin of the deactivated form
* @param params.formId Form ID of deactivated form
* @param params.formTitle Title of deactivated form
*/
sendFormDeactivatedSms: (
params: BounceNotificationSmsParams,
) => ReturnType<typeof sendFormDeactivatedSms>
/**
* Informs recipient that a response for the given form was lost due to email bounces.
* Rejects if SMS feature not activated in app.
* @param params Data for SMS to be sent
* @param params.recipient Mobile number to be SMSed
* @param params.recipientEmail The email address of the recipient being SMSed
* @param params.adminId User ID of the admin of the form
* @param params.adminEmail Email of the admin of the form
* @param params.formId Form ID of form
* @param params.formTitle Title of form
*/
sendBouncedSubmissionSms: (
params: BounceNotificationSmsParams,
) => ReturnType<typeof sendBouncedSubmissionSms>
}

// Exported for testing.
Expand Down Expand Up @@ -82,12 +43,6 @@ export const createSmsFactory = (smsConfig: ISms): ISmsFactory => {
senderIp,
twilioConfig,
),
sendAdminContactOtp: (recipient, otp, userId, senderIp) =>
sendAdminContactOtp(recipient, otp, userId, senderIp, twilioConfig),
sendFormDeactivatedSms: (params) =>
sendFormDeactivatedSms(params, twilioConfig),
sendBouncedSubmissionSms: (params) =>
sendBouncedSubmissionSms(params, twilioConfig),
}
}

Expand Down
147 changes: 5 additions & 142 deletions src/app/services/sms/sms.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,19 @@ import {
getMongoErrorMessage,
transformMongoError,
} from '../../utils/handle-mongo-error'
import {
InvalidNumberError,
SmsSendError,
} from '../postman-sms/postman-sms.errors'
import { renderVerificationSms } from '../postman-sms/postman-sms.util'

import { InvalidNumberError, SmsSendError } from './sms.errors'
import {
BouncedSubmissionSmsData,
BounceNotificationSmsParams,
FormDeactivatedSmsData,
LogSmsParams,
LogType,
SmsType,
TwilioConfig,
TwilioCredentials,
} from './sms.types'
import {
renderBouncedSubmissionSms,
renderFormDeactivatedSms,
renderVerificationSms,
} from './sms.util'
import getSmsCountModel from './sms_count.server.model'

const logger = createLoggerWithLabel(module)
Expand Down Expand Up @@ -362,139 +358,6 @@ export const sendVerificationOtp = (
})
}

export const sendAdminContactOtp = (
recipient: string,
otp: string,
userId: string,
senderIp: string,
defaultConfig: TwilioConfig,
): ResultAsync<true, SmsSendError | InvalidNumberError> => {
logger.info({
message: `Sending admin contact verification OTP for ${userId}`,
meta: {
action: 'sendAdminContactOtp',
userId,
},
})

const message = `Use the OTP ${otp} to verify your emergency contact number.`

const otpData: AdminContactOtpData = {
admin: userId,
}

return sendSms(
defaultConfig,
otpData,
recipient,
message,
SmsType.AdminContact,
senderIp,
)
}

/**
* Informs recipient that the given form was deactivated.
* @param params Data for SMS to be sent
* @param params.recipient Mobile number to be SMSed
* @param params.recipientEmail The email address of the recipient being SMSed
* @param params.adminId User ID of the admin of the deactivated form
* @param params.adminEmail Email of the admin of the deactivated form
* @param params.formId Form ID of deactivated form
* @param params.formTitle Title of deactivated form
* @param defaultConfig Twilio configuration
*/
export const sendFormDeactivatedSms = (
{
recipient,
recipientEmail,
adminId,
adminEmail,
formId,
formTitle,
}: BounceNotificationSmsParams,
defaultConfig: TwilioConfig,
): ResultAsync<true, SmsSendError | InvalidNumberError> => {
logger.info({
message: `Sending form deactivation notification for ${recipientEmail}`,
meta: {
action: 'sendFormDeactivatedSms',
formId,
},
})

const message = renderFormDeactivatedSms(formTitle)

const smsData: FormDeactivatedSmsData = {
form: formId,
collaboratorEmail: recipientEmail,
recipientNumber: recipient,
formAdmin: {
email: adminEmail,
userId: adminId,
},
}

return sendSms(
defaultConfig,
smsData,
recipient,
message,
SmsType.DeactivatedForm,
)
}

/**
* Informs recipient that a response for the given form was lost due to email bounces.
* @param params Data for SMS to be sent
* @param params.recipient Mobile number to be SMSed
* @param params.recipientEmail The email address of the recipient being SMSed
* @param params.adminId User ID of the admin of the form
* @param params.adminEmail Email of the admin of the form
* @param params.formId Form ID of form
* @param params.formTitle Title of form
* @param defaultConfig Twilio configuration
*/
export const sendBouncedSubmissionSms = (
{
recipient,
recipientEmail,
adminId,
adminEmail,
formId,
formTitle,
}: BounceNotificationSmsParams,
defaultConfig: TwilioConfig,
): ResultAsync<true, SmsSendError | InvalidNumberError> => {
logger.info({
message: `Sending bounced submission notification for ${recipientEmail}`,
meta: {
action: 'sendBouncedSubmissionSms',
formId,
},
})

const message = renderBouncedSubmissionSms(formTitle)

const smsData: BouncedSubmissionSmsData = {
form: formId,
collaboratorEmail: recipientEmail,
recipientNumber: recipient,
formAdmin: {
email: adminEmail,
userId: adminId,
},
}

return sendSms(
defaultConfig,
smsData,
recipient,
message,
SmsType.BouncedSubmission,
)
}

/**
* Retrieves the free sms count for a particular user
* @param userId The id of the user to retrieve the sms counts for
Expand Down
20 changes: 0 additions & 20 deletions src/app/services/sms/sms.util.ts

This file was deleted.

0 comments on commit 6a68b77

Please sign in to comment.