import { Injectable } from '@nestjs/common' ; import { ConfigService } from '@nestjs/config' ; import * as twilio from 'twilio' ; /**
 * A wrapper around twilio SDK to make testing easier.
 * Should NOT interact with DB models or do anything smart. Just wrap Twilio.
 */ @ Injectable ( ) export class TwilioService { private twilioClient : twilio . Twilio ; constructor ( private configService ) { this . twilioClient = twilio ( this . configService . get ( 'TWILIOACCOUNTSID' ) , this . configService . get ( 'TWILIOAUTHTOKEN' ) ) ; } /**
     * Get full phone number or return false if phone number isn't real
     */ public async getFullPhoneNumber ( phoneNumber ) { try { return ( await this . twilioClient . lookups . phoneNumbers ( phoneNumber ) . fetch ( ) ) . phoneNumber ; } catch ( err ) { return false ; } } /**
     * Send SMS to phone number using our Twilio number
     */ public async sendSMS ( phoneNumber , message ) { await this . twilioClient . messages . create ( { body : message , from : this . configService . get ( 'TWILIOPHONENUMBER' ) , to : phoneNumber , } ) ; } }