1.2.0 • Published 9 months ago

@pixelplex/sms-service v1.2.0

Weekly downloads
111
License
MIT
Repository
-
Last release
9 months ago

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

  1. create template for message
  2. add @pixelplex/sms-service to your application
  3. call SmsModule.forRoot from @pixelplex/sms-service to import in your module
  4. send a message by calling this.smsService.sendSms('+375297775544', 'auth', { name: 'Афанасий' }); where smsService is SmsSenderService from @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 subject

Configuration Variables

NameDescriptionExample
gatewaysArray of gateways to send email, supported: smpt, slack, console['slack']
customGatewaysArray of custom gateways classes[CustomGateway]
slack.urlHook URL in case you want to duplicate messages to Slackhttps://hooks.slack.com
*.senderSms 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-service

2. 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.

1.2.0

9 months ago

1.1.19

2 years ago

1.1.18

2 years ago

1.1.17

2 years ago

0.1.15

2 years ago

1.1.16

2 years ago

0.1.13

3 years ago

0.1.14

3 years ago

0.1.11

3 years ago

0.1.12

3 years ago

0.1.10

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3-dev1

3 years ago

0.1.3-dev

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago