1919 async_to_raw_response_wrapper ,
2020 async_to_streamed_response_wrapper ,
2121)
22- from ..pagination import SyncCursorSearch , AsyncCursorSearch
22+ from ..pagination import SyncCursorList , AsyncCursorList , SyncCursorSearch , AsyncCursorSearch
2323from .._base_client import AsyncPaginator , make_request_options
2424from ..types .shared .message import Message
25- from ..types .message_list_response import MessageListResponse
2625from ..types .message_send_response import MessageSendResponse
2726
2827__all__ = ["MessagesResource" , "AsyncMessagesResource" ]
@@ -52,8 +51,8 @@ def with_streaming_response(self) -> MessagesResourceWithStreamingResponse:
5251
5352 def list (
5453 self ,
55- * ,
5654 chat_id : str ,
55+ * ,
5756 cursor : str | Omit = omit ,
5857 direction : Literal ["after" , "before" ] | Omit = omit ,
5958 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -62,7 +61,7 @@ def list(
6261 extra_query : Query | None = None ,
6362 extra_body : Body | None = None ,
6463 timeout : float | httpx .Timeout | None | NotGiven = not_given ,
65- ) -> MessageListResponse :
64+ ) -> SyncCursorList [ Message ] :
6665 """List all messages in a chat with cursor-based pagination.
6766
6867 Sorted by timestamp.
@@ -84,23 +83,25 @@ def list(
8483
8584 timeout: Override the client-level default timeout for this request, in seconds
8685 """
87- return self ._get (
88- "/v1/messages" ,
86+ if not chat_id :
87+ raise ValueError (f"Expected a non-empty value for `chat_id` but received { chat_id !r} " )
88+ return self ._get_api_list (
89+ f"/v1/chats/{ chat_id } /messages" ,
90+ page = SyncCursorList [Message ],
8991 options = make_request_options (
9092 extra_headers = extra_headers ,
9193 extra_query = extra_query ,
9294 extra_body = extra_body ,
9395 timeout = timeout ,
9496 query = maybe_transform (
9597 {
96- "chat_id" : chat_id ,
9798 "cursor" : cursor ,
9899 "direction" : direction ,
99100 },
100101 message_list_params .MessageListParams ,
101102 ),
102103 ),
103- cast_to = MessageListResponse ,
104+ model = Message ,
104105 )
105106
106107 def search (
@@ -206,8 +207,8 @@ def search(
206207
207208 def send (
208209 self ,
210+ chat_id : str ,
209211 * ,
210- chat_id : str | Omit = omit ,
211212 reply_to_message_id : str | Omit = omit ,
212213 text : str | Omit = omit ,
213214 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -237,11 +238,12 @@ def send(
237238
238239 timeout: Override the client-level default timeout for this request, in seconds
239240 """
241+ if not chat_id :
242+ raise ValueError (f"Expected a non-empty value for `chat_id` but received { chat_id !r} " )
240243 return self ._post (
241- "/v1/messages" ,
244+ f "/v1/chats/ { chat_id } /messages" ,
242245 body = maybe_transform (
243246 {
244- "chat_id" : chat_id ,
245247 "reply_to_message_id" : reply_to_message_id ,
246248 "text" : text ,
247249 },
@@ -276,10 +278,10 @@ def with_streaming_response(self) -> AsyncMessagesResourceWithStreamingResponse:
276278 """
277279 return AsyncMessagesResourceWithStreamingResponse (self )
278280
279- async def list (
281+ def list (
280282 self ,
281- * ,
282283 chat_id : str ,
284+ * ,
283285 cursor : str | Omit = omit ,
284286 direction : Literal ["after" , "before" ] | Omit = omit ,
285287 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -288,7 +290,7 @@ async def list(
288290 extra_query : Query | None = None ,
289291 extra_body : Body | None = None ,
290292 timeout : float | httpx .Timeout | None | NotGiven = not_given ,
291- ) -> MessageListResponse :
293+ ) -> AsyncPaginator [ Message , AsyncCursorList [ Message ]] :
292294 """List all messages in a chat with cursor-based pagination.
293295
294296 Sorted by timestamp.
@@ -310,23 +312,25 @@ async def list(
310312
311313 timeout: Override the client-level default timeout for this request, in seconds
312314 """
313- return await self ._get (
314- "/v1/messages" ,
315+ if not chat_id :
316+ raise ValueError (f"Expected a non-empty value for `chat_id` but received { chat_id !r} " )
317+ return self ._get_api_list (
318+ f"/v1/chats/{ chat_id } /messages" ,
319+ page = AsyncCursorList [Message ],
315320 options = make_request_options (
316321 extra_headers = extra_headers ,
317322 extra_query = extra_query ,
318323 extra_body = extra_body ,
319324 timeout = timeout ,
320- query = await async_maybe_transform (
325+ query = maybe_transform (
321326 {
322- "chat_id" : chat_id ,
323327 "cursor" : cursor ,
324328 "direction" : direction ,
325329 },
326330 message_list_params .MessageListParams ,
327331 ),
328332 ),
329- cast_to = MessageListResponse ,
333+ model = Message ,
330334 )
331335
332336 def search (
@@ -432,8 +436,8 @@ def search(
432436
433437 async def send (
434438 self ,
439+ chat_id : str ,
435440 * ,
436- chat_id : str | Omit = omit ,
437441 reply_to_message_id : str | Omit = omit ,
438442 text : str | Omit = omit ,
439443 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -463,11 +467,12 @@ async def send(
463467
464468 timeout: Override the client-level default timeout for this request, in seconds
465469 """
470+ if not chat_id :
471+ raise ValueError (f"Expected a non-empty value for `chat_id` but received { chat_id !r} " )
466472 return await self ._post (
467- "/v1/messages" ,
473+ f "/v1/chats/ { chat_id } /messages" ,
468474 body = await async_maybe_transform (
469475 {
470- "chat_id" : chat_id ,
471476 "reply_to_message_id" : reply_to_message_id ,
472477 "text" : text ,
473478 },
0 commit comments