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("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; } }