update sms api for smspipe
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 9s

This commit is contained in:
2026-08-02 06:04:20 +05:00
parent c414116ed5
commit 2db0369d7c
2 changed files with 21 additions and 12 deletions
+16 -8
View File
@@ -10,6 +10,16 @@ bot_token = str(config("TG_BOT_TOKEN", cast=str, default=""))
chat_id = str(config("TG_CHAT_ID", cast=str, default=""))
def format_mobile(mobile: str) -> str:
"""Normalize a Maldives mobile number to E.164 (+960XXXXXXX)."""
number = str(mobile).strip().replace(" ", "")
if number.startswith("+"):
return number
if number.startswith("960"):
return "+" + number
return "+960" + number
def send_otp(mobile: str, message: str):
if not api_url or not api_key:
logger.debug("Failed to send SMS. Missing SMS_API_URL or SMS_API_KEY.")
@@ -17,12 +27,11 @@ def send_otp(mobile: str, message: str):
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}",
"X-API-Key": api_key,
}
data = {
"number": mobile,
"message": message,
"check_delivery": False,
"to": format_mobile(mobile),
"text": message,
}
response = requests.post(api_url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
@@ -41,12 +50,11 @@ def send_sms(mobile: str, message: str):
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}",
"X-API-Key": api_key,
}
data = {
"number": mobile,
"message": message,
"check_delivery": False,
"to": format_mobile(mobile),
"text": message,
}
response = requests.post(api_url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
+5 -4
View File
@@ -232,14 +232,15 @@ def send_sms_with_callback_token(user, mobile_token, **kwargs):
logger.debug("Failed to send SMS. Missing SMS_API_URL or SMS_API_KEY.")
return False
from api.notifications import format_mobile
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}",
"X-API-Key": api_key,
}
data = {
"number": to_number,
"message": base_string % mobile_token.key,
"check_delivery": False,
"to": format_mobile(to_number),
"text": base_string % mobile_token.key,
}
print(mobile_token.key)
response = requests.post(api_url, headers=headers, data=json.dumps(data))