Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork11
Injectable Twilio client for Nestjs.
License
lkaric/nestjs-twilio
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Injectable Twilio client forNestjs.
Implementing theTwilioModule from this package you gain access to Twilio client through dependency injection with minimal setup.
$ npm install --save nestjs-twilio
$ yarn add nestjs-twilio
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,}),],})exportclassAppModule{}
If you are using the@nestjs/config package from nest, you can use theConfigModule using theregisterAsync() 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],}),],})exportclassAppModule{}
Example usage in service.
import{InjectTwilio,TwilioService}from'nestjs-twilio';@Injectable()exportclassAppService{publicconstructor(privatereadonlytwilioService:TwilioService){}asyncsendSMS(){returnthis.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 referencehere
Example of testing can be foundhere.
About
Injectable Twilio client for Nestjs.
Topics
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors8
Uh oh!
There was an error while loading.Please reload this page.