11from __future__ import annotations
22
3- from typing import Any
3+ from typing import Any , overload
44from urllib .parse import urlencode
55
66from linkedapi .config import LinkedApiConfig
5555 ConversationPollRequest ,
5656 ConversationPollResult ,
5757 InboxMessage ,
58+ InboxPersonPollRequest ,
59+ InboxPersonPollResult ,
5860 InboxPollRequest ,
5961)
6062from linkedapi .types .network import NetworkEvent , NetworkPollRequest
@@ -161,7 +163,12 @@ def poll_conversations(
161163 self ,
162164 conversations : list [ConversationPollRequest ],
163165 ) -> MappedResponse [list [ConversationPollResult ]]:
164- """Poll previously synced standard or Sales Navigator conversations."""
166+ """Poll previously synced standard or Sales Navigator conversations.
167+
168+ Deprecated: legacy, kept working for existing integrations. Use ``poll_inbox`` with
169+ ``InboxPersonPollRequest(person_url=...)``: it returns the same history together with the
170+ messages the inbox captured, and does not fail for people whose history was never loaded.
171+ """
165172
166173 try :
167174 response = self .http_client .post ("/conversations/poll" , serialize_value (conversations ))
@@ -187,15 +194,39 @@ def poll_conversations(
187194 )
188195 raise
189196
197+ @overload
198+ def poll_inbox ( # type: ignore[overload-overlap]
199+ self ,
200+ request : InboxPersonPollRequest ,
201+ ) -> MappedResponse [InboxPersonPollResult ]: ...
202+
203+ @overload
190204 def poll_inbox (
191205 self ,
192206 request : InboxPollRequest | None = None ,
193- ) -> MappedResponse [list [InboxMessage ]]:
194- """Read the monitored standard or Sales Navigator inbox, newest messages first."""
207+ ) -> MappedResponse [list [InboxMessage ]]: ...
208+
209+ def poll_inbox (
210+ self ,
211+ request : InboxPollRequest | None = None ,
212+ ) -> MappedResponse [list [InboxMessage ]] | MappedResponse [InboxPersonPollResult ]:
213+ """Read the monitored standard or Sales Navigator inbox, newest messages first.
214+
215+ Without ``person_url`` the data is the list of inbox messages across every conversation.
216+ With ``person_url`` (use ``InboxPersonPollRequest``) the data is the whole known
217+ conversation with that person: the messages the inbox captured together with the history
218+ loaded by ``sync_conversation`` / ``nv_sync_conversation``, each message once, plus
219+ ``threads`` with ``history_from`` and ``history_complete``.
220+ """
195221
196222 payload = serialize_value (request ) if request is not None else {}
197223 response = self .http_client .post ("/inbox/poll" , payload )
198224 if response .success and response .result is not None :
225+ if request is not None and request .person_url :
226+ return MappedResponse (
227+ data = InboxPersonPollResult .model_validate (response .result ),
228+ errors = [],
229+ )
199230 messages = response .result .get ("messages" , [])
200231 return MappedResponse (
201232 data = [InboxMessage .model_validate (item ) for item in messages ],
0 commit comments