From 3f1b0c85bee4d2b8c8236a97ea13bafac499d679 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Mon, 20 Jan 2025 10:53:46 -0700 Subject: [PATCH] pkg: update constant names Signed-off-by: Sumner Evans --- pkg/connector/backfill.go | 12 ++--- pkg/connector/config.go | 7 +-- pkg/connector/handlematrix.go | 6 +-- pkg/linkedingo/client.go | 8 +-- pkg/linkedingo/http.go | 2 +- pkg/linkedingo/media.go | 4 +- pkg/linkedingo/messaging.go | 60 +++++++++++------------ pkg/linkedingo/page_loader.go | 4 +- pkg/linkedingo/realtime.go | 50 +++++++++---------- pkg/linkedingo/routing/endpoints.go | 22 ++++----- pkg/linkedingo/routing/payload/media.go | 4 +- pkg/linkedingo/routing/query/messaging.go | 22 ++++----- pkg/linkedingo/routing/store.go | 41 +++++++--------- pkg/linkedingo/types/events.go | 46 ++++++++--------- pkg/linkedingo/types/graphql.go | 12 ++--- pkg/linkedingo/types/http.go | 16 +++--- 16 files changed, 150 insertions(+), 166 deletions(-) diff --git a/pkg/connector/backfill.go b/pkg/connector/backfill.go index 93d4515..b0ef81f 100644 --- a/pkg/connector/backfill.go +++ b/pkg/connector/backfill.go @@ -14,7 +14,7 @@ import ( var _ bridgev2.BackfillingNetworkAPI = (*LinkedInClient)(nil) func (lc *LinkedInClient) FetchMessages(ctx context.Context, params bridgev2.FetchMessagesParams) (*bridgev2.FetchMessagesResponse, error) { - conversationUrn := string(params.Portal.PortalKey.ID) + conversationUrn := string(params.Portal.ID) variables := query.FetchMessagesVariables{ ConversationUrn: conversationUrn, @@ -43,10 +43,6 @@ func (lc *LinkedInClient) FetchMessages(ctx context.Context, params bridgev2.Fet return messages[j].DeliveredAt < messages[i].DeliveredAt }) - if err != nil { - return nil, err - } - backfilledMessages := make([]*bridgev2.BackfillMessage, len(messages)) cursor := networkid.PaginationCursor("") if len(messages) > 0 { @@ -58,12 +54,10 @@ func (lc *LinkedInClient) FetchMessages(ctx context.Context, params bridgev2.Fet } } - fetchMessagesResp := &bridgev2.FetchMessagesResponse{ + return &bridgev2.FetchMessagesResponse{ Messages: backfilledMessages, Cursor: cursor, HasMore: len(messages) >= 20, Forward: params.Forward, - } - - return fetchMessagesResp, nil + }, nil } diff --git a/pkg/connector/config.go b/pkg/connector/config.go index 779e321..7426d75 100644 --- a/pkg/connector/config.go +++ b/pkg/connector/config.go @@ -26,10 +26,7 @@ func (c *Config) UnmarshalYAML(node *yaml.Node) error { } c.displaynameTemplate, err = template.New("displayname").Parse(c.DisplaynameTemplate) - if err != nil { - return err - } - return nil + return err } func upgradeConfig(helper up.Helper) { @@ -41,7 +38,7 @@ type DisplaynameParams struct { LastName string } -func (c *Config) FormatDisplayname(firstName string, lastName string) string { +func (c *Config) FormatDisplayname(firstName, lastName string) string { var nameBuf strings.Builder err := c.displaynameTemplate.Execute(&nameBuf, &DisplaynameParams{ FirstName: firstName, diff --git a/pkg/connector/handlematrix.go b/pkg/connector/handlematrix.go index 223eacc..c149d51 100644 --- a/pkg/connector/handlematrix.go +++ b/pkg/connector/handlematrix.go @@ -70,12 +70,12 @@ func (lc *LinkedInClient) HandleMatrixMessage(ctx context.Context, msg *bridgev2 return nil, err } - attachmentType := payload.MESSAGING_FILE_ATTACHMENT + attachmentType := payload.MediaUploadFileAttachment if content.MsgType == event.MsgImage { - attachmentType = payload.MESSAGING_PHOTO_ATTACHMENT + attachmentType = payload.MediaUploadTypePhotoAttachment } - mediaMetadata, err := lc.client.UploadMedia(attachmentType, content.FileName, data, types.JSON_PLAINTEXT_UTF8) + mediaMetadata, err := lc.client.UploadMedia(attachmentType, content.FileName, data, types.ContentTypeJSONPlaintextUTF8) if err != nil { return nil, err } diff --git a/pkg/linkedingo/client.go b/pkg/linkedingo/client.go index 23c2e94..93e7632 100644 --- a/pkg/linkedingo/client.go +++ b/pkg/linkedingo/client.go @@ -81,11 +81,11 @@ func (c *Client) Logout() error { return err } - logoutUrl := fmt.Sprintf("%s?%s", routing.LOGOUT_URL, string(encodedQuery)) + logoutUrl := fmt.Sprintf("%s?%s", routing.LinkedInLogoutURL, string(encodedQuery)) - logoutDefinition := routing.RequestStoreDefinition[routing.LOGOUT_URL] + logoutDefinition := routing.RequestStoreDefinition[routing.LinkedInLogoutURL] headers := c.buildHeaders(logoutDefinition.HeaderOpts) - _, _, err = c.MakeRequest(logoutUrl, http.MethodGet, headers, make([]byte, 0), logoutDefinition.ContentType) + _, _, err = c.MakeRequest(logoutUrl, http.MethodGet, headers, nil, logoutDefinition.ContentType) _ = c.Disconnect() c.cookies.Store = make(map[cookies.LinkedInCookieName]string) return err @@ -113,7 +113,7 @@ func (c *Client) GetCurrentUserProfile() (*types.UserLoginProfile, error) { WithXLiLang: true, }) - _, data, err := c.MakeRequest(string(routing.VOYAGER_COMMON_ME_URL), http.MethodGet, headers, make([]byte, 0), types.JSON_LINKEDIN_NORMALIZED) + _, data, err := c.MakeRequest(string(routing.LinkedInVoyagerCommonMeURL), http.MethodGet, headers, make([]byte, 0), types.ContentTypeJSONLinkedInNormalized) if err != nil { return nil, err } diff --git a/pkg/linkedingo/http.go b/pkg/linkedingo/http.go index ec4e149..b76ada7 100644 --- a/pkg/linkedingo/http.go +++ b/pkg/linkedingo/http.go @@ -125,7 +125,7 @@ func (c *Client) makeRequestDirect(url string, method string, headers http.Heade return nil, nil, err } - if contentType != types.NONE { + if contentType != "" { headers.Set("content-type", string(contentType)) } diff --git a/pkg/linkedingo/media.go b/pkg/linkedingo/media.go index cbb6dd4..36135dd 100644 --- a/pkg/linkedingo/media.go +++ b/pkg/linkedingo/media.go @@ -13,7 +13,7 @@ import ( func (c *Client) UploadMedia(mediaUploadType payload.MediaUploadType, fileName string, mediaBytes []byte, contentType types.ContentType) (*response.MediaMetadata, error) { uploadMetadataQuery := query.DoActionQuery{ - Action: query.ACTION_UPLOAD, + Action: query.ActionUpload, } uploadMetadataPayload := payload.UploadMediaMetadataPayload{ MediaUploadType: mediaUploadType, @@ -21,7 +21,7 @@ func (c *Client) UploadMedia(mediaUploadType payload.MediaUploadType, fileName s Filename: fileName, } - _, respData, err := c.MakeRoutingRequest(routing.VOYAGER_MEDIA_UPLOAD_METADATA_URL, uploadMetadataPayload, uploadMetadataQuery) + _, respData, err := c.MakeRoutingRequest(routing.LinkedInVoyagerMediaUploadMetadataURL, uploadMetadataPayload, uploadMetadataQuery) if err != nil { return nil, err } diff --git a/pkg/linkedingo/messaging.go b/pkg/linkedingo/messaging.go index e98d001..6ac4dad 100644 --- a/pkg/linkedingo/messaging.go +++ b/pkg/linkedingo/messaging.go @@ -27,11 +27,11 @@ func (c *Client) GetThreads(variables query.GetThreadsVariables) (*response.Mess withCursor := variables.LastUpdatedBefore != 0 && variables.NextCursor != "" var queryId types.GraphQLQueryIDs if withCursor { - queryId = types.GRAPHQL_QUERY_ID_MESSENGER_CONVERSATIONS_WITH_CURSOR + queryId = types.GraphQLQueryIDMessengerConversationsWithCursor } else if variables.SyncToken != "" { - queryId = types.GRAPHQL_QUERY_ID_MESSENGER_CONVERSATIONS_WITH_SYNC_TOKEN + queryId = types.GraphQLQueryIDMessengerConversationsWithSyncToken } else { - queryId = types.GRAPHQL_QUERY_ID_MESSENGER_CONVERSATIONS + queryId = types.GraphQLQueryIDMessengerConversations } variablesQuery, err := variables.Encode() @@ -44,7 +44,7 @@ func (c *Client) GetThreads(variables query.GetThreadsVariables) (*response.Mess Variables: string(variablesQuery), } - _, respData, err := c.MakeRoutingRequest(routing.VOYAGER_MESSAGING_GRAPHQL_URL, nil, &threadQuery) + _, respData, err := c.MakeRoutingRequest(routing.LinkedInVoyagerMessagingGraphQLURL, nil, &threadQuery) if err != nil { return nil, err } @@ -68,11 +68,11 @@ func (c *Client) FetchMessages(variables query.FetchMessagesVariables) (*respons var queryId types.GraphQLQueryIDs if withCursor { - queryId = types.GRAPHQL_QUERY_ID_MESSENGER_MESSAGES_BY_CONVERSATION + queryId = types.GraphQLQueryIDMessengerMessagesByConversation } else if withAnchorTimestamp { - queryId = types.GRAPHQL_QUERY_ID_MESSENGER_MESSAGES_BY_ANCHOR_TIMESTAMP + queryId = types.GraphQLQueryIDMessengerMessagesByAnchorTimestamp } else { - queryId = types.GRAPHQL_QUERY_ID_MESSENGER_MESSAGES_BY_SYNC_TOKEN + queryId = types.GraphQLQueryIDMessengerMessagesBySyncToken } variablesQuery, err := variables.Encode() @@ -84,7 +84,7 @@ func (c *Client) FetchMessages(variables query.FetchMessagesVariables) (*respons Variables: string(variablesQuery), } - _, respData, err := c.MakeRoutingRequest(routing.VOYAGER_MESSAGING_GRAPHQL_URL, nil, &messagesQuery) + _, respData, err := c.MakeRoutingRequest(routing.LinkedInVoyagerMessagingGraphQLURL, nil, &messagesQuery) if err != nil { return nil, err } @@ -105,17 +105,17 @@ func (c *Client) FetchMessages(variables query.FetchMessagesVariables) (*respons } func (c *Client) EditMessage(messageUrn string, p payload.MessageBody) error { - editMessageUrl := fmt.Sprintf("%s/%s", routing.VOYAGER_MESSAGING_DASH_MESSENGER_MESSAGES_URL, url.QueryEscape(messageUrn)) + editMessageUrl := fmt.Sprintf("%s/%s", routing.LinkedInVoyagerMessagingDashMessengerMessagesURL, url.QueryEscape(messageUrn)) headerOpts := types.HeaderOpts{ WithCookies: true, WithCsrfToken: true, - Origin: string(routing.BASE_URL), + Origin: string(routing.LinkedInBaseURL), WithXLiTrack: true, WithXLiProtocolVer: true, WithXLiPageInstance: true, WithXLiLang: true, - Extra: map[string]string{"accept": string(types.JSON)}, + Extra: map[string]string{"accept": string(types.ContentTypeJSON)}, } headers := c.buildHeaders(headerOpts) @@ -132,7 +132,7 @@ func (c *Client) EditMessage(messageUrn string, p payload.MessageBody) error { return err } - resp, respBody, err := c.MakeRequest(editMessageUrl, http.MethodPost, headers, payloadBytes, types.PLAINTEXT_UTF8) + resp, respBody, err := c.MakeRequest(editMessageUrl, http.MethodPost, headers, payloadBytes, types.ContentTypePlaintextUTF8) if err != nil { return err } @@ -148,7 +148,7 @@ func (c *Client) EditMessage(messageUrn string, p payload.MessageBody) error { // so you do not have to set it if u dont want to func (c *Client) SendMessage(p payload.SendMessagePayload) (*response.MessageSentResponse, error) { actionQuery := query.DoActionQuery{ - Action: query.ACTION_CREATE_MESSAGE, + Action: query.ActionCreateMessage, } if p.MailboxUrn == "" { @@ -163,7 +163,7 @@ func (c *Client) SendMessage(p payload.SendMessagePayload) (*response.MessageSen p.Message.OriginToken = uuid.NewString() } - resp, respData, err := c.MakeRoutingRequest(routing.VOYAGER_MESSAGING_DASH_MESSENGER_MESSAGES_URL, p, actionQuery) + resp, respData, err := c.MakeRoutingRequest(routing.LinkedInVoyagerMessagingDashMessengerMessagesURL, p, actionQuery) if err != nil { return nil, err } @@ -182,14 +182,14 @@ func (c *Client) SendMessage(p payload.SendMessagePayload) (*response.MessageSen func (c *Client) StartTyping(conversationUrn string) error { actionQuery := query.DoActionQuery{ - Action: query.ACTION_TYPING, + Action: query.ActionTyping, } typingPayload := payload.StartTypingPayload{ ConversationUrn: conversationUrn, } - resp, _, err := c.MakeRoutingRequest(routing.VOYAGER_MESSAGING_DASH_MESSENGER_CONVERSATIONS_URL, typingPayload, actionQuery) + resp, _, err := c.MakeRoutingRequest(routing.LinkedInMessagingDashMessengerConversationsURL, typingPayload, actionQuery) if err != nil { return err } @@ -203,14 +203,14 @@ func (c *Client) StartTyping(conversationUrn string) error { func (c *Client) DeleteMessage(messageUrn string) error { actionQuery := query.DoActionQuery{ - Action: query.ACTION_RECALL, + Action: query.ActionRecall, } deleteMsgPayload := payload.DeleteMessagePayload{ MessageUrn: messageUrn, } - resp, _, err := c.MakeRoutingRequest(routing.VOYAGER_MESSAGING_DASH_MESSENGER_MESSAGES_URL, deleteMsgPayload, actionQuery) + resp, _, err := c.MakeRoutingRequest(routing.LinkedInVoyagerMessagingDashMessengerMessagesURL, deleteMsgPayload, actionQuery) if err != nil { return err } @@ -243,7 +243,7 @@ func (c *Client) MarkThreadRead(conversationUrns []string, read bool) (*response } queryStr := fmt.Sprintf("ids=List(%s)", queryUrnValues) - markReadUrl := fmt.Sprintf("%s?%s", routing.VOYAGER_MESSAGING_DASH_MESSENGER_CONVERSATIONS_URL, queryStr) + markReadUrl := fmt.Sprintf("%s?%s", routing.LinkedInMessagingDashMessengerConversationsURL, queryStr) patchEntitiesPayload := payload.PatchEntitiesPayload{ Entities: entities, } @@ -256,16 +256,16 @@ func (c *Client) MarkThreadRead(conversationUrns []string, read bool) (*response headerOpts := types.HeaderOpts{ WithCookies: true, WithCsrfToken: true, - Origin: string(routing.BASE_URL), + Origin: string(routing.LinkedInBaseURL), WithXLiTrack: true, WithXLiProtocolVer: true, WithXLiPageInstance: true, WithXLiLang: true, - Extra: map[string]string{"accept": string(types.JSON)}, + Extra: map[string]string{"accept": string(types.ContentTypeJSON)}, } headers := c.buildHeaders(headerOpts) - resp, respBody, err := c.MakeRequest(markReadUrl, http.MethodPost, headers, payloadBytes, types.PLAINTEXT_UTF8) + resp, respBody, err := c.MakeRequest(markReadUrl, http.MethodPost, headers, payloadBytes, types.ContentTypePlaintextUTF8) if err != nil { return nil, err } @@ -279,7 +279,7 @@ func (c *Client) MarkThreadRead(conversationUrns []string, read bool) (*response } func (c *Client) DeleteConversation(conversationUrn string) error { - deleteConvUrl := fmt.Sprintf("%s/%s", routing.VOYAGER_MESSAGING_DASH_MESSENGER_CONVERSATIONS_URL, url.QueryEscape(conversationUrn)) + deleteConvUrl := fmt.Sprintf("%s/%s", routing.LinkedInMessagingDashMessengerConversationsURL, url.QueryEscape(conversationUrn)) headers := c.buildHeaders(types.HeaderOpts{ WithCookies: true, @@ -288,13 +288,13 @@ func (c *Client) DeleteConversation(conversationUrn string) error { WithXLiPageInstance: true, WithXLiLang: true, WithXLiProtocolVer: true, - Origin: string(routing.BASE_URL), + Origin: string(routing.LinkedInBaseURL), Extra: map[string]string{ - "accept": string(types.GRAPHQL), + "accept": string(types.ContentTypeGraphQL), }, }) - resp, _, err := c.MakeRequest(deleteConvUrl, http.MethodDelete, headers, nil, types.NONE) + resp, _, err := c.MakeRequest(deleteConvUrl, http.MethodDelete, headers, nil, "") if err != nil { return err } @@ -308,15 +308,15 @@ func (c *Client) DeleteConversation(conversationUrn string) error { // pass true to second arg to react and pass false to unreact func (c *Client) SendReaction(p payload.SendReactionPayload, react bool) error { - action := query.ACTION_REACT_WITH_EMOJI + action := query.ActionReactWithEmoji if !react { - action = query.ACTION_UNREACT_WITH_EMOJI + action = query.ActionUnreactWithEmoji } actionQuery := query.DoActionQuery{ Action: action, } - resp, _, err := c.MakeRoutingRequest(routing.VOYAGER_MESSAGING_DASH_MESSENGER_MESSAGES_URL, p, actionQuery) + resp, _, err := c.MakeRoutingRequest(routing.LinkedInVoyagerMessagingDashMessengerMessagesURL, p, actionQuery) if err != nil { return err } @@ -339,7 +339,7 @@ func (c *Client) GetReactionsForEmoji(vars query.GetReactionsForEmojiVariables) Variables: string(variablesQuery), } - _, respData, err := c.MakeRoutingRequest(routing.VOYAGER_MESSAGING_GRAPHQL_URL, nil, &gqlQuery) + _, respData, err := c.MakeRoutingRequest(routing.LinkedInVoyagerMessagingGraphQLURL, nil, &gqlQuery) if err != nil { return nil, err } diff --git a/pkg/linkedingo/page_loader.go b/pkg/linkedingo/page_loader.go index cba14cb..3d660d7 100644 --- a/pkg/linkedingo/page_loader.go +++ b/pkg/linkedingo/page_loader.go @@ -33,9 +33,9 @@ func (c *Client) newPageLoader() *PageLoader { } func (pl *PageLoader) LoadMessagesPage() error { - messagesDefinition := routing.RequestStoreDefinition[routing.MESSAGES_BASE_URL] + messagesDefinition := routing.RequestStoreDefinition[routing.LinkedInMessagingBaseURL] headers := pl.client.buildHeaders(messagesDefinition.HeaderOpts) - _, respBody, err := pl.client.MakeRequest(string(routing.MESSAGES_BASE_URL), string(messagesDefinition.Method), headers, nil, types.NONE) + _, respBody, err := pl.client.MakeRequest(string(routing.LinkedInMessagingBaseURL), string(messagesDefinition.Method), headers, nil, "") if err != nil { return err } diff --git a/pkg/linkedingo/realtime.go b/pkg/linkedingo/realtime.go index e93c442..0a1d81a 100644 --- a/pkg/linkedingo/realtime.go +++ b/pkg/linkedingo/realtime.go @@ -41,11 +41,11 @@ func (c *Client) newRealtimeClient() *RealtimeClient { func (rc *RealtimeClient) Connect() error { extraHeaders := map[string]string{ - "accept": string(types.TEXT_EVENTSTREAM), + "accept": string(types.ContentTypeTextEventStream), "x-li-realtime-session": rc.sessionID, - "x-li-recipe-accept": string(types.JSON_LINKEDIN_NORMALIZED), - "x-li-query-accept": string(types.GRAPHQL), - "x-li-accept": string(types.JSON_LINKEDIN_NORMALIZED), + "x-li-recipe-accept": string(types.ContentTypeJSONLinkedInNormalized), + "x-li-query-accept": string(types.ContentTypeGraphQL), + "x-li-accept": string(types.ContentTypeJSONLinkedInNormalized), "x-li-recipe-map": `{"inAppAlertsTopic":"com.linkedin.voyager.dash.deco.identity.notifications.InAppAlert-51","professionalEventsTopic":"com.linkedin.voyager.dash.deco.events.ProfessionalEventDetailPage-57","topCardLiveVideoTopic":"com.linkedin.voyager.dash.deco.video.TopCardLiveVideo-9","tabBadgeUpdateTopic":"com.linkedin.voyager.dash.deco.notifications.RealtimeBadgingItemCountsEvent-1"}`, "x-li-query-map": `{"topicToGraphQLQueryParams":{"conversationsBroadcastTopic":{"queryId":"voyagerMessagingDashMessengerRealtimeDecoration.dc0088938e4fd0220c7694cdc1e7e2f6","variables":{},"extensions":{}},"conversationsTopic":{"queryId":"voyagerMessagingDashMessengerRealtimeDecoration.dc0088938e4fd0220c7694cdc1e7e2f6","variables":{},"extensions":{}},"conversationDeletesBroadcastTopic":{"queryId":"voyagerMessagingDashMessengerRealtimeDecoration.282abe5fa1a242cb76825c32dbbfaede","variables":{},"extensions":{}},"conversationDeletesTopic":{"queryId":"voyagerMessagingDashMessengerRealtimeDecoration.282abe5fa1a242cb76825c32dbbfaede","variables":{},"extensions":{}},"messageReactionSummariesBroadcastTopic":{"queryId":"voyagerMessagingDashMessengerRealtimeDecoration.3173250b03ea4f9f9e138a145cf3d9b4","variables":{},"extensions":{}},"messageReactionSummariesTopic":{"queryId":"voyagerMessagingDashMessengerRealtimeDecoration.3173250b03ea4f9f9e138a145cf3d9b4","variables":{},"extensions":{}},"messageSeenReceiptsBroadcastTopic":{"queryId":"voyagerMessagingDashMessengerRealtimeDecoration.56fd79ca10248ead05369fa7ab1868dc","variables":{},"extensions":{}},"messageSeenReceiptsTopic":{"queryId":"voyagerMessagingDashMessengerRealtimeDecoration.56fd79ca10248ead05369fa7ab1868dc","variables":{},"extensions":{}},"messagesBroadcastTopic":{"queryId":"voyagerMessagingDashMessengerRealtimeDecoration.9a690a85b608d1212fdaed40be3a1465","variables":{},"extensions":{}},"messagesTopic":{"queryId":"voyagerMessagingDashMessengerRealtimeDecoration.9a690a85b608d1212fdaed40be3a1465","variables":{},"extensions":{}},"replySuggestionBroadcastTopic":{"queryId":"voyagerMessagingDashMessengerRealtimeDecoration.412964c3f7f5a67fb0e56b6bb3a00028","variables":{},"extensions":{}},"replySuggestionTopicV2":{"queryId":"voyagerMessagingDashMessengerRealtimeDecoration.412964c3f7f5a67fb0e56b6bb3a00028","variables":{},"extensions":{}},"typingIndicatorsBroadcastTopic":{"queryId":"voyagerMessagingDashMessengerRealtimeDecoration.ad2174343a09cd7ef53b2e6f633695fe","variables":{},"extensions":{}},"typingIndicatorsTopic":{"queryId":"voyagerMessagingDashMessengerRealtimeDecoration.ad2174343a09cd7ef53b2e6f633695fe","variables":{},"extensions":{}},"messagingSecondaryPreviewBannerTopic":{"queryId":"voyagerMessagingDashRealtimeDecoration.60068248c1f5c683ad2557f7ccfdf188","variables":{},"extensions":{}},"reactionsTopic":{"queryId":"liveVideoVoyagerSocialDashRealtimeDecoration.b8b33dedca7efbe34f1d7e84c3b3aa81","variables":{},"extensions":{}},"commentsTopic":{"queryId":"liveVideoVoyagerSocialDashRealtimeDecoration.c582028e0b04485c17e4324d3f463e11","variables":{},"extensions":{}},"reactionsOnCommentsTopic":{"queryId":"liveVideoVoyagerSocialDashRealtimeDecoration.0a181b05b3751f72ae3eb489b77e3245","variables":{},"extensions":{}},"socialPermissionsPersonalTopic":{"queryId":"liveVideoVoyagerSocialDashRealtimeDecoration.170bf3bfbcca1da322e34f34f37fb954","variables":{},"extensions":{}},"liveVideoPostTopic":{"queryId":"liveVideoVoyagerFeedDashLiveUpdatesRealtimeDecoration.ccc245beb0ba0d99bd1df96a1fc53abc","variables":{},"extensions":{}},"generatedJobDescriptionsTopic":{"queryId":"voyagerHiringDashRealtimeDecoration.58501bc70ea8ce6b858527fb1be95007","variables":{},"extensions":{}},"eventToastsTopic":{"queryId":"voyagerEventsDashProfessionalEventsRealtimeResource.6b42abd3511e267e84a6765257deea50","variables":{},"extensions":{}},"coachStreamingResponsesTopic":{"queryId":"voyagerCoachDashGaiRealtimeDecoration.c5707587cf5d95191185235cf15d5129","variables":{},"extensions":{}},"realtimeSearchResultClustersTopic":{"queryId":"voyagerSearchDashRealtimeDecoration.545edd9da8c728b0854505ab6df11870","variables":{},"extensions":{}}}}`, } @@ -56,14 +56,14 @@ func (rc *RealtimeClient) Connect() error { WithXLiPageInstance: true, WithXLiProtocolVer: true, Extra: extraHeaders, - Referer: string(routing.MESSAGES_BASE_URL) + "/", + Referer: string(routing.LinkedInMessagingBaseURL) + "/", } headers := rc.client.buildHeaders(headerOpts) ctx, cancel := context.WithCancel(context.Background()) rc.cancelFunc = cancel - req, err := http.NewRequestWithContext(ctx, http.MethodGet, string(routing.REALTIME_CONNECT_URL)+"?rc=1", nil) // ("GET", string(routing.REALTIME_CONNECT_URL) + "?rc=1", nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, string(routing.LinkedInRealtimeConnectURL)+"?rc=1", nil) // ("GET", string(routing.REALTIME_CONNECT_URL) + "?rc=1", nil) if err != nil { return err } @@ -131,7 +131,7 @@ func (rc *RealtimeClient) Disconnect() error { if rc.client.eventHandler != nil { rc.client.eventHandler(event.ConnectionClosed{ - Reason: types.SELF_DISCONNECT_ISSUED, + Reason: types.ConnectionClosedReasonSelfDisconnectIssued, }) } @@ -141,7 +141,7 @@ func (rc *RealtimeClient) Disconnect() error { func (rc *RealtimeClient) processEvents(data map[types.RealtimeEvent]json.RawMessage) { for eventType, eventDataBytes := range data { switch eventType { - case types.DecoratedEvent: + case types.RealtimeEventDecoratedEvent: var decoratedEventResponse raw.DecoratedEventResponse err := json.Unmarshal(eventDataBytes, &decoratedEventResponse) if err != nil { @@ -149,9 +149,9 @@ func (rc *RealtimeClient) processEvents(data map[types.RealtimeEvent]json.RawMes } log.Println(string(eventDataBytes)) rc.processDecoratedEvent(decoratedEventResponse) - case types.HeartBeat: + case types.RealtimeEventHeartbeat: log.Println("received heartbeat") - case types.ClientConnectionEvent: + case types.RealtimeEventClientConnection: if rc.client.eventHandler != nil { rc.client.eventHandler(event.ConnectionReady{}) } @@ -165,7 +165,7 @@ func (rc *RealtimeClient) processDecoratedEvent(data raw.DecoratedEventResponse) var evtData any topic, topicChunks := parseRealtimeTopic(data.Topic) switch topic { - case types.MessagesTopic: + case types.RealtimeEventTopicMessages: renderFormat := data.Payload.Data.DecoratedMessage.Result.MessageBodyRenderFormat switch renderFormat { case response.RenderFormatDefault: @@ -179,29 +179,29 @@ func (rc *RealtimeClient) processDecoratedEvent(data raw.DecoratedEventResponse) default: rc.client.Logger.Warn().Any("json_data", data.Payload).Str("format", string(renderFormat)).Msg("Received unknown message body render format") } - case types.MessageReactionSummariesTopic: + case types.RealtimeEventTopicMessageReactionSummaries: evtData = data.Payload.Data.ToMessageReactionEvent() - case types.TypingIndicatorsTopic: + case types.RealtimeEventTopicTypingIndicators: evtData = data.Payload.Data.ToTypingIndicatorEvent() - case types.PresenceStatusTopic: + case types.RealtimeEventTopicPresenceStatus: fsdProfileId := topicChunks[:-0] log.Println("presence updated for user id:", fsdProfileId) evtData = data.Payload.ToPresenceStatusUpdateEvent(fsdProfileId[0]) - case types.MessageSeenReceiptsTopic: + case types.RealtimeEventTopicMessageSeenReceipts: evtData = data.Payload.Data.ToMessageSeenEvent() - case types.ConversationsTopic: + case types.RealtimeEventTopicConversations: evtData = data.Payload.Data.ToThreadUpdateEvent() - case types.ConversationsDeleteTopic: + case types.RealtimeEventTopicConversationsDelete: evtData = data.Payload.Data.ToThreadDeleteEvent() /* Ignored event topics */ - case types.JobPostingPersonalTopic: - case types.SocialPermissionsPersonalTopic: - case types.MessagingProgressIndicatorTopic: - case types.MessagingDataSyncTopic: - case types.InvitationsTopic: - case types.InAppAlertsTopic: - case types.ReplySuggestionTopicV2: - case types.TabBadgeUpdateTopic: + case types.RealtimeEventTopicJobPostingPersonal: + case types.RealtimeEventTopicSocialPermissionsPersonal: + case types.RealtimeEventTopicMessagingProgressIndicator: + case types.RealtimeEventTopicMessagingDataSync: + case types.RealtimeEventTopicInvitations: + case types.RealtimeEventTopicInAppAlerts: + case types.RealtimeEventTopicReplySuggestionV2: + case types.RealtimeEventTopicTabBadgeUpdate: break default: rc.client.Logger.Warn().Any("json_data", data.Payload).Str("event_topic", string(data.Topic)).Msg("Received unknown event topic") diff --git a/pkg/linkedingo/routing/endpoints.go b/pkg/linkedingo/routing/endpoints.go index 1d6490f..83fab26 100644 --- a/pkg/linkedingo/routing/endpoints.go +++ b/pkg/linkedingo/routing/endpoints.go @@ -1,18 +1,18 @@ package routing -const BASE_HOST = "www.linkedin.com" +const LinkedInBaseHost = "www.linkedin.com" type RequestEndpointURL string const ( - BASE_URL RequestEndpointURL = "https://" + BASE_HOST - MESSAGES_BASE_URL = BASE_URL + "/messaging" - VOYAGER_GRAPHQL_URL = BASE_URL + "/voyager/api/graphql" - VOYAGER_COMMON_ME_URL = BASE_URL + "/voyager/api/me" - VOYAGER_MESSAGING_GRAPHQL_URL = BASE_URL + "/voyager/api/voyagerMessagingGraphQL/graphql" - VOYAGER_MESSAGING_DASH_MESSENGER_MESSAGES_URL = BASE_URL + "/voyager/api/voyagerMessagingDashMessengerMessages" - VOYAGER_MESSAGING_DASH_MESSENGER_CONVERSATIONS_URL = BASE_URL + "/voyager/api/voyagerMessagingDashMessengerConversations" - VOYAGER_MEDIA_UPLOAD_METADATA_URL = BASE_URL + "/voyager/api/voyagerVideoDashMediaUploadMetadata" - REALTIME_CONNECT_URL = BASE_URL + "/realtime/connect" - LOGOUT_URL = BASE_URL + "/uas/logout" + LinkedInBaseURL RequestEndpointURL = "https://" + LinkedInBaseHost + LinkedInMessagingBaseURL = LinkedInBaseURL + "/messaging" + LinkedInVoyagerGraphQLURL = LinkedInBaseURL + "/voyager/api/graphql" + LinkedInVoyagerCommonMeURL = LinkedInBaseURL + "/voyager/api/me" + LinkedInVoyagerMessagingGraphQLURL = LinkedInBaseURL + "/voyager/api/voyagerMessagingGraphQL/graphql" + LinkedInVoyagerMessagingDashMessengerMessagesURL = LinkedInBaseURL + "/voyager/api/voyagerMessagingDashMessengerMessages" + LinkedInMessagingDashMessengerConversationsURL = LinkedInBaseURL + "/voyager/api/voyagerMessagingDashMessengerConversations" + LinkedInVoyagerMediaUploadMetadataURL = LinkedInBaseURL + "/voyager/api/voyagerVideoDashMediaUploadMetadata" + LinkedInRealtimeConnectURL = LinkedInBaseURL + "/realtime/connect" + LinkedInLogoutURL = LinkedInBaseURL + "/uas/logout" ) diff --git a/pkg/linkedingo/routing/payload/media.go b/pkg/linkedingo/routing/payload/media.go index 3848cb2..1d5ab7e 100644 --- a/pkg/linkedingo/routing/payload/media.go +++ b/pkg/linkedingo/routing/payload/media.go @@ -5,8 +5,8 @@ import "encoding/json" type MediaUploadType string const ( - MESSAGING_PHOTO_ATTACHMENT MediaUploadType = "MESSAGING_PHOTO_ATTACHMENT" - MESSAGING_FILE_ATTACHMENT MediaUploadType = "MESSAGING_FILE_ATTACHMENT" + MediaUploadTypePhotoAttachment MediaUploadType = "MESSAGING_PHOTO_ATTACHMENT" + MediaUploadFileAttachment MediaUploadType = "MESSAGING_FILE_ATTACHMENT" ) type UploadMediaMetadataPayload struct { diff --git a/pkg/linkedingo/routing/query/messaging.go b/pkg/linkedingo/routing/query/messaging.go index 08b410e..8fefe1e 100644 --- a/pkg/linkedingo/routing/query/messaging.go +++ b/pkg/linkedingo/routing/query/messaging.go @@ -7,12 +7,12 @@ import ( type Action string const ( - ACTION_CREATE_MESSAGE Action = "createMessage" - ACTION_TYPING Action = "typing" - ACTION_UPLOAD Action = "upload" - ACTION_RECALL Action = "recall" - ACTION_REACT_WITH_EMOJI Action = "reactWithEmoji" - ACTION_UNREACT_WITH_EMOJI Action = "unreactWithEmoji" + ActionCreateMessage Action = "createMessage" + ActionTyping Action = "typing" + ActionUpload Action = "upload" + ActionRecall Action = "recall" + ActionReactWithEmoji Action = "reactWithEmoji" + ActionUnreactWithEmoji Action = "unreactWithEmoji" ) type DoActionQuery struct { @@ -26,11 +26,11 @@ func (q DoActionQuery) Encode() ([]byte, error) { type InboxCategory string const ( - INBOX_CATEGORY_OTHER InboxCategory = "OTHER" - INBOX_CATEGORY_ARCHIVE InboxCategory = "ARCHIVE" - INBOX_CATEGORY_INBOX InboxCategory = "INBOX" - INBOX_CATEGORY_PRIMARY InboxCategory = "PRIMARY_INBOX" - INBOX_CATEGORY_SECONDARY InboxCategory = "SECONDARY_INBOX" + InboxCategoryOther InboxCategory = "OTHER" + InboxCategoryArchive InboxCategory = "ARCHIVE" + InboxCategoryInbox InboxCategory = "INBOX" + InboxCategoryPrimary InboxCategory = "PRIMARY_INBOX" + InboxCategorySecondary InboxCategory = "SECONDARY_INBOX" ) type GetThreadsVariables struct { diff --git a/pkg/linkedingo/routing/store.go b/pkg/linkedingo/routing/store.go index 4a36f13..b4108d6 100644 --- a/pkg/linkedingo/routing/store.go +++ b/pkg/linkedingo/routing/store.go @@ -23,9 +23,8 @@ type RequestEndpointInfo struct { } var RequestStoreDefinition = map[RequestEndpointURL]RequestEndpointInfo{ - MESSAGES_BASE_URL: { - Method: http.MethodGet, - ContentType: types.NONE, + LinkedInMessagingBaseURL: { + Method: http.MethodGet, HeaderOpts: types.HeaderOpts{ WithCookies: true, Extra: map[string]string{ @@ -37,25 +36,24 @@ var RequestStoreDefinition = map[RequestEndpointURL]RequestEndpointInfo{ }, }, }, - VOYAGER_MESSAGING_GRAPHQL_URL: { - Method: http.MethodGet, - ContentType: types.NONE, + LinkedInVoyagerMessagingGraphQLURL: { + Method: http.MethodGet, HeaderOpts: types.HeaderOpts{ WithCookies: true, WithCsrfToken: true, WithXLiTrack: true, WithXLiPageInstance: true, WithXLiProtocolVer: true, - Referer: string(MESSAGES_BASE_URL) + "/", + Referer: string(LinkedInMessagingBaseURL) + "/", Extra: map[string]string{ - "accept": string(types.GRAPHQL), + "accept": string(types.ContentTypeGraphQL), }, }, ResponseDefinition: response.GraphQlResponse{}, }, - VOYAGER_MESSAGING_DASH_MESSENGER_MESSAGES_URL: { + LinkedInVoyagerMessagingDashMessengerMessagesURL: { Method: http.MethodPost, - ContentType: types.PLAINTEXT_UTF8, + ContentType: types.ContentTypePlaintextUTF8, HeaderOpts: types.HeaderOpts{ WithCookies: true, WithCsrfToken: true, @@ -63,16 +61,16 @@ var RequestStoreDefinition = map[RequestEndpointURL]RequestEndpointInfo{ WithXLiPageInstance: true, WithXLiTrack: true, WithXLiProtocolVer: true, - Origin: string(BASE_URL), + Origin: string(LinkedInBaseURL), Extra: map[string]string{ - "accept": string(types.JSON), + "accept": string(types.ContentTypeJSON), }, }, ResponseDefinition: response.MessageSentResponse{}, }, - VOYAGER_MESSAGING_DASH_MESSENGER_CONVERSATIONS_URL: { + LinkedInMessagingDashMessengerConversationsURL: { Method: http.MethodPost, - ContentType: types.PLAINTEXT_UTF8, + ContentType: types.ContentTypePlaintextUTF8, HeaderOpts: types.HeaderOpts{ WithCookies: true, WithCsrfToken: true, @@ -80,15 +78,15 @@ var RequestStoreDefinition = map[RequestEndpointURL]RequestEndpointInfo{ WithXLiPageInstance: true, WithXLiProtocolVer: true, WithXLiLang: true, - Origin: string(BASE_URL), + Origin: string(LinkedInBaseURL), Extra: map[string]string{ - "accept": string(types.JSON), + "accept": string(types.ContentTypeJSON), }, }, }, - VOYAGER_MEDIA_UPLOAD_METADATA_URL: { + LinkedInVoyagerMediaUploadMetadataURL: { Method: http.MethodPost, - ContentType: types.JSON_PLAINTEXT_UTF8, + ContentType: types.ContentTypeJSONPlaintextUTF8, HeaderOpts: types.HeaderOpts{ WithCookies: true, WithCsrfToken: true, @@ -97,14 +95,13 @@ var RequestStoreDefinition = map[RequestEndpointURL]RequestEndpointInfo{ WithXLiProtocolVer: true, WithXLiLang: true, Extra: map[string]string{ - "accept": string(types.JSON_LINKEDIN_NORMALIZED), + "accept": string(types.ContentTypeJSONLinkedInNormalized), }, }, ResponseDefinition: response.UploadMediaMetadataResponse{}, }, - LOGOUT_URL: { - Method: http.MethodGet, - ContentType: types.NONE, + LinkedInLogoutURL: { + Method: http.MethodGet, HeaderOpts: types.HeaderOpts{ WithCookies: true, }, diff --git a/pkg/linkedingo/types/events.go b/pkg/linkedingo/types/events.go index 49ab735..940d072 100644 --- a/pkg/linkedingo/types/events.go +++ b/pkg/linkedingo/types/events.go @@ -3,29 +3,29 @@ package types type RealtimeEvent string const ( - ClientConnectionEvent RealtimeEvent = "com.linkedin.realtimefrontend.ClientConnection" - DecoratedEvent RealtimeEvent = "com.linkedin.realtimefrontend.DecoratedEvent" - HeartBeat RealtimeEvent = "com.linkedin.realtimefrontend.Heartbeat" + RealtimeEventClientConnection RealtimeEvent = "com.linkedin.realtimefrontend.ClientConnection" + RealtimeEventDecoratedEvent RealtimeEvent = "com.linkedin.realtimefrontend.DecoratedEvent" + RealtimeEventHeartbeat RealtimeEvent = "com.linkedin.realtimefrontend.Heartbeat" ) type RealtimeEventTopic string const ( - ConversationsTopic RealtimeEventTopic = "conversationsTopic" - ConversationsDeleteTopic RealtimeEventTopic = "conversationDeletesTopic" - MessageSeenReceiptsTopic RealtimeEventTopic = "messageSeenReceiptsTopic" - MessagesTopic RealtimeEventTopic = "messagesTopic" - ReplySuggestionTopicV2 RealtimeEventTopic = "replySuggestionTopicV2" - TabBadgeUpdateTopic RealtimeEventTopic = "tabBadgeUpdateTopic" - TypingIndicatorsTopic RealtimeEventTopic = "typingIndicatorsTopic" - InvitationsTopic RealtimeEventTopic = "invitationsTopic" - InAppAlertsTopic RealtimeEventTopic = "inAppAlertsTopic" - MessageReactionSummariesTopic RealtimeEventTopic = "messageReactionSummariesTopic" - SocialPermissionsPersonalTopic RealtimeEventTopic = "socialPermissionsPersonalTopic" - JobPostingPersonalTopic RealtimeEventTopic = "jobPostingPersonalTopic" - MessagingProgressIndicatorTopic RealtimeEventTopic = "messagingProgressIndicatorTopic" - MessagingDataSyncTopic RealtimeEventTopic = "messagingDataSyncTopic" - PresenceStatusTopic RealtimeEventTopic = "presenceStatusTopic" + RealtimeEventTopicConversations RealtimeEventTopic = "conversationsTopic" + RealtimeEventTopicConversationsDelete RealtimeEventTopic = "conversationDeletesTopic" + RealtimeEventTopicMessageSeenReceipts RealtimeEventTopic = "messageSeenReceiptsTopic" + RealtimeEventTopicMessages RealtimeEventTopic = "messagesTopic" + RealtimeEventTopicReplySuggestionV2 RealtimeEventTopic = "replySuggestionTopicV2" + RealtimeEventTopicTabBadgeUpdate RealtimeEventTopic = "tabBadgeUpdateTopic" + RealtimeEventTopicTypingIndicators RealtimeEventTopic = "typingIndicatorsTopic" + RealtimeEventTopicInvitations RealtimeEventTopic = "invitationsTopic" + RealtimeEventTopicInAppAlerts RealtimeEventTopic = "inAppAlertsTopic" + RealtimeEventTopicMessageReactionSummaries RealtimeEventTopic = "messageReactionSummariesTopic" + RealtimeEventTopicSocialPermissionsPersonal RealtimeEventTopic = "socialPermissionsPersonalTopic" + RealtimeEventTopicJobPostingPersonal RealtimeEventTopic = "jobPostingPersonalTopic" + RealtimeEventTopicMessagingProgressIndicator RealtimeEventTopic = "messagingProgressIndicatorTopic" + RealtimeEventTopicMessagingDataSync RealtimeEventTopic = "messagingDataSyncTopic" + RealtimeEventTopicPresenceStatus RealtimeEventTopic = "presenceStatusTopic" ) type LinkedInAPIType string @@ -40,19 +40,19 @@ const ( type RealtimeEventType string const ( - MessageEvent RealtimeEventType = "com.linkedin.voyager.messaging.event.MessageEvent" + RealtimeEventTypeMessageEvent RealtimeEventType = "com.linkedin.voyager.messaging.event.MessageEvent" ) type PresenceAvailabilityStatus string const ( - Online PresenceAvailabilityStatus = "ONLINE" - Offline PresenceAvailabilityStatus = "OFFLINE" + PresenceAvailabilityStatusOnline PresenceAvailabilityStatus = "ONLINE" + PresenceAvailabilityStatusOffline PresenceAvailabilityStatus = "OFFLINE" ) type ConnectionClosedReason string const ( - SELF_DISCONNECT_ISSUED ConnectionClosedReason = "client called Disconnect() method" - CONNECTION_DROPPED ConnectionClosedReason = "real-time client lost connection to the server" + ConnectionClosedReasonSelfDisconnectIssued ConnectionClosedReason = "client called Disconnect() method" + SecondClosedReasonDropped ConnectionClosedReason = "real-time client lost connection to the server" ) diff --git a/pkg/linkedingo/types/graphql.go b/pkg/linkedingo/types/graphql.go index adb943a..650a9d1 100644 --- a/pkg/linkedingo/types/graphql.go +++ b/pkg/linkedingo/types/graphql.go @@ -3,10 +3,10 @@ package types type GraphQLQueryIDs string const ( - GRAPHQL_QUERY_ID_MESSENGER_CONVERSATIONS GraphQLQueryIDs = "messengerConversations.95e0a4b80fbc6bc53550e670d34d05d9" - GRAPHQL_QUERY_ID_MESSENGER_CONVERSATIONS_WITH_CURSOR GraphQLQueryIDs = "messengerConversations.18240d6a3ac199067a703996eeb4b163" - GRAPHQL_QUERY_ID_MESSENGER_CONVERSATIONS_WITH_SYNC_TOKEN GraphQLQueryIDs = "messengerConversations.be2479ed77df3dd407dd90efc8ac41de" - GRAPHQL_QUERY_ID_MESSENGER_MESSAGES_BY_SYNC_TOKEN GraphQLQueryIDs = "messengerMessages.d1b494ac18c24c8be71ea07b5bd1f831" - GRAPHQL_QUERY_ID_MESSENGER_MESSAGES_BY_ANCHOR_TIMESTAMP GraphQLQueryIDs = "messengerMessages.b52340f92136e74c2aab21dac7cf7ff2" - GRAPHQL_QUERY_ID_MESSENGER_MESSAGES_BY_CONVERSATION GraphQLQueryIDs = "messengerMessages.86ca573adc64110d94d8bce89c5b2f3b" + GraphQLQueryIDMessengerConversations GraphQLQueryIDs = "messengerConversations.95e0a4b80fbc6bc53550e670d34d05d9" + GraphQLQueryIDMessengerConversationsWithCursor GraphQLQueryIDs = "messengerConversations.18240d6a3ac199067a703996eeb4b163" + GraphQLQueryIDMessengerConversationsWithSyncToken GraphQLQueryIDs = "messengerConversations.be2479ed77df3dd407dd90efc8ac41de" + GraphQLQueryIDMessengerMessagesBySyncToken GraphQLQueryIDs = "messengerMessages.d1b494ac18c24c8be71ea07b5bd1f831" + GraphQLQueryIDMessengerMessagesByAnchorTimestamp GraphQLQueryIDs = "messengerMessages.b52340f92136e74c2aab21dac7cf7ff2" + GraphQLQueryIDMessengerMessagesByConversation GraphQLQueryIDs = "messengerMessages.86ca573adc64110d94d8bce89c5b2f3b" ) diff --git a/pkg/linkedingo/types/http.go b/pkg/linkedingo/types/http.go index cd97d1b..aee9e09 100644 --- a/pkg/linkedingo/types/http.go +++ b/pkg/linkedingo/types/http.go @@ -3,16 +3,12 @@ package types type ContentType string const ( - NONE ContentType = "" - JSON ContentType = "application/json" - JSON_PLAINTEXT_UTF8 ContentType = "application/json; charset=UTF-8" - JSON_LINKEDIN_NORMALIZED ContentType = "application/vnd.linkedin.normalized+json+2.1" - FORM ContentType = "application/x-www-form-urlencoded" - GRAPHQL ContentType = "application/graphql" - TEXT_EVENTSTREAM ContentType = "text/event-stream" - PLAINTEXT_UTF8 ContentType = "text/plain;charset=UTF-8" - IMAGE_JPEG ContentType = "image/jpeg" - VIDEO_MP4 ContentType = "video/mp4" + ContentTypeJSON ContentType = "application/json" + ContentTypeJSONPlaintextUTF8 ContentType = "application/json; charset=UTF-8" + ContentTypeJSONLinkedInNormalized ContentType = "application/vnd.linkedin.normalized+json+2.1" + ContentTypeGraphQL ContentType = "application/graphql" + ContentTypeTextEventStream ContentType = "text/event-stream" + ContentTypePlaintextUTF8 ContentType = "text/plain;charset=UTF-8" ) type HeaderOpts struct {