(20241209) SMS auth and sending ready.
This commit is contained in:
@@ -37,7 +37,7 @@ sys.path.append("..")
|
||||
|
||||
# For making data behaviour_models:
|
||||
from pydantic import BaseModel, Field, field_validator, PastDatetime, AwareDatetime
|
||||
from typing import Optional, Literal, Union, List
|
||||
from typing import Optional, Literal, Union, List, Any
|
||||
|
||||
# My utils:
|
||||
from utils_v2.string import regex
|
||||
@@ -206,6 +206,12 @@ class LLMOutput(BaseModel):
|
||||
frozen = True
|
||||
)
|
||||
|
||||
invocationId: Any | None = Field(
|
||||
description = "the id of the document that notes this invocation; useful for reconciliation",
|
||||
frozen = False,
|
||||
default = None
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
|
||||
@@ -43,6 +43,9 @@ from typing import Optional, Literal
|
||||
from utils_v2.string import regex
|
||||
from utils_v2.date_time import date_time
|
||||
|
||||
# Data models:
|
||||
from models.data.core.message import CoreMessageModel
|
||||
|
||||
# To work with date and time:
|
||||
import datetime
|
||||
|
||||
@@ -168,7 +171,7 @@ class MailSyncOneResult(BaseModel):
|
||||
default = None
|
||||
)
|
||||
|
||||
mailMessage: dict | None = Field(
|
||||
mailMessage: CoreMessageModel | None = Field(
|
||||
description = "the actual data of the mail; can be null in a successful process if the mail is already sync'd",
|
||||
default = None
|
||||
)
|
||||
|
||||
+32
-31
@@ -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
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
|
||||
@@ -86,7 +86,7 @@ class CoreAuthTokenModel(BaseModel):
|
||||
description = "a hint about the version no. of this message",
|
||||
min_length = 1,
|
||||
frozen = True,
|
||||
default = "1.0.0"
|
||||
default = "2.0.0"
|
||||
)
|
||||
|
||||
serviceType: Literal["email", "sms", "chat"] = Field(
|
||||
@@ -109,25 +109,25 @@ class CoreAuthTokenModel(BaseModel):
|
||||
frozen = True
|
||||
)
|
||||
|
||||
firstRequestTs: AwareDatetime = Field(
|
||||
firstRequestTs: AwareDatetime | None = Field(
|
||||
description = "the time (utc) at which authorization was first requested",
|
||||
frozen = True,
|
||||
default = None
|
||||
)
|
||||
|
||||
lastRequestTs: AwareDatetime = Field(
|
||||
lastRequestTs: AwareDatetime | None = Field(
|
||||
description = "the time (utc) at which authorization was last requested",
|
||||
frozen = False,
|
||||
default_factory = lambda: date_time.get_current_utc_date_time(as_string = False)
|
||||
)
|
||||
|
||||
firstRefreshTs: AwareDatetime = Field(
|
||||
firstRefreshTs: AwareDatetime | None = Field(
|
||||
description = "the time (utc) at which the tokens were first refreshed",
|
||||
frozen = False,
|
||||
default = None
|
||||
)
|
||||
|
||||
lastRefreshTs: AwareDatetime = Field(
|
||||
lastRefreshTs: AwareDatetime | None = Field(
|
||||
description = "the time (utc) at which the tokens were last refreshed",
|
||||
frozen = False,
|
||||
default = None
|
||||
|
||||
@@ -83,7 +83,7 @@ class CoreMessageModel(BaseModel):
|
||||
description = "a hint about the version no. of this message",
|
||||
min_length = 1,
|
||||
frozen = True,
|
||||
default = "1.0.0"
|
||||
default = "2.0.0"
|
||||
)
|
||||
|
||||
ts: AwareDatetime = Field(
|
||||
@@ -116,7 +116,7 @@ class CoreMessageModel(BaseModel):
|
||||
frozen = True
|
||||
)
|
||||
|
||||
clientMessageId: str | int = Field(
|
||||
clientMessageId: str | int | None = Field(
|
||||
description = "how the client identifies this message",
|
||||
frozen = True
|
||||
)
|
||||
@@ -127,6 +127,24 @@ class CoreMessageModel(BaseModel):
|
||||
default = None
|
||||
)
|
||||
|
||||
isInward: bool = Field(
|
||||
description = "to understand whether this message was an inward message or outward message",
|
||||
frozen = True,
|
||||
default = True
|
||||
)
|
||||
|
||||
isBroadcast: bool = Field(
|
||||
description = "to understand if this message was broadcasted or sent one-to-one",
|
||||
frozen = True,
|
||||
default = False
|
||||
)
|
||||
|
||||
sentSuccessfully: bool | None = Field(
|
||||
description = "when a message is an outgoing message, this indicates if the message was send successfully",
|
||||
frozen = False,
|
||||
default = False
|
||||
)
|
||||
|
||||
payload: dict = Field(
|
||||
description = "the actual contents of the message; will differ for each client",
|
||||
frozen = True
|
||||
|
||||
@@ -130,7 +130,7 @@ class CorePaymentModel(BaseModel):
|
||||
description = "a hint about the version no. of this message",
|
||||
min_length = 1,
|
||||
frozen = True,
|
||||
default = "1.0.0"
|
||||
default = "2.0.0"
|
||||
)
|
||||
|
||||
paymentStatus: Literal[
|
||||
|
||||
@@ -83,7 +83,7 @@ class CoreUserInfoModel(BaseModel):
|
||||
description = "a hint about the version no. of this message",
|
||||
min_length = 1,
|
||||
frozen = True,
|
||||
default = "1.0.0"
|
||||
default = "2.0.0"
|
||||
)
|
||||
|
||||
fullName: str | None = Field(
|
||||
|
||||
Reference in New Issue
Block a user