|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import Any, Literal |
| 4 | + |
| 5 | +from pydantic import Field |
| 6 | + |
| 7 | +from linkedapi.types.base import LinkedApiModel |
| 8 | +from linkedapi.types.post import PostAuthor, PostComment, ReactionType |
| 9 | +from linkedapi.types.profile_viewers import ProfileViewer |
| 10 | +from linkedapi.types.search_posts import ( |
| 11 | + PostSearchContentType, |
| 12 | + PostSearchPostedBy, |
| 13 | + SearchPostResult, |
| 14 | + SearchPostsCompanyFilterEntry, |
| 15 | + SearchPostsPersonFilterEntry, |
| 16 | +) |
| 17 | + |
| 18 | +SignalType = Literal[ |
| 19 | + "personPosts", |
| 20 | + "companyPosts", |
| 21 | + "postSearch", |
| 22 | + "postEngagement", |
| 23 | + "network", |
| 24 | + "profileViewers", |
| 25 | +] |
| 26 | +SignalStatus = Literal["active", "paused", "stopped"] |
| 27 | +SignalStoppedReason = Literal["targetNotFound", "watchPeriodEnded"] |
| 28 | +SignalEventType = Literal[ |
| 29 | + "postPublished", |
| 30 | + "postFound", |
| 31 | + "commentAdded", |
| 32 | + "reactionAdded", |
| 33 | + "profileViewed", |
| 34 | + "connectionAccepted", |
| 35 | + "connectionAdded", |
| 36 | + "connectionRequestReceived", |
| 37 | +] |
| 38 | + |
| 39 | + |
| 40 | +class SignalPostSearchFilter(LinkedApiModel): |
| 41 | + """The filters a "postSearch" signal accepts: the content search filters other than sort, |
| 42 | + date and author.""" |
| 43 | + |
| 44 | + content_type: PostSearchContentType | None = None |
| 45 | + posted_by: list[PostSearchPostedBy] | None = None |
| 46 | + mentioning_members: list[SearchPostsPersonFilterEntry] | None = None |
| 47 | + mentioning_companies: list[SearchPostsCompanyFilterEntry] | None = None |
| 48 | + author_companies: list[SearchPostsCompanyFilterEntry] | None = None |
| 49 | + author_industries: list[str] | None = None |
| 50 | + |
| 51 | + |
| 52 | +class CreateSignalParams(LinkedApiModel): |
| 53 | + """A signal to create. The "type" decides the target field. |
| 54 | +
|
| 55 | + "personPosts" takes "person_url", "companyPosts" takes "company_url", "postSearch" takes |
| 56 | + "term" (a phrase or a list of up to three) and an optional "filter", "postEngagement" takes |
| 57 | + "post_url" or "my_posts=True", and "network" and "profileViewers" take none. "label" is your |
| 58 | + own identifier, up to 64 characters, returned with the signal and every event it produces. |
| 59 | + """ |
| 60 | + |
| 61 | + type: SignalType |
| 62 | + label: str | None = Field(default=None, max_length=64) |
| 63 | + person_url: str | None = None |
| 64 | + company_url: str | None = None |
| 65 | + post_url: str | None = None |
| 66 | + my_posts: Literal[True] | None = None |
| 67 | + term: str | list[str] | None = None |
| 68 | + filter: SignalPostSearchFilter | None = None |
| 69 | + |
| 70 | + |
| 71 | +class GetSignalsParams(LinkedApiModel): |
| 72 | + type: SignalType | None = None |
| 73 | + status: SignalStatus | None = None |
| 74 | + |
| 75 | + |
| 76 | +class SignalIdParams(LinkedApiModel): |
| 77 | + signal_id: str |
| 78 | + |
| 79 | + |
| 80 | +class SignalPollRequest(LinkedApiModel): |
| 81 | + """Pass "since" as the "detected_at" of the newest event you have; without it every |
| 82 | + retained event is returned.""" |
| 83 | + |
| 84 | + since: str | None = None |
| 85 | + signal_id: str | None = None |
| 86 | + signal_type: SignalType | None = None |
| 87 | + event_type: SignalEventType | None = None |
| 88 | + |
| 89 | + |
| 90 | +class Signal(LinkedApiModel): |
| 91 | + id: str | None = None |
| 92 | + type: SignalType | str | None = None |
| 93 | + label: str | None = None |
| 94 | + status: SignalStatus | str | None = None |
| 95 | + # Why Linked API stopped the signal; None unless status is "stopped". |
| 96 | + stopped_reason: SignalStoppedReason | str | None = None |
| 97 | + created_at: str | None = None |
| 98 | + baseline_at: str | None = None |
| 99 | + last_checked_at: str | None = None |
| 100 | + next_check_at: str | None = None |
| 101 | + person_url: str | None = None |
| 102 | + company_url: str | None = None |
| 103 | + post_url: str | None = None |
| 104 | + my_posts: bool | None = None |
| 105 | + term: str | list[str] | None = None |
| 106 | + filter: dict[str, Any] | None = None |
| 107 | + |
| 108 | + |
| 109 | +class SignalComment(PostComment): |
| 110 | + parent_comment_urn: str | None = None |
| 111 | + |
| 112 | + |
| 113 | +class SignalReaction(LinkedApiModel): |
| 114 | + actor: PostAuthor | None = None |
| 115 | + type: ReactionType | str | None = None |
| 116 | + |
| 117 | + |
| 118 | +class SignalEvent(LinkedApiModel): |
| 119 | + """One event a signal detected. Which subject fields are set depends on "type": "post" for |
| 120 | + postPublished and postFound, "post_url" with "comment" or "reaction", "viewer" for |
| 121 | + profileViewed, and "person_urn" with "person_url" for the connection events.""" |
| 122 | + |
| 123 | + id: str | None = None |
| 124 | + signal_id: str | None = None |
| 125 | + signal_type: SignalType | str | None = None |
| 126 | + label: str | None = None |
| 127 | + type: SignalEventType | str | None = None |
| 128 | + # When Linked API recorded the event, not when it happened on LinkedIn. |
| 129 | + detected_at: str | None = None |
| 130 | + post: SearchPostResult | None = None |
| 131 | + post_url: str | None = None |
| 132 | + comment: SignalComment | None = None |
| 133 | + reaction: SignalReaction | None = None |
| 134 | + viewer: ProfileViewer | None = None |
| 135 | + person_urn: str | None = None |
| 136 | + person_url: str | None = None |
0 commit comments