Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sinuoslabs/twilio
Twilio channel for NestJS notification
https://github.com/sinuoslabs/twilio
nestjs sms twilio typescript
Last synced: 2 months ago
JSON representation
Twilio channel for NestJS notification
- Host: GitHub
- URL: https://github.com/sinuoslabs/twilio
- Owner: sinuoslabs
- License: mit
- Created: 2021-12-22T17:07:20.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-22T18:09:45.000Z (about 2 years ago)
- Last Synced: 2024-03-29T02:44:43.937Z (10 months ago)
- Topics: nestjs, sms, twilio, typescript
- Language: TypeScript
- Homepage:
- Size: 1.58 MB
- Stars: 4
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
![issues](https://img.shields.io/github/issues/nestjs-notification-channels/twilio)
[![npm version](https://badge.fury.io/js/@nestjs-notification-channels%2Ftwilio.svg)](https://badge.fury.io/js/@nestjs-notification-channels%2Ftwilio)
![license](https://img.shields.io/github/license/nestjs-notification-channels/twilio)
[![Open Source Helpers](https://www.codetriage.com/nestjs-notification-channels/twilio/badges/users.svg)](https://www.codetriage.com/nestjs-notification-channels/twilio)# Twilio notification channel for NestJS
This package makes it easy to send [Twilio notifications](https://documentation.twilio.com/docs) with NestJS.
This package is a sub-module of [NestJS notification](https://github.com/sinuoslabs/nestjs-notification).
## Contents
- [Installation](#installation)
- [Usage](#usage)
- [Available Message methods](#available-message-methods)
- [Changelog](#changelog)
- [Testing](#testing)
- [Security](#security)
- [Contributing](#contributing)
- [License](#license)## Installation
::: code
```bash npm
$ npm i @nestjs-notification-channels/twilio
``````bash yarn
$ yarn add @nestjs-notification-channels/twilio
```:::
### Configuration
Add your Twilio Account SID, Auth Token, and Sender (optional) to your `.env`:
```dotenv
TWILIO_ACCOUNT_SID=
TWILIO_AUTH_TOKEN=
TWILIO_SENDER=
```## Usage
Module declaration
```typescript
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import {
NestjsNotificationModule,
NestjsNotificationModuleOptions,
} from '@sinuos/nestjs-notification';@Module({
imports: [
NestjsNotificationModule.register({}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
```You can also declare the account sid, auth token and sender by declaring them like this.
```typescript
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import {
NestjsNotificationModule,
NestjsNotificationModuleOptions,
} from '@sinuos/nestjs-notification';
import { TwilioChannelModule } from '@nestjs-notification-channels/twilio';@Module({
imports: [
NestjsNotificationModule.register({}),
TwilioChannelModule.register({
twilioAccountSid: 'xxx',
twilioAuthToken: 'xxx',
twilioSender: 'xxx', // SENDER OR +212xxxxxx,
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
```Now you can use the channel in your `sendToChannels()` method inside the notification:
```typescript
import { NestJsNotification } from '@sinuos/nestjs-notification';
import {
TwilioChannel,
TwilioChannelMessage,
ITwilioChannel,
} from '@nestjs-notification-channels/twilio';export class OrderedNotification implements NestJsNotification {
public sendToChannels() {
return [TwilioChannel];
}toTwilio() {
return new TwilioChannelMessage()
.setToFrom('+212xxxxxxxx')
.setMessage('Your order XXXXX is placed');
}
}
```### Available Message methods
#### TwilioMessage
- `accountSid('')` - Optional if account sid is defined in your env.
- `authToken('')` - Optional if auth token is defined in your env.
- `sender('')` - Optional if sender is defined in your env.
- `message('')` - SMS content.
- `toPhoneNumber('')` - Your recipient.## Changelog
Please see [CHANGELOG][changelog] for more information what has changed recently.
## Testing
::: code
```bash npm
$ npm run test
``````bash yarn
$ yarn test
```:::
## Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
## Contributing
Please see [CONTRIBUTING][contributing] for details.
## License
The MIT License (MIT). Please see [License File][license] for more information.
[license]: https://github.com/nestjs-notification-channels/twilio/blob/main/LICENSE
[changelog]: https://github.com/nestjs-notification-channels/twilio/blob/main/CHANGELOG
[contributing]: https://github.com/nestjs-notification-channels/twilio/blob/main/CONTRIBUTING