nestjs-alicloud-sms
v1.0.1
Published
An Alicloud short message service (SMS) module for NestJS framework (node.js)
Downloads
23
Maintainers
Readme
English | 简体中文
Before Installation
- Create Alicloud account
- Purchase SMS. (read more)
- Apply for SMS sign name and message template, go to Dashboard > Short Message Service > Domestic Message > Add Singname
- Create message template, go to Dashboard > Short Message Service > Domestic Message > Templates Management > Add Template.
Installation
npm install --save nestjs-alicloud-sms
#or
yarn add nestjs-alicloud-sms
Documentation
- Import the
AlicloudSmsModule
with the following configuration:
import { Module } from '@nestjs/common';
import { AlicloudSmsModule } from 'nestjs-alicloud-sms';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@Module({
controllers: [AppController],
providers: [AppService],
imports: [
AlicloudSmsModule.forRoot({
config: { accessKeyId: '***', accessKeySecret: '***' },
defaults: { signName: '***', regionId: 'cn-hangzhou' },
}),
],
})
export class AppModule {}
- Send Message
import { Controller, Logger, Post } from '@nestjs/common';
import { AlicloudSmsService } from 'nestjs-alicloud-sms';
@Controller()
export class AppController {
constructor(private readonly smsService: AlicloudSmsService) {}
@Post('sms/send')
async sendSms(): Promise<any> {
const templateCodeId = 'SMS_1490999999';
const phoneNumber = '1388886666';
const templateParam = { code: '888666' };
const sendResponse = await this.smsService.sendSms(templateCodeId, phoneNumber, templateParam);
if (sendResponse.Code === 'OK') {
// success
} else {
// failed
}
}
}
License
The MIT License.