diff --git a/src/twitchclient/api.py b/src/twitchclient/api.py index 9852396..05f9dff 100644 --- a/src/twitchclient/api.py +++ b/src/twitchclient/api.py @@ -913,3 +913,30 @@ class TwitchAPIClient(AioHTTPXClient): case _: raise s.Error(req.status_code, 'Internal Server Error') + + async def get_shared_chat_session( + self, + access_token: str, + broadcaster_id: int | str, + cache_time: int | None = None, + ): + req = await self.get( + '/shared_chat/session', + headers=self.clean_dict( + { + 'Authorization': f'Bearer {access_token}', + 'X-Cache-TTL': cache_time, + } + ), + params={'broadcaster_id': broadcaster_id}, + ) + + match req.status_code: + case st.OK: + return s.SharedChatSession.model_validate(req.json()).data + + case st.BAD_REQUEST | st.UNAUTHORIZED: + raise s.Error(req.status_code, req.json()['message']) + + case _: + raise s.Error(req.status_code, 'Internal Server Error') diff --git a/src/twitchclient/schema.py b/src/twitchclient/schema.py index a72aa20..fc05553 100644 --- a/src/twitchclient/schema.py +++ b/src/twitchclient/schema.py @@ -563,3 +563,25 @@ class ChatSettings(BaseModel): model_config = ConfigDict(extra='forbid') data: list[ChatSettingsData] + + +class SharedChatSessionParticipant(BaseModel): + model_config = ConfigDict(extra='forbid') + + broadcaster_id: int + + +class SharedChatSessionData(BaseModel): + model_config = ConfigDict(extra='forbid') + + session_id: str + host_broadcaster_id: int + participants: list[SharedChatSessionParticipant] + created_at: datetime + updated_at: datetime + + +class SharedChatSession(BaseModel): + model_config = ConfigDict(extra='forbid') + + data: list[SharedChatSessionData]