npm install nestjs-twilio

Injectable Twilio client for Nestjs

About nestjs-twilio

The "nestjs-twilio" package is a highly useful tool for developers working with both NestJS and Twilio. As an injectable Twilio client specifically designed for NestJS, this package seamlessly integrates the powerful communications capabilities of Twilio into the robust, server-side NestJS framework. This integration assists developers in implementing a variety of communications features such as SMS, voice calls, and video calls directly into their applications. The primary benefit of using nestjs-twilio is its ability to simplify the complexity of handling communications APIs by providing a straightforward, declarative approach to Twilio's extensive features within a NestJS application.

To begin using nestjs-twilio in your project, the installation process is straightforward and can be completed with a simple command: npm install nestjs-twilio. Once installed, developers can easily configure the module in their NestJS application by injecting it into services or controllers where Twilio's functionalities are required. This npm package not only saves time but also ensures that the application remains scalable and maintainable. Developers can leverage Twilio's capabilities without needing to manage the intricate details of API calls and response handling, as nestjs-twilio abstracts these complexities in a clean, idiomatic way that fits perfectly within the NestJS ecosystem.

Developers opting for nestjs-twilio benefit from the robustness of NestJS combined with the reliability and versatility of Twilio. Whether you are building a customer service system, a two-factor authentication feature, or a fully interactive communication platform, nestjs-twilio provides all the tools necessary to create a seamless experience. The package is regularly updated to keep up with the latest changes in both Twilio's APIs and the NestJS framework, ensuring that your application remains cutting-edge and functional. This makes nestjs-twilio an indispensable tool for developers looking to integrate professional-grade communication solutions into their NestJS applications efficiently and effectively.

More from lkaric

lkaric npm packages

Find the best node modules for your project.

Search npm

nestjs-twilio

Injectable Twilio client for...

Read more

Dependencies

Core dependencies of this npm package and its dev dependencies.

twilio, @commitlint/cli, @commitlint/config-conventional, @nestjs/common, @nestjs/core, @nestjs/testing, @semantic-release/changelog, @semantic-release/git, @types/jest, @types/node, @typescript-eslint/eslint-plugin, @typescript-eslint/parser, dotenv, eslint, eslint-config-prettier, eslint-plugin-prettier, husky, jest, lint-staged, pinst, prettier, reflect-metadata, rimraf, rxjs, semantic-release, ts-jest, typescript

Documentation

A README file for the nestjs-twilio code repository. View Code

nestjs-twilio

Injectable Twilio client for Nestjs.

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.