You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

message.py 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from datetime import datetime
  2. from math import floor
  3. from typing import Any, List
  4. from pydantic import BaseModel
  5. class Reaction(BaseModel):
  6. reaction: str
  7. actor: str
  8. class AudioFile(BaseModel):
  9. uri: str
  10. creation_timestamp: int
  11. class Video(BaseModel):
  12. uri: str
  13. creation_timestamp: int
  14. class Photo(BaseModel):
  15. uri: str
  16. creation_timestamp: int
  17. class Gif(BaseModel):
  18. uri: str
  19. class Share(BaseModel):
  20. link: str
  21. share_text: str
  22. class Sticker(BaseModel):
  23. uri: str
  24. ai_stickers: List[Any]
  25. class Message(BaseModel):
  26. sender_name: str
  27. timestamp_ms: int
  28. content: str | None = None
  29. sticker: Sticker | None = None
  30. share: Share | None = None
  31. photos: List[Photo] | None = None
  32. videos: List[Video] | None = None
  33. gifs: List[Gif] | None = None
  34. audio_files: List[AudioFile] | None = None
  35. call_duration: int | None = None
  36. reactions: List[Reaction] | None = None
  37. is_unsent: bool | None = None
  38. is_geoblocked_for_viewer: bool
  39. def __str__(self) -> str:
  40. dt = datetime.fromtimestamp(self.timestamp_ms / 1000)
  41. dt_str = dt.strftime("%d/%m/%Y, %H:%M:%S")
  42. return f"{self.sender_name}({dt_str}) : {self.content}"