From 2afce3ec5ecef1ddfd4f39604ea1896e56a2b32a Mon Sep 17 00:00:00 2001 From: mahyargdz Date: Sun, 16 Feb 2025 10:58:00 +0330 Subject: [PATCH] update: sms service --- server/plugins/SMS_Module.js | 47 ++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/server/plugins/SMS_Module.js b/server/plugins/SMS_Module.js index bd94263..7d2714b 100644 --- a/server/plugins/SMS_Module.js +++ b/server/plugins/SMS_Module.js @@ -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) => { - 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 = { - Mobile: mobile, - TemplateId: smsCredential.patternCode, - ParameterArray: [{ Parameter: 'code', ParameterValue: message }], - UserApiKey: smsCredential.apiKey, - SecretKey: smsCredential.secretKey + Parameters: [{ name: 'code', value: `${otp}` }], + Mobile: phone, + TemplateId: this.OTP_PATTERN + } + 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') } }