(20241214) SMS also ported to the 'tokenKey' system.
This commit is contained in:
+18
-21
@@ -141,7 +141,7 @@ class SMSController:
|
||||
success = False
|
||||
|
||||
# Get a token id:
|
||||
token_id = await current_app.core_auth_token_controller.get_token_id(
|
||||
token_key = await current_app.core_auth_token_controller.get_token_key(
|
||||
db_conn = db_conn,
|
||||
mongo_conn = mongo_conn,
|
||||
auth_token = auth_token,
|
||||
@@ -153,7 +153,7 @@ class SMSController:
|
||||
success = await current_app.core_auth_token_controller.set_token(
|
||||
db_conn = db_conn,
|
||||
mongo_conn = mongo_conn,
|
||||
token_id = token_id,
|
||||
token_key = token_key,
|
||||
auth_token = auth_token,
|
||||
token_notes = {},
|
||||
session_token = session_token
|
||||
@@ -165,13 +165,13 @@ class SMSController:
|
||||
@staticmethod
|
||||
async def get_token(
|
||||
mongo_conn: AsyncMongo,
|
||||
token_id: ObjectId | str = None,
|
||||
token_key: ObjectId | str = None,
|
||||
) -> CoreAuthTokenModel | None:
|
||||
|
||||
# Simply call the core model:
|
||||
return await current_app.core_auth_token_controller.get_token(
|
||||
mongo_conn = mongo_conn,
|
||||
token_id = token_id
|
||||
token_key = token_key
|
||||
)
|
||||
|
||||
# ┏┓ ┓
|
||||
@@ -181,7 +181,6 @@ class SMSController:
|
||||
@staticmethod
|
||||
async def __send_from_nimbus_sms_india(
|
||||
http_client: httpx.AsyncClient,
|
||||
token_id: ObjectId | str,
|
||||
auth_token: CoreAuthTokenModel,
|
||||
messages: List[NimbusSMSIndiaMessage],
|
||||
) -> SMSSendManyResults:
|
||||
@@ -215,7 +214,7 @@ class SMSController:
|
||||
send_results.smsMessages.append(CoreMessageModel(
|
||||
ts = client_response.ts,
|
||||
syncTs = date_time.get_current_utc_date_time(as_string = False),
|
||||
tokenId = ObjectId(token_id),
|
||||
tokenId = auth_token.authTokenId,
|
||||
serviceType = auth_token.serviceType,
|
||||
client = auth_token.client,
|
||||
clientMessageId = client_response.messageId,
|
||||
@@ -238,7 +237,6 @@ class SMSController:
|
||||
@staticmethod
|
||||
async def __send_from_savvy_bulk_sms_kenya(
|
||||
http_client: httpx.AsyncClient,
|
||||
token_id: ObjectId | str,
|
||||
auth_token: CoreAuthTokenModel,
|
||||
messages: List[SavvyBulkSMSKenyaMessage],
|
||||
) -> SMSSendManyResults:
|
||||
@@ -270,7 +268,7 @@ class SMSController:
|
||||
send_results.smsMessages.append(CoreMessageModel(
|
||||
ts = client_response.ts,
|
||||
syncTs = date_time.get_current_utc_date_time(as_string = False),
|
||||
tokenId = ObjectId(token_id),
|
||||
tokenId = auth_token.authTokenId,
|
||||
serviceType = auth_token.serviceType,
|
||||
client = auth_token.client,
|
||||
clientMessageId = client_response.messageId,
|
||||
@@ -294,37 +292,36 @@ class SMSController:
|
||||
self,
|
||||
mongo_conn: AsyncMongo,
|
||||
http_client: httpx.AsyncClient,
|
||||
token_id: ObjectId | str,
|
||||
# token_id: ObjectId | str,
|
||||
auth_token: CoreAuthTokenModel,
|
||||
messages: List[NimbusSMSIndiaMessage | SavvyBulkSMSKenyaMessage]
|
||||
) -> SMSSendManyResults:
|
||||
|
||||
# Start by assuming failure:
|
||||
send_results = SMSSendManyResults()
|
||||
|
||||
# We first load the authorization tokens:
|
||||
auth_token = await self.get_token(
|
||||
mongo_conn = mongo_conn,
|
||||
token_id = token_id,
|
||||
)
|
||||
|
||||
# If we failed to load the authorization tokens:
|
||||
if not auth_token:
|
||||
send_results.message = f"no such token id '{token_id}'"
|
||||
return send_results
|
||||
# # We first load the authorization tokens:
|
||||
# auth_token = await self.get_token(
|
||||
# mongo_conn = mongo_conn,
|
||||
# token_id = token_id,
|
||||
# )
|
||||
#
|
||||
# # If we failed to load the authorization tokens:
|
||||
# if not auth_token:
|
||||
# send_results.message = f"no such token id '{token_id}'"
|
||||
# return send_results
|
||||
|
||||
# Now we route the message to the appropriate client:
|
||||
match auth_token.client:
|
||||
case "nimbusSmsIndia":
|
||||
send_results = await self.__send_from_nimbus_sms_india(
|
||||
http_client = http_client,
|
||||
token_id = token_id,
|
||||
auth_token = auth_token,
|
||||
messages = messages
|
||||
)
|
||||
case "savvyBulkSmsKenya":
|
||||
send_results = await self.__send_from_savvy_bulk_sms_kenya(
|
||||
http_client = http_client,
|
||||
token_id = token_id,
|
||||
auth_token = auth_token,
|
||||
messages = messages
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user