JSPM

@nestjs-packages/ncp-sens

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q62326F
  • License MIT

NCP SENS Client module for Nest.js

Package Exports

  • @nestjs-packages/ncp-sens

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@nestjs-packages/ncp-sens) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Nest Logo

NCP SENS Client module for Nest.js

NPM Version Package License NPM Downloads Coverage

Base on @pickk/sens

1. Features

  • send SMS
  • send Alimtalk

2. Installation

$ npm i --save @nestjs-packages/ncp-sens
# or
$ yarn add @nestjs-packages/ncp-sens

3. Usage

1. configure

sync

import { SensModule } from '@nestjs-packages/ncp-sens';

@Module({
  imports: [
    SensModule.forRoot({
      accessKey: 'ACCESS_KEY',
      secretKey: 'SECRET_KEY',
      sms: {
        smsServiceId: 'SMS_SERVICE_ID',
        smsSecretKey: 'SMS_SECRET_KEY',
        callingNumber: '01012341234',
      },
      alimtalk: {
        alimtalkServiceId: 'ALIMTALK_SERVICE_ID',
        plusFriendId: 'PLUS_FRIEND_ID',
      }
    }),
  ],
})

async

import {
  SensModule,
  SensModuleAsyncOptions,
  SensModuleOptions,
} from '@nestjs-packages/ncp-sens';

import { SensConfigModule, SensConfigService } from 'your-config-path';

@Module({
  imports: [
    SensModule.forRootAsync({
      imports: [SensConfigModule],
      useFactory: async (sensConfigService: SensConfigService) =>
        ({
          accessKey: sensConfigService.ncloudAccessKey,
          secretKey: sensConfigService.ncloudSecretKey,
          sms: {
            smsServiceId: sensConfigService.ncloudSmsServiceId,
            smsSecretKey: sensConfigService.ncloudSmsSecretKey,
            callingNumber: sensConfigService.ncloudSmsCallingNumber,
          },
          alimtalk: {
            alimtalkServiceId: sensConfigService.ncloudAlimtalkServiceId,
            plusFriendId: sensConfigService.plusFriendId,
          },
        } as SensModuleOptions),
      inject: [SensConfigService],
    } as SensModuleAsyncOptions),
  ],
})

2. inject & send

import { AlimtalkClient, SmsClient } from '@nestjs-packages/ncp-sens';

@Injectable()
export class YourService {
  constructor(
    @Inject(AlimtalkClient) private readonly alimtalkClient: AlimtalkClient,
    @Inject(SmsClient) private readonly smsClient: SmsClient
  ) {}

  async sendAlimtalk(templateCode: string, to: string, content: string) {
    await this.alimtalkClient.send({
      templateCode,
      messages: [{ to, content }],
    });
  }

  async sendSms(to: string, content: string) {
    await this.smsClient.send({ to, content });
  }
}

Author

License

@nestjs-packages/ncp-sens is MIT licensed.