https://github.com/lkaric/nestjs-twilio
Injectable Twilio client for Nestjs.
https://github.com/lkaric/nestjs-twilio
hacktoberfest nestjs nodejs twilio twilio-api typescript
Last synced: 3 months ago
JSON representation
Injectable Twilio client for Nestjs.
- Host: GitHub
- URL: https://github.com/lkaric/nestjs-twilio
- Owner: lkaric
- License: mit
- Created: 2020-09-17T11:27:21.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-05-22T04:44:15.000Z (about 1 year ago)
- Last Synced: 2025-10-04T20:14:41.086Z (8 months ago)
- Topics: hacktoberfest, nestjs, nodejs, twilio, twilio-api, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/nestjs-twilio
- Size: 577 KB
- Stars: 47
- Watchers: 1
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/funding.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
nestjs-twilio
Injectable Twilio client for Nestjs.
[](https://www.npmjs.com/package/nestjs-twilio)
[](https://bundlephobia.com/result?p=nestjs-twilio)
[](https://github.com/lkaric/nestjs-twilio)
[](https://raw.githubusercontent.com/lkaric/nestjs-twilio/master/LICENSE)
Implementing the `TwilioModule` from this package you gain access to Twilio client through dependency injection with minimal setup.
## Instalation
```bash
$ npm install --save nestjs-twilio
```
```bash
$ yarn add nestjs-twilio
```
## Getting Started
To use Twilio client we need to register module for example in app.module.ts
```typescript
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:
```typescript
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.
```typescript
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](https://www.twilio.com/docs/libraries/node)
## Testing
Example of testing can be found [here](https://github.com/lkaric/nestjs-twilio/blob/master/lib/__tests__/twilio.module.test.ts).