(20241213) Mail Module Reworked!

This commit is contained in:
2024-12-13 14:14:15 +05:30
parent a702e5ca20
commit e8ddffbdfe
12 changed files with 297 additions and 175 deletions
+10 -4
View File
@@ -37,7 +37,7 @@ sys.path.append("..")
# For making data behaviour_models:
from pydantic import BaseModel, Field, field_validator, PastDatetime
from typing import Optional, Literal, List
from typing import Optional, Literal, List, Any
# My utils:
from utils_v2.string import regex
@@ -99,10 +99,10 @@ class MailListRequestHeaders(BaseModel):
# ---------------------------------------------------------------------------------------------------------------------
class MailListByAccountIdRequestData(BaseModel):
class MailListRequestData(BaseModel):
tokenId: str | List[str] = Field(
description = "the account identifier(s) (Mongo ObjectId) granted by 'MailOAuthModel.get_account_identifier'",
tokenIds: str | List[str] = Field(
description = "the token identifier(s) that tell you which auth-tokens were used for fetching those messages",
frozen = True
)
@@ -116,10 +116,16 @@ class MailListByAccountIdRequestData(BaseModel):
fromCount: int = Field(
description = "the no. of mails to skip before picking mails to list; useful for pagination",
ge = 0,
default = 0,
frozen = True
)
tags: List[Any] | None = Field(
description = "any no. of tags that you want to filter by",
default = None
)
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
# ┗┛┗┛┛┗┛┗┗┫
+17 -5
View File
@@ -6,11 +6,11 @@
DATE:
Tuesday, 3rd Dec., 2024.
Friday, 13th Dec., 2024.
OBJECTIVE:
To provide a structure to query the full payload of an email.
To provide a structure to work with the tags on mail messages.
REFERENCES:
@@ -37,7 +37,7 @@ sys.path.append("..")
# For making data behaviour_models:
from pydantic import BaseModel, Field, field_validator, PastDatetime
from typing import Optional, Literal
from typing import Optional, Literal, List, Any
# My utils:
from utils_v2.string import regex
@@ -75,7 +75,7 @@ REGEX_SESSION_TOKEN = r"^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]
# *****************************************************************************************************************
class MailGetRequestHeaders(BaseModel):
class MailUpdateTagsRequestHeaders(BaseModel):
sessionToken: str = Field(
description = "the session token of the user who is requesting the service",
@@ -99,7 +99,7 @@ class MailGetRequestHeaders(BaseModel):
# ---------------------------------------------------------------------------------------------------------------------
class MailGetRequestData(BaseModel):
class MailUpdateTagsRequestData(BaseModel):
tokenId: str = Field(
description = "the id of the token associated with the mail; needed for security",
@@ -111,6 +111,18 @@ class MailGetRequestData(BaseModel):
frozen = True
)
unsetTags: List[Any] | None = Field(
description = "the list of tags to remove from the mail",
frozen = True,
default = None
)
setTags: List[Any] | None = Field(
description = "the list of tags to add to the mail",
frozen = True,
default = None
)
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
# ┗┛┗┛┛┗┛┗┗┫
+70 -30
View File
@@ -36,7 +36,7 @@ sys.path.append(".")
sys.path.append("..")
# For making data behaviour_models:
from pydantic import BaseModel, Field, field_validator, PastDatetime, AwareDatetime
from pydantic import BaseModel, Field, field_validator, PastDatetime, AwareDatetime, constr
from typing import Optional, Literal, Union, List, Any
# My utils:
@@ -100,18 +100,6 @@ class CoreMessageModel(BaseModel):
default_factory = lambda: date_time.get_current_utc_date_time(as_string = False)
)
readTs: AwareDatetime | None = Field(
description = "the time (utc) at which this message was read by the user",
frozen = True,
default = None
)
markedAsUnread: bool = Field(
description = "to note when the user has marked this message as unread",
frozen = False,
default = False
)
tokenId: ObjectId = Field(
description = "the id of the auth token that is associated with this message",
frozen = True
@@ -160,20 +148,30 @@ class CoreMessageModel(BaseModel):
default = False
)
aiSnippet: LLMOutput | dict | None = Field(
description = "holds a short summary generated by ",
frozen = False,
default = None
sender: str | None = Field(
description = "the name of the sender; null if you are the sender",
frozen = True
)
preview: str = Field(
chat: str | None = Field(
description = "the name of the chat where the message was exchanged; relevant in chat apps like telegram",
frozen = True
)
message: dict = Field(
description = "the actual content(s) of the message; will differ for each service/client",
frozen = True
)
snippet: str = Field(
description = "a truncated version of the actual textual content of the message",
frozen = False
)
message: dict = Field(
description = "the actual contents of the message; will differ for each client",
frozen = True
aiSnippet: LLMOutput | dict | None = Field(
description = "holds a short summary generated by an llm",
frozen = False,
default = None
)
tags: List[Any] = Field(
@@ -183,29 +181,67 @@ class CoreMessageModel(BaseModel):
examples = ["urgent", "otp", "GST"]
)
usedAi: bool | None = Field(
description = "to mark when a sent message was generated by ai; null means the status is not known",
frozen = True,
default = None
)
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
# ┗┛┗┛┛┗┛┗┗┫
# ┛
class Config:
extra = "allow"
extra = "forbid"
arbitrary_types_allowed = True
def model_dump(self, *args, **kwargs):
return super().model_dump(*args, by_alias = True, **kwargs)
# ┏┓ •
# ┃┃┏┓┏┓┏┓┏┓┏┓╋┓┏┓┏
# ┣┛┛ ┗┛┣┛┗ ┛ ┗┗┗ ┛
# ┛
@property
def full(self):
return {
"messageId": str(self.messageId),
"ts": self.ts.isoformat(),
"serviceType": self.serviceType,
"client": self.client,
"clientMessageId": self.clientMessageId,
"clientThreadId": self.clientThreadId,
"isSent": self.isSent,
"isBroadcast": self.isBroadcast,
"sentSuccessfully": self.sentSuccessfully,
"sender": self.sender,
"chat": self.chat,
"message": self.message,
"snippet": self.snippet,
"aiSnippet": self.aiSnippet,
"tags": self.tags
}
@property
def preview(self):
return {
"messageId": str(self.messageId),
"ts": self.ts.isoformat(),
"serviceType": self.serviceType,
"client": self.client,
"clientMessageId": self.clientMessageId,
"clientThreadId": self.clientThreadId,
"isSent": self.isSent,
"isBroadcast": self.isBroadcast,
"sentSuccessfully": self.sentSuccessfully,
"sender": self.sender,
"chat": self.chat,
"snippet": self.snippet,
"aiSnippet": self.aiSnippet,
"tags": self.tags
}
# ┓┏ ┓• ┓ •
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
@field_validator("ts", "syncTs", "readTs", mode = "before")
@field_validator("ts", "syncTs", mode = "before")
def parse_date_time(cls, value):
return date_time.parse_date_time(input_value = value, timezone = date_time.TIMEZONE_UTC)
@@ -231,6 +267,7 @@ class CoreMessageModel(BaseModel):
if __name__ == "__main__":
from utils_v2.string import json
message = CoreMessageModel(
@@ -245,7 +282,10 @@ if __name__ == "__main__":
"from": "bhopli@gmil.com",
"to": "hello@thecaoffice.com",
"message": "Hello, World!"
}
},
sender = "Polki",
chat = "T6 Cats",
preview = "Hi, there! How do you do?"
)
print("MESSAGE MODEL:", json.to_string(message.model_dump(), default = str))