feat(telegram): implement asynchronous Telegram alert system and enhance user verification messaging
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 4m38s

This commit is contained in:
2025-07-27 21:56:59 +05:00
parent 2bc594da9c
commit 9c082aedf2
4 changed files with 123 additions and 12 deletions

View File

@@ -12,6 +12,7 @@ from .views import (
CancelTopupView,
ListWalletTransactionView,
AdminTopupCreateView,
# AlertTestView,
)
urlpatterns = [
@@ -50,4 +51,6 @@ urlpatterns = [
ListWalletTransactionView.as_view(),
name="list-wallet-transactions",
),
# Test tg notification
# path("test-alert/", AlertTestView.as_view(), name="test-alert"),
]

View File

@@ -30,6 +30,9 @@ from typing import Optional
from api.models import User
from api.omada import Omada
# from api.bot import send_telegram_alert, telegram_loop, escape_markdown_v2
# import asyncio
env.read_env(os.path.join(BASE_DIR, ".env"))
PAYMENT_BASE_URL = env("PAYMENT_BASE_URL", default="") # type: ignore
@@ -685,3 +688,35 @@ class ListWalletTransactionView(StaffEditorPermissionMixin, generics.ListAPIView
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)
# class AlertTestView(generics.GenericAPIView):
# def get(self, request, *args, **kwargs):
# msg = """*ID Card:* A265117\n*Name:* Abdulla Aidhaan\n*House Name:* Nooree Villa\n*Date of Birth:* 1997-08-24\n*Island:* Sh Funadhoo\n*Mobile:* 9697404\nVisit [SAR Link Portal](https://portal.sarlink.net) to manually verify this user."""
# print(msg)
# print("escaped:", escape_markdown_v2(msg))
# user = request.user
# print(user)
# global telegram_loop # Access the global loop
# if telegram_loop is None:
# return Response(
# {"message": "Telegram worker not initialized."},
# status=status.HTTP_503_SERVICE_UNAVAILABLE,
# )
# try:
# asyncio.run_coroutine_threadsafe(
# send_telegram_alert(markdown_message=escape_markdown_v2(msg)),
# telegram_loop,
# ).result()
# return Response(
# {"message": "Alert sent successfully."}, status=status.HTTP_200_OK
# )
# except Exception as e:
# logger.warning("[alert test] TELEGRAM ALERT ERROR", e)
# return Response(
# {"message": "Alert failed to send."}, status=status.HTTP_400_BAD_REQUEST
# )