@redredgroup/nestjs-solapi
v1.2.0
Published
SOLAPI integration to a NestJS application
Downloads
121
Readme
Nestjs Solapi
Introduction
This package is a module that converts the asynchronous Solapi to Nestjs.
Installation
using npm
npm install @redredgroup/nestjs-solapi
using yarn
yarn install @redredgroup/nestjs-solapi
using pnpm
pnpm add @redredgroup/nestjs-solapi
Import module
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { SolapiModule } from '@redredgroup/nestjs-solapi';
@Module({
imports: [
SolapiModule.forRoot({
solapiOptions: {
apiKey: 'YOUR_API_KEY',
apiSecret: 'YOUR_API_TOKEN',
},
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
//Or the forRootAsync module using @nestjs/Config
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { SolapiModule } from '@redredgroup/nestjs-solapi';
@Module({
imports: [
SolapiModule.forRootAsync({
useFactory: () => ({
solapiOptions: {
apiKey: 'YOUR_API_KEY',
apiSecret: 'YOUR_API_TOKEN',
},
}),
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
Example
Sending SMS
import { Injectable } from '@nestjs/common';
import { SolapiService } from '@redredgroup/nestjs-solapi';
@Injectable()
export class AppService {
constructor(private readonly solapiService: SolapiService) {}
async sendingSms(): Promise<string> {
const sendResult = await this.solapiService.send({
to: 'target Number',
from: 'Enter the registered calling number from your account',
text: 'SMS can be up to 45 Korean characters and 90 alphanumeric characters.',
});
console.log(sendResult);
return 'ok';
}
}
Custom Class
SMS Verification (Random String)
import { Injectable } from '@nestjs/common';
import { SolapiService } from '@redredgroup/nestjs-solapi';
@Injectable()
export class AppService {
constructor(private readonly solapiService: SolapiService) {}
async sendingCustomVerifySms() {
const sendVerifySmsResult = await this.solapiService.CustomSolapi.SmsVerify.send({
config: {
verificationCodeLength: 10, //Code Length
verificationCodeType: 'ALPHABET_ONLY', // 'NUMBER_ONLY' | 'ALPHABET_ONLY' | 'MIX'
verificationMessage: 'Verification Code is: {{VERIFICATION_CODE}}', // Inject wherever you want with the {{VERIFICATION_CODE}} format.
},
smsOptions: {
to: 'target Number',
from: 'Enter the registered calling number from your account',
type: 'SMS',
},
});
console.log(sendVerifySmsResult.verificationCode);
console.log(sendVerifySmsResult.smsResult);
return 'ok';
}
}
Copyright
© 2023 REDREDGROUP Software. All Right Reserved.
License
Apache-2.0