All files / src/authzero smsService.ts

100% Statements 11/11
100% Branches 0/0
100% Functions 3/3
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 3612x 12x       12x       53x         1x                     1x 1x       1x 1x        
import { Injectable } from '@nestjs/common';
import * as AWS from 'aws-sdk';
import { PublishResponse } from 'aws-sdk/clients/sns';
 
@Injectable()
export class SmsService {
  private readonly sns: AWS.SNS;
 
  constructor() {
    this.sns = new AWS.SNS();
  }
 
  async sendSMS(mobileNumber: string, messageToSend: string, senderId: string) {
    // TODO: senderId should be registered in AWS
    const smsOptions = {
      Message: messageToSend,
      PhoneNumber: mobileNumber,
      MessageAttributes: {
        'AWS.SNS.SMS.SMSType': {
          DataType: 'String',
          StringValue: 'Transactional',
        },
      },
    };
 
    console.log(`sending phone registration sms, senderId=${senderId}`);
    return this.sns
      .publish(smsOptions)
      .promise()
      .then((info: PublishResponse) => {
        console.log(`SMS sent = ${JSON.stringify(info)}`);
        return Promise.resolve(true);
      });
  }
}