4.4.0 • Published 1 month ago

nestjs-twilio v4.4.0

Weekly downloads
987
License
MIT
Repository
github
Last release
1 month ago

npm version miniziped size tree shaking MIT licensed

Implementing the TwilioModule from this package you gain access to Twilio client through dependency injection with minimal setup.

Instalation

$ npm install --save nestjs-twilio
$ yarn add nestjs-twilio

Getting Started

To use Twilio client we need to register module for example in app.module.ts

import { TwilioModule } from 'nestjs-twilio';

@Module({
  imports: [
    TwilioModule.forRoot({
      accountSid: process.env.TWILIO_ACCOUNT_SID,
      authToken: process.env.TWILIO_AUTH_TOKEN,
    }),
  ],
})
export class AppModule {}

If you are using the @nestjs/config package from nest, you can use the ConfigModule using the registerAsync() function to inject your environment variables like this in your custom module:

import { TwilioModule } from 'nestjs-twilio';

@Module({
  imports: [
    TwilioModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: (cfg: ConfigService) => ({
        accountSid: cfg.get('TWILIO_ACCOUNT_SID'),
        authToken: cfg.get('TWILIO_AUTH_TOKEN'),
      }),
      inject: [ConfigService],
    }),
  ],
})
export class AppModule {}

Example usage in service.

import { InjectTwilio, TwilioService } from 'nestjs-twilio';

@Injectable()
export class AppService {
  public constructor(private readonly twilioService: TwilioService) {}

  async sendSMS() {
    return this.twilioService.client.messages.create({
      body: 'SMS Body, sent to the phone!',
      from: TWILIO_PHONE_NUMBER,
      to: TARGET_PHONE_NUMBER,
    });
  }
}

For full Client API see Twilio Node SDK reference here

Testing

Example of testing can be found here.

4.4.0

1 month ago

4.3.0

4 months ago

4.2.0

6 months ago

4.0.0

1 year ago

4.1.1

1 year ago

3.2.1

1 year ago

3.2.0

1 year ago

3.1.0

2 years ago

3.0.0

2 years ago

2.2.1

2 years ago

2.2.0

2 years ago

2.1.0

3 years ago

2.0.0

3 years ago

1.2.0

3 years ago

1.2.1

3 years ago

1.0.2

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago