(20241213) SMS Auth reworked.

This commit is contained in:
2024-12-13 18:28:45 +05:30
parent 4c258b110a
commit 4f5668c036
9 changed files with 476 additions and 47 deletions
+79 -2
View File
@@ -37,12 +37,16 @@ sys.path.append("..")
# For making data behaviour_models:
from pydantic import BaseModel, Field, field_validator, PastDatetime
from typing import Optional, Literal, Union
from typing import Optional, Literal, Union, List
# My utils:
from utils_v2.string import regex
from utils_v2.date_time import date_time
# Data models:
from models.core.message import CoreMessageModel
from utils_v2.sms.models.data.sms_message import SentSMSMessageModel
# To work with date and time:
import datetime
@@ -174,7 +178,7 @@ class SMSSendRequestHeaders(BaseModel):
class SMSSendRequestData(BaseModel):
tokenId: ObjectId = Field(description = "the auth token to use to send this message")
message: Union[NimbusSMSIndiaMessage, SavvyBulkSMSKenyaMessage]
message: Union[List[NimbusSMSIndiaMessage], List[SavvyBulkSMSKenyaMessage]]
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
@@ -195,6 +199,79 @@ class SMSSendRequestData(BaseModel):
except: pass
return value
@field_validator("message", mode = "before")
def ensure_list(cls, value):
if not isinstance(value, list): value = [value]
return value
# ---------------------------------------------------------------------------------------------------------------------
class SMSSendOneResult(BaseModel):
success: bool = Field(
description = "whether, or not, the sms was successfully sent",
default = False
)
message: str | None = Field(
description = "a brief message to summarize the result of the process",
default = None
)
smsMessage: Union[NimbusSMSIndiaMessage, SavvyBulkSMSKenyaMessage] = Field(
description = "the actual data of the sms",
default = None
)
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
# ┗┛┗┛┛┗┛┗┗┫
# ┛
class Config:
extra = "forbid"
# ---------------------------------------------------------------------------------------------------------------------
class SMSSendManyResults(BaseModel):
totalCount: int = Field(
description = "the total no. of mails that were to be sync'd",
default = 0
)
successCount: int = Field(
description = "the no. of mails that were successfully sync'd",
default = 0
)
failureCount: int = Field(
description = "the no. of mails that were successfully sync'd",
default = 0
)
message: str = Field(
description = "a brief message to summarize the results of the process",
default = None
)
smsMessages: List[CoreMessageModel] = Field(
description = "the actual data of the sms",
default = []
)
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
# ┗┛┗┛┛┗┛┗┗┫
# ┛
class Config:
extra = "forbid"
# *****************************************************************************************************************
# ***** ****