Add SMS and Telegram notification functions to handle user verification messages
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 4m15s

This commit is contained in:
2025-05-31 13:40:29 +05:00
parent a9e1973f4a
commit cdd032ac54
3 changed files with 45 additions and 2 deletions

View File

@ -1,13 +1,14 @@
from django.shortcuts import get_object_or_404
from api.models import User
from devices.models import Device
from api.sms import send_sms
from api.notifications import send_sms
import requests
from apibase.env import env, BASE_DIR
import os
import logging
from celery import shared_task
from django.utils import timezone
from api.notifications import send_telegram_markdown
logger = logging.getLogger(__name__)
@ -157,6 +158,19 @@ def verify_user_with_person_api_task(user_id: int):
user = get_object_or_404(User, id=user_id)
# Call the Person API to verify the user
verification_failed_message = f"""
_The following user verification failed_:
*ID Card:* {user.id_card} \n
*Name:* {user.first_name} {user.last_name} \n
*House Name:* {user.address} \n
*Date of Birth:* {user.dob} \n
*Island:* {user.atoll} {user.island} \n
*Mobile:* {user.mobile} \n
Visit [SAR Link Portal](https://portal.sarlink.net) to manually verify this user.
"""
if not PERSON_VERIFY_BASE_URL:
raise ValueError(
"PERSON_VERIFY_BASE_URL is not set in the environment variables."
@ -227,6 +241,7 @@ def verify_user_with_person_api_task(user_id: int):
user.mobile,
f"Dear {user.first_name} {user.last_name}, \n\nYour account registration is being processed. \n\nWe will notify you once verification is complete. \n\n - SAR Link",
)
send_telegram_markdown(message=verification_failed_message)
return False
else:
# Handle the error case