1- from typing import Any , Dict , List , Literal , Optional , Set , Union
1+ from typing import List , Literal , Optional , Set , Union
22from uuid import UUID
33
4- from pydantic import (
5- Field ,
6- ConfigDict ,
7- field_serializer ,
8- field_validator ,
9- model_validator ,
10- )
4+ from pydantic import Field , ConfigDict , field_serializer , field_validator
115
126from pybotx .client .authorized_botx_method import AuthorizedBotXMethod
137from pybotx .client .botx_method import response_exception_thrower
@@ -36,12 +30,11 @@ class BotXAPICreateChatRequestPayload(UnverifiedPayloadBaseModel):
3630 shared_history : Missing [bool ]
3731 avatar : Optional [str ] = None
3832
39- @model_validator (mode = "before" )
40- def _convert_chat_type (cls , values : Dict [str , Any ]) -> Dict [str , Any ]:
41- ct = values .get ("chat_type" )
42- if isinstance (ct , ChatTypes ):
43- values ["chat_type" ] = convert_chat_type_from_domain (ct )
44- return values
33+ @classmethod
34+ def _convert_chat_type (cls , v : Union [APIChatTypes , ChatTypes ]) -> APIChatTypes :
35+ if isinstance (v , ChatTypes ):
36+ return convert_chat_type_from_domain (v )
37+ return v
4538
4639 @field_validator ("avatar" )
4740 def _validate_avatar (cls , v : Optional [str ]) -> Optional [str ]:
@@ -59,6 +52,26 @@ def _validate_avatar(cls, v: Optional[str]) -> Optional[str]:
5952 def _serialize_chat_type (self , v : APIChatTypes ) -> str :
6053 return v .value .lower ()
6154
55+ @classmethod
56+ def from_domain (
57+ cls ,
58+ name : str ,
59+ chat_type : Union [APIChatTypes , ChatTypes ],
60+ members : List [UUID ],
61+ shared_history : Missing [bool ],
62+ description : Optional [str ] = None ,
63+ avatar : Optional [str ] = None ,
64+ ) -> "BotXAPICreateChatRequestPayload" :
65+ converted_chat_type = cls ._convert_chat_type (chat_type )
66+ return cls (
67+ name = name ,
68+ chat_type = converted_chat_type ,
69+ members = members ,
70+ shared_history = shared_history ,
71+ description = description ,
72+ avatar = avatar ,
73+ )
74+
6275
6376class BotXAPIChatIdResult (VerifiedPayloadBaseModel ):
6477 model_config = ConfigDict (frozen = True )
0 commit comments