|
|
@@ -0,0 +1,72 @@
|
|
|
+import axios from 'axios'
|
|
|
+import { GetNumberService, GetNumberResponse } from './get-number-service'
|
|
|
+import { RcsNumber, RcsNumberSource, RcsNumberStatus } from '../entities/rcs-number.entity'
|
|
|
+import { InternalServerErrorException, Logger } from '@nestjs/common'
|
|
|
+import { addMinutes } from 'date-fns'
|
|
|
+
|
|
|
+const account = 'ihzc9190@gmail.com'
|
|
|
+const apiKey = 'oFASOiuSPfZVddOhB83XtLyJrilufUpGvAIuyQxRPn8kwiAylaBYsXsOvFIKrg'
|
|
|
+
|
|
|
+let token = ''
|
|
|
+let expiresAt = null
|
|
|
+
|
|
|
+async function getAxiosInstance() {
|
|
|
+ const axiosInstance = axios.create({
|
|
|
+ baseURL: 'https://www.textverified.com'
|
|
|
+ })
|
|
|
+ if (!(token && expiresAt && expiresAt > Date.now())) {
|
|
|
+ const { data } = await axiosInstance.post('/api/pub/v2/auth', null, {
|
|
|
+ headers: {
|
|
|
+ 'content-length': 0,
|
|
|
+ 'x-api-key': apiKey,
|
|
|
+ 'x-api-username': account
|
|
|
+ }
|
|
|
+ })
|
|
|
+ token = data.token
|
|
|
+ expiresAt = addMinutes(new Date(data.expiresAt), -1)
|
|
|
+ }
|
|
|
+ axiosInstance.defaults.headers.common['Authorization'] = `Bearer ${token}`
|
|
|
+ return axiosInstance
|
|
|
+}
|
|
|
+
|
|
|
+export class textverified extends GetNumberService {
|
|
|
+ source: RcsNumberSource = RcsNumberSource.textverified
|
|
|
+
|
|
|
+ async getNumber(country: string, num?: number): Promise<GetNumberResponse> {
|
|
|
+ if (country.toLocaleLowerCase() !== 'us') throw new Error('Only US is supported')
|
|
|
+ const axiosInstance = await getAxiosInstance()
|
|
|
+ const {
|
|
|
+ data: { href }
|
|
|
+ } = await axiosInstance.post('/api/pub/v2/verifications', {
|
|
|
+ serviceName: 'googlemessenger',
|
|
|
+ capability: 'sms'
|
|
|
+ })
|
|
|
+ const { data: detail } = await axiosInstance.get(href)
|
|
|
+ return {
|
|
|
+ orderId: detail.id,
|
|
|
+ number: detail.number,
|
|
|
+ operatorCode: '',
|
|
|
+ rawResponse: JSON.stringify(detail),
|
|
|
+ source: this.source,
|
|
|
+ expiryTime: new Date(detail.endsAt)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async releaseNumber(number: string) {}
|
|
|
+
|
|
|
+ async retriveMessage(orderId: string, num?: number): Promise<string> {
|
|
|
+ const axiosInstance = await getAxiosInstance()
|
|
|
+ const { data } = await axiosInstance.get(`/api/pub/v2/sms`, {
|
|
|
+ params: { ReservationId: orderId }
|
|
|
+ })
|
|
|
+ if (data.data && data.data.length) {
|
|
|
+ return data.data[0].smsContent.trim()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async blockNumber(number: string) {}
|
|
|
+
|
|
|
+ async cacheNumber(country: string, size: number) {
|
|
|
+ return null
|
|
|
+ }
|
|
|
+}
|