@qrvey/sms v0.0.5
@qrvey/sms
@qrvey/sms is a lightweight and reliable library to send manage sms messages. It supports different clients such SNS (AWS), ACS (Azure), Twilio, and Vonage.
Installation
You can install the @qrvey/sms package via npm. Run the following command in your terminal:
npm install @qrvey/smsPeer Dependencies
This package has the following peer dependencies:
@aws-sdk/client-sns(v3.x) for interacting with AWS SNS.@azure/communication-sms(v1.x) for interacting with Azure Communication Services.@vonage/server-sdk(v3.x) and@vonage/auth(v1.x) for interacting with Vonage.twilio(v5.x) for interacting with Twilio.
Configuration
To work properly, the package need some env variables. To set the sms provider, you must set the SMS_PROVIDER env variable with one of these values:
AWSAZURETWILIOVONAGE
In case the SMS_PROVIDER env variable is set with an unknown value, you will get a UnknownProvider error. Depending on the provider you must set some variables:
AWS
If you set SMS_PROVIDER = AWS, the following env variables are required:
SMS_PROVIDER_USERNAMEwhich isAWS_ACCESS_KEY_IDin aws context.SMS_PROVIDER_PASSWORDwhich isAWS_SECRET_ACCESS_KEYin aws context.SMS_PROVIDER_REGIONwhich isAWS_REGIONin aws context.
AZURE
If you set SMS_PROVIDER = AZURE, the following env variables are required:
SMS_PROVIDER_USERNAMEwhich isresource-namein azureconnectionStringcontext.SMS_PROVIDER_PASSWORDwhich isaccess-keyin azureconnectionStringcontext.SMS_PROVIDER_FROM_NUMBERwhich is the ACS-registered number in azure context. This must be in E.164 format, example: "+123456789"
Note: The azure connectionString for Azure Communication Services looks like this: endpoint=https://<resource-name>.communication.azure.com/;accesskey=<access-key>.
TWILIO
If you set SMS_PROVIDER = TWILIO, the following env variables are required:
SMS_PROVIDER_USERNAMEwhich isTWILIO_ACCOUNT_SIDin twilio context.SMS_PROVIDER_PASSWORDwhich isTWILIO_AUTH_TOKENin twilio context.
VONAGE
If you set SMS_PROVIDER = VONAGE, the following env variables are required:
SMS_PROVIDER_USERNAMEwhich isVONAGE_API_KEYin vonage context.SMS_PROVIDER_PASSWORDwhich isVONAGE_API_SECRETin vonage context.SMS_PROVIDER_FROM_NUMBERwhich can be one of the next:- An alphanumeric ID. Example: "MyCompanyBrand"
- A Vonage-registered number in E.164 format. Example: "+123456789".
- A local-registered short number. Example: "12345".
API Documentation
Available Methods
send: (phones: string[], message: string) => Promise<SendResult>;Example Usage
const phones: string[] = [
"+123456789",
"+9876543210"
];
const message = "Hello world!";
const smsSenderService = new SMSSenderService();
await smsSenderService.send(phones, message);