update: sms service

This commit is contained in:
mahyargdz
2025-02-16 10:58:00 +03:30
parent c707b94f3b
commit 2afce3ec5e
+26 -21
View File
@@ -53,29 +53,34 @@ const axios = require('axios')
// }) // })
// } // }
const smsCredential = {
secretKey: 'drtime@A!@#',
apiKey: '569ee43ed0d9ac27708ce43d',
patternCode: '83604',
url: 'https://RestfulSms.com/api/UltraFastSend/direct'
}
module.exports.SMS = async (mobile, message) => { module.exports.SMS = async (mobile, message) => {
try { const smsService = new SmsService('QkkNxhyXZ6GtEf1soOTtikomO3mA4LaNQDH8mol8huDIwh00')
return await smsService.sendOTPSms(message, mobile)
}
class SmsService {
constructor(apiKey) {
this.API_URL_FAST = 'https://api.sms.ir/v1'
this.OTP_PATTERN = '83604'
this.SMS_API_KEY = apiKey
}
async sendOTPSms(otp, phone) {
const smsData = { const smsData = {
Mobile: mobile, Parameters: [{ name: 'code', value: `${otp}` }],
TemplateId: smsCredential.patternCode, Mobile: phone,
ParameterArray: [{ Parameter: 'code', ParameterValue: message }], TemplateId: this.OTP_PATTERN
UserApiKey: smsCredential.apiKey, }
SecretKey: smsCredential.secretKey try {
const { data } = await axios.post(`${this.API_URL_FAST}/send/verify`, smsData, {
headers: {
'X-API-KEY': this.SMS_API_KEY,
'Content-Type': 'application/json'
}
})
return data
} catch (error) {
console.error('Error in sending OTP SMS', error)
} }
const { data } = await axios.post(smsCredential.url, smsData, {
headers: {
'Content-Type': 'application/json'
}
})
return data.IsSuccessful
} catch (error) {
console.log('error in sms module', error)
throw new Error('error in sms module')
} }
} }