mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-07-04 15:16:34 +00:00
This commit is contained in:
30
api/sms.py
Normal file
30
api/sms.py
Normal file
@ -0,0 +1,30 @@
|
||||
from decouple import config
|
||||
import requests
|
||||
import json
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
api_url = config("SMS_API_URL")
|
||||
api_key = config("SMS_API_KEY")
|
||||
|
||||
|
||||
def send_otp(mobile: str, otp: int, message: str):
|
||||
if not api_url or not api_key:
|
||||
logger.debug("Failed to send SMS. Missing SMS_API_URL or SMS_API_KEY.")
|
||||
return False
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {api_key}",
|
||||
}
|
||||
data = {
|
||||
"number": mobile,
|
||||
"message": message,
|
||||
"check_delivery": False,
|
||||
}
|
||||
response = requests.post(api_url, headers=headers, data=json.dumps(data))
|
||||
if response.status_code == 200:
|
||||
return True
|
||||
else:
|
||||
logger.debug(f"Failed to send SMS. Status code: {response.status_code}")
|
||||
return False
|
Reference in New Issue
Block a user