forked from Yara724/api
Tidied up the project
This commit is contained in:
45
src/sms-orchestration/provider/kavenegar.service.ts
Normal file
45
src/sms-orchestration/provider/kavenegar.service.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { HttpService } from "@nestjs/axios";
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
@Injectable()
|
||||
export class KavenegarService {
|
||||
private readonly apiKey: string;
|
||||
private readonly baseUrl: string;
|
||||
|
||||
constructor(
|
||||
private readonly http: HttpService,
|
||||
private readonly configService: ConfigService,
|
||||
) {
|
||||
this.apiKey = this.configService.get<string>("SMS_API_KEY", "");
|
||||
|
||||
this.baseUrl = `https://api.kavenegar.com/v1/${this.apiKey}`;
|
||||
}
|
||||
|
||||
async send(data: { receptor: string; message: string; sender?: string }) {
|
||||
const response = await firstValueFrom(
|
||||
this.http.post(`${this.baseUrl}/sms/send.json`, null, {
|
||||
params: data,
|
||||
}),
|
||||
);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async verifyLookup(data: {
|
||||
receptor: string;
|
||||
token: string;
|
||||
template: string;
|
||||
token2?: string;
|
||||
token3?: string;
|
||||
}) {
|
||||
const response = await firstValueFrom(
|
||||
this.http.get(`${this.baseUrl}/verify/lookup.json`, {
|
||||
params: data,
|
||||
}),
|
||||
);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user