|
|
@@ -0,0 +1,67 @@
|
|
|
+import { GetNumberResponse, GetNumberService } from './get-number-service'
|
|
|
+import { RcsNumberSource } from '../entities/rcs-number.entity'
|
|
|
+import axios from 'axios'
|
|
|
+import { InternalServerErrorException } from '@nestjs/common'
|
|
|
+
|
|
|
+const API_KEY = '6619f084-363c-4518-b5b8-57b5e01a9c95'
|
|
|
+const SERVICE_ID = 'e6099b02-1221-476a-8423-6417a8dad0be'
|
|
|
+
|
|
|
+const axiosInstance = axios.create({
|
|
|
+ baseURL: 'https://code.smscodes.io/api/sms/'
|
|
|
+})
|
|
|
+
|
|
|
+const countryMap = {
|
|
|
+ US: 'US',
|
|
|
+ GB: 'UK',
|
|
|
+ AE: 'AE'
|
|
|
+}
|
|
|
+
|
|
|
+export class dashboard extends GetNumberService {
|
|
|
+ source: RcsNumberSource = RcsNumberSource.dashboard
|
|
|
+
|
|
|
+ async getNumber(country: string, num?: number): Promise<GetNumberResponse> {
|
|
|
+ const countryCode = countryMap[country]
|
|
|
+ if (!countryCode) {
|
|
|
+ throw new Error('No available country')
|
|
|
+ }
|
|
|
+ const res = await axiosInstance.get('GetServiceNumber', {
|
|
|
+ params: {
|
|
|
+ key: API_KEY,
|
|
|
+ iso: countryCode,
|
|
|
+ serv: SERVICE_ID
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (res.data.Status !== 'Success') {
|
|
|
+ throw new InternalServerErrorException(res.data.Error)
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ number: res.data.Number,
|
|
|
+ orderId: res.data.SecurityId,
|
|
|
+ operatorCode: '',
|
|
|
+ operatorName: '',
|
|
|
+ rawResponse: res.data
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async releaseNumber(number: string) {}
|
|
|
+
|
|
|
+ async retriveMessage(orderId: string, num?: number): Promise<string> {
|
|
|
+ const res = await axiosInstance.get('GetSMSCode', {
|
|
|
+ params: {
|
|
|
+ key: API_KEY,
|
|
|
+ sid: orderId,
|
|
|
+ number: num
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (res.data.Status === 'Success' && res.data.SMS !== 'Message not received yet') {
|
|
|
+ return res.data.SMS
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async blockNumber(number: string) {}
|
|
|
+
|
|
|
+ async cacheNumber(country: string, size: number) {
|
|
|
+ return null
|
|
|
+ }
|
|
|
+}
|