(20241211) Started more work on the files part and added validation to the phone no. in the API exposed for Nimbus.

This commit is contained in:
2024-12-11 13:20:54 +05:30
parent 570a28ef38
commit 897c32c595
8 changed files with 792 additions and 433 deletions
+24 -2
View File
@@ -82,7 +82,7 @@ class NimbusSMSIndiaMessage(BaseModel):
recipientNo: str = Field(
description = "the phone no. of the target recipient",
min_length = 1,
pattern = r"\+?\d{0,3}\s*\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}",
frozen = True
)
@@ -106,6 +106,17 @@ class NimbusSMSIndiaMessage(BaseModel):
class Config:
extra = "forbid"
# ┓┏ ┓• ┓ •
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
@field_validator("recipientNo", mode = "before")
def validate_contact_nos(cls, value):
value = regex.replace(text = str(value), pattern = r"[^\d]", substitute_text = "")
if len(value) > 10: value = regex.replace(text = str(value), pattern = r"^(91)", substitute_text = "")
value = regex.find_first(text = str(value), pattern = r"^[\d]{10}")
return value
# ---------------------------------------------------------------------------------------------------------------------
@@ -194,4 +205,15 @@ class SMSSendRequestData(BaseModel):
if __name__ == "__main__":
pass
from utils_v2.string import json
my_request = SMSSendRequestData(
tokenId = "670f580d7cda4ebc1adc3444",
message = NimbusSMSIndiaMessage(
recipientNo = "+.9.1 ---> 93261 3642fgnn193261",
text = "Hello, Nimbus!",
templateId = "12345678"
)
)
print("NIMBUS SMS API MODEL:", json.to_string(my_request.model_dump(), default = str))