diff --git a/aiogram/custom_types.py b/aiogram/custom_types.py new file mode 100644 index 00000000..cc600b63 --- /dev/null +++ b/aiogram/custom_types.py @@ -0,0 +1,17 @@ +import datetime +from typing import Annotated + +from pydantic import PlainSerializer + +# Make datetime compatible with Telegram Bot API (unixtime) +DateTime = Annotated[ + datetime, + PlainSerializer( + func=lambda dt: int(dt.timestamp()), + return_type=int, + when_used="json-unless-none", + ), +] + +# Make string compatible with custom lazy proxy +# String = Union[str, LazyProxy]