update sms api for smspipe
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 9s
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 9s
This commit is contained in:
+16
-8
@@ -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:
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user