(20241209) SMS auth and sending ready.

This commit is contained in:
2024-12-09 19:39:15 +05:30
parent d10b156c0b
commit 845827a6bc
18 changed files with 367 additions and 348 deletions
+53 -29
View File
@@ -59,15 +59,12 @@ from utils_v2.api.async_quart import (
handle_cancelled_request
)
# SMS-related utils:
from utils_v2.sms.nimbus.async_nimbus import AsyncNimbusSMS
from utils_v2.sms.savvy_bulk_sms.async_savvy_bulk_sms import AsyncSavvyBulkSMS
# Common:
from shared import constants
# Data Models:
from models.data.api.sms.auth import SMSAuthRequestHeaders, SMSAuthRequestData
from models.data.core.auth_token import CoreAuthTokenModel
# For asynchronous activities:
import asyncio
@@ -132,7 +129,7 @@ def init(blueprint_setup_state):
data_validator = lambda x: SMSAuthRequestData(**x)
)
@handle_cancelled_request()
async def request_oauth_authorization_url(
async def authorize_sms_client(
inbound_headers: dict | SMSAuthRequestHeaders = None,
inbound_data: dict | SMSAuthRequestData = None,
inbound_files: dict = None,
@@ -167,22 +164,36 @@ async def request_oauth_authorization_url(
# ┣ ┏┓┏┓ ┃┃┓┏┳┓┣┓┓┏┏ ┗┓┃┃┃┗┓ ┃┏┓┏┫┓┏┓
# ┻ ┗┛┛ ┛┗┗┛┗┗┗┛┗┻┛ ┗┛┛ ┗┗┛ ┻┛┗┗┻┗┗┻
if inbound_data.messageClient == "nimbusSmsIndia":
if inbound_data.smsClient == "nimbusSmsIndia":
token_id = await current_app.sms_auth_model.set(
db_conn = current_app.sql_writer,
mongo_conn = current_app.data_mongo,
user_info = kwargs["session_info"],
client_user_id = {
"userId": inbound_data.auth.userId,
"senderId": inbound_data.auth.senderId,
"entityId": inbound_data.auth.entityId
},
auth = inbound_data.auth.model_dump(),
token = None,
service_client = inbound_data.smsClient,
auth_type = "auth",
sync_freq = 300,
auth_token = CoreAuthTokenModel(
serviceType = "sms",
client = inbound_data.smsClient,
authType = "auth",
auth = inbound_data.auth.model_dump(),
user = kwargs.get("session_info"),
clientUserId = {
"userId": inbound_data.auth.userId,
"senderId": inbound_data.auth.senderId,
"entityId": inbound_data.auth.entityId
},
status = "active",
syncFreq = 60
),
# user_info = kwargs["session_info"],
# client_user_id = {
# "userId": inbound_data.auth.userId,
# "senderId": inbound_data.auth.senderId,
# "entityId": inbound_data.auth.entityId
# },
# auth = inbound_data.auth.model_dump(),
# token = None,
# service_client = inbound_data.smsClient,
# auth_type = "auth",
# sync_freq = 300,
session_token = inbound_headers["X-Session-Token"]
)
@@ -191,21 +202,34 @@ async def request_oauth_authorization_url(
# ┻ ┗┛┛ ┗┛┗┻┗┛┗┛┗┫ ┻┛┗┻┗┛┗ ┗┛┛ ┗┗┛ ┛┗┛┗ ┛┗┗┫┗┻
# ┛ ┛
if inbound_data.messageClient == "savvyBulkSmsKenya":
elif inbound_data.smsClient == "savvyBulkSmsKenya":
token_id = await current_app.sms_auth_model.set(
db_conn = current_app.sql_writer,
mongo_conn = current_app.data_mongo,
user_info = kwargs["session_info"],
client_user_id = {
"partnerId": inbound_data.auth.partnerId,
"shortCode": inbound_data.auth.shortCode
},
auth = inbound_data.auth.model_dump(),
token = None,
service_client = inbound_data.smsClient,
auth_type = "auth",
sync_freq = 300,
auth_token=CoreAuthTokenModel(
serviceType = "sms",
client = inbound_data.smsClient,
authType = "auth",
auth = inbound_data.auth.model_dump(),
user = kwargs.get("session_info"),
clientUserId = {
"partnerId": inbound_data.auth.partnerId,
"shortCode": inbound_data.auth.shortCode
},
status = "active",
syncFreq = 60
),
# user_info = kwargs["session_info"],
# client_user_id = {
# "partnerId": inbound_data.auth.partnerId,
# "shortCode": inbound_data.auth.shortCode
# },
# auth = inbound_data.auth.model_dump(),
# token = None,
# service_client = inbound_data.smsClient,
# auth_type = "auth",
# sync_freq = 300,
session_token = inbound_headers["X-Session-Token"]
)
@@ -219,7 +243,7 @@ async def request_oauth_authorization_url(
status_code = StatusCodes.OK if token_id else StatusCodes.FAILED,
http_code = HttpCodes.SUCCESS if token_id else HttpCodes.INTERNAL_SERVER_ERROR,
data = {
"smsClient": inbound_data.messageClient,
"smsClient": inbound_data.smsClient,
"authorized": True
}
)