(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
+32 -31
View File
@@ -6,11 +6,11 @@
DATE:
Thursday, 5th Dec., 2024.
Monday, 9th Dec., 2024.
OBJECTIVE:
To provide a structure to receive auth details of various SMS providers.
To provide a structure to receive API calls to send SMS messages from various third-party clients.
REFERENCES:
@@ -46,6 +46,9 @@ from utils_v2.date_time import date_time
# To work with date and time:
import datetime
# To work with MongoDB:
from bson.objectid import ObjectId
# *****************************************************************************************************************
# ***** ****
@@ -75,29 +78,22 @@ REGEX_SESSION_TOKEN = r"^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]
# *****************************************************************************************************************
class NimbusSMSIndiaAuth(BaseModel):
class NimbusSMSIndiaMessage(BaseModel):
entityId: str = Field(
description = "the entity id as registered with DLT",
recipientNo: str = Field(
description = "the phone no. of the target recipient",
min_length = 1,
frozen = True
)
senderId: str = Field(
description = "the 6-char code that you see in your SMS inbox",
min_length = 1,
frozen = True,
examples = ["HDFCBK", "NSESMS", "ZRODHA"]
)
userId: str = Field(
description = "the 6-digit id that Nimbus has assigned to you",
text: str = Field(
description = "the actual text that you want to send",
min_length = 1,
frozen = True
)
apiKey: str = Field(
description = "the key generated through Nimbus's portal",
templateId: str = Field(
description = "the id of the template that you are trying to use to send the message",
min_length = 1,
frozen = True
)
@@ -114,22 +110,16 @@ class NimbusSMSIndiaAuth(BaseModel):
# ---------------------------------------------------------------------------------------------------------------------
class SavvyBulkSMSKenyaAuth(BaseModel):
class SavvyBulkSMSKenyaMessage(BaseModel):
apiKey: str = Field(
description = "the key generated through Savvy's portal",
recipientNo: str = Field(
description = "the phone no. of the target recipient",
min_length = 1,
frozen = True
)
partnerId: str = Field(
description = "the key generated through Savvy's portal",
min_length = 1,
frozen = True
)
shortCode: str = Field(
description = "your short code with Savvy",
text: str = Field(
description = "the actual text that you want to send",
min_length = 1,
frozen = True
)
@@ -146,7 +136,7 @@ class SavvyBulkSMSKenyaAuth(BaseModel):
# ---------------------------------------------------------------------------------------------------------------------
class SMSAuthRequestHeaders(BaseModel):
class SMSSendRequestHeaders(BaseModel):
sessionToken: str = Field(
description = "the session token of the user who is requesting the service",
@@ -170,10 +160,10 @@ class SMSAuthRequestHeaders(BaseModel):
# ---------------------------------------------------------------------------------------------------------------------
class SMSAuthRequestData(BaseModel):
class SMSSendRequestData(BaseModel):
smsClient: Literal["nimbusSmsIndia", "savvyBulkSmsKenya"] = Field(alias = "client")
auth: Union[NimbusSMSIndiaAuth, SavvyBulkSMSKenyaAuth]
tokenId: ObjectId = Field(description = "the auth token to use to send this message")
message: Union[NimbusSMSIndiaMessage, SavvyBulkSMSKenyaMessage]
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
@@ -182,6 +172,17 @@ class SMSAuthRequestData(BaseModel):
class Config:
extra = "forbid"
arbitrary_types_allowed = True
# ┓┏ ┓• ┓ •
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
@field_validator("tokenId", mode = "before")
def parse_oid(cls, value):
try: value = ObjectId(value)
except: pass
return value
# *****************************************************************************************************************