@pixelplex/sms-service
v1.2.0
Published
Sms service
Readme
SMS Service
Library for fast implementation of the functionality of sending SMS messages.
Supported gateways:
- smsc
- sms-traffic
- twilio
- fire-mobile
- devinotele
and debug gateways:
- console
- slack
The service receive messages and sends them via SMS.
How to use
- create template for message
- add
@pixelplex/sms-serviceto your application - call
SmsModule.forRootfrom@pixelplex/sms-servicetoimportin your module - send a message by calling
this.smsService.sendSms('+375297775544', 'auth', { name: 'Афанасий' });wheresmsServiceisSmsSenderServicefrom@pixelplex/sms-service
Didn't understand anything? Okay, let's see more details
Prepare templates
The service uses Handlebars as template engine. So all your sms templates should be prepared as handlebars templates.
Welcome, {{name}}! This is subjectConfiguration Variables
| Name | Description | Example |
|----------------|-------------------------------------------------------------------|---------------------------|
| gateways | Array of gateways to send email, supported: smpt, slack, console | ['slack'] |
| customGateways | Array of custom gateways classes | [CustomGateway] |
| slack.url | Hook URL in case you want to duplicate messages to Slack | https://hooks.slack.com |
| *.sender | Sms sender phone number | +375333333333 |
| * | Other gateway-specific options like username, password, sid etc. | |
Trigger new message sending
1. Install npm package
yarn add @pixelplex/sms-service2. Import SmsModule in your module you'll send sms from:
import { Module } from '@nestjs/common';
import { SmsModule } from '@pixelplex/sms-service';
import { AppService } from './app.service';
@Module({
controllers: [],
imports: [
MailModule.forRoot({
gateways: ['slack', 'twilio', 'console'],
slack: { url: 'hooks.slack.com' },
twilio: {
sid: 'SID',
token: 'TOKEN',
sender: '+375333333333',
},
}),
],
providers: [AppService],
})
export class AppModule {}3. Call sendSms to send your sms:
import { Injectable } from '@nestjs/common';
import { SmsSenderService } from '@pixelplex/sms-service';
@Injectable()
export class AppService {
constructor(private readonly smsService: SmsSenderService) {
}
async onModuleInit() {
this.smsService.sendSms('+375297775544', './path', { name: 'Афанасий' });
}
}In the example below we'll send sms to +375297775544 with handlebars path ./path.
{name: 'Афанасий'} is the object with data which will used as payload data during processing your handlebars template.
