README
Feature
Nestjs module wrapper for twilio client.
Installation
Yarn
yarn add @lkaric/twilio-nestjs
NPM
npm install @lkaric/twilio-nestjs --save
Getting Started
An example instantiatiation of twilio client in for example app.module.ts
import { Module } from '@nestjs/common';
import { TwilioModule } from '@lkaric/twilio-nestjs';
@Module({
imports: [
TwilioModule.register({
accountSid: '<TWILIO_SID>',
authToken: '<TWILIO_AUTH_TOKEN>',
}),
],
})
export class AppModule {}
Example usage.
import { Injectable } from '@nestjs/common';
import { TwilioService } from '@lkaric/twilio-nestjs';
@Injectable()
export class SendMeSms {
constructor(private readonly twilioService: TwilioService) {}
async sendSms() {
try {
const message = await this.twilioService.client.messages.create({
body: '<MESSAGE_BODY>',
from: '<TWILIO_PHONE_NUMBER>',
to: '<TARGET_PHONE_NUMBER>',
});
return message;
} catch (error) {
return error;
}
}
}
For full Client API see the official Twilio SDK reference here;