linkedin-private-api
Advanced tools
Comparing version 1.0.1 to 1.0.2
import { Client } from '../core/client'; | ||
import { Conversation, ConversationId } from '../entities/conversation.entity'; | ||
import { ProfileId } from '../entities/mini-profile.entity'; | ||
import { ConversationScroller } from '../scrollers/conversation.scroller'; | ||
@@ -12,3 +13,4 @@ export declare class ConversationRepository { | ||
}): Promise<Conversation>; | ||
getConversations({ createdBefore }?: { | ||
getConversations({ recipients, createdBefore, }?: { | ||
recipients?: ProfileId | ProfileId[]; | ||
createdBefore?: Date; | ||
@@ -15,0 +17,0 @@ }): ConversationScroller; |
@@ -9,2 +9,3 @@ "use strict"; | ||
const participantToProfileId = (participant) => participant.replace(/urn:li:fs_messagingMember:\(|\)/g, '').split(',')[1]; | ||
const transformConversationId = (conversationUrn) => conversationUrn.replace('urn:li:fs_conversation:', ''); | ||
const transformConversations = ({ conversations = [], profiles = {}, }) => conversations.map(conversation => { | ||
@@ -18,3 +19,3 @@ const participants = lodash_1.map(conversation['*participants'], participant => { | ||
participants, | ||
conversationId: conversation.entityUrn.replace('urn:li:fs_conversation:', ''), | ||
conversationId: transformConversationId(conversation.entityUrn), | ||
}; | ||
@@ -35,7 +36,7 @@ }); | ||
} | ||
getConversations({ createdBefore } = {}) { | ||
return new conversation_scroller_1.ConversationScroller({ fetchConversations: this.fetchConversations.bind(this), createdBefore }); | ||
getConversations({ recipients, createdBefore, } = {}) { | ||
return new conversation_scroller_1.ConversationScroller({ fetchConversations: this.fetchConversations.bind(this), recipients, createdBefore }); | ||
} | ||
async fetchConversations({ createdBefore }) { | ||
const res = await this.client.request.conversation.getConversations({ createdBefore }); | ||
async fetchConversations({ recipients, createdBefore, }) { | ||
const res = await this.client.request.conversation.getConversations({ recipients, createdBefore }); | ||
const conversations = res.included.filter(p => p.$type === linkedin_conversation_entity_1.CONVERSATION_TYPE); | ||
@@ -42,0 +43,0 @@ const profiles = profile_repository_1.getProfilesFromResponse(res); |
@@ -0,1 +1,2 @@ | ||
import { ProfileId } from './../entities/mini-profile.entity'; | ||
import { Client } from '../core/client'; | ||
@@ -14,4 +15,4 @@ import { ConversationId } from '../entities/conversation.entity'; | ||
}): MessageScroller; | ||
sendMessage({ conversationId, text, }: { | ||
conversationId: ConversationId; | ||
sendMessage({ profileId, text }: { | ||
profileId: ProfileId; | ||
text: string; | ||
@@ -18,0 +19,0 @@ }): Promise<MessageEventCreateResponse>; |
@@ -16,5 +16,5 @@ "use strict"; | ||
} | ||
async sendMessage({ conversationId, text, }) { | ||
async sendMessage({ profileId, text }) { | ||
var _a; | ||
const response = await this.client.request.message.sendMessage({ conversationId, text }); | ||
const response = await this.client.request.message.sendMessage({ profileId, text }); | ||
return { ...(_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.value, text }; | ||
@@ -21,0 +21,0 @@ } |
import { LinkedInRequest } from '../core/linkedin-request'; | ||
import { ConversationId } from '../entities/conversation.entity'; | ||
import { ProfileId } from '../entities/mini-profile.entity'; | ||
import { GetConversationResponse } from '../responses/conversation.response.get'; | ||
@@ -13,5 +14,6 @@ import { GetConversationsResponse } from '../responses/conversations.response.get'; | ||
}): Promise<GetConversationResponse>; | ||
getConversations({ createdBefore }: { | ||
getConversations({ recipients, createdBefore, }: { | ||
recipients?: ProfileId | ProfileId[]; | ||
createdBefore?: Date; | ||
}): Promise<GetConversationsResponse>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ConversationRequest = void 0; | ||
const lodash_1 = require("lodash"); | ||
class ConversationRequest { | ||
@@ -16,5 +17,6 @@ constructor({ request }) { | ||
} | ||
getConversations({ createdBefore }) { | ||
getConversations({ recipients, createdBefore, }) { | ||
const queryParams = { | ||
keyVersion: 'LEGACY_INBOX', | ||
...(recipients && { q: 'participants', recipients: lodash_1.castArray(recipients) }), | ||
...(createdBefore && { createdBefore: createdBefore.getTime() }), | ||
@@ -21,0 +23,0 @@ }; |
@@ -0,1 +1,2 @@ | ||
import { ProfileId } from 'src/entities'; | ||
import { LinkedInRequest } from '../core/linkedin-request'; | ||
@@ -10,4 +11,4 @@ import { ConversationId } from '../entities/conversation.entity'; | ||
}); | ||
sendMessage({ conversationId, text }: { | ||
conversationId: ConversationId; | ||
sendMessage({ profileId, text }: { | ||
profileId: ProfileId; | ||
text: string; | ||
@@ -14,0 +15,0 @@ }): Promise<SendMessageResponse>; |
@@ -8,3 +8,3 @@ "use strict"; | ||
} | ||
sendMessage({ conversationId, text }) { | ||
sendMessage({ profileId, text }) { | ||
const queryParams = { | ||
@@ -14,14 +14,20 @@ action: 'create', | ||
const payload = { | ||
eventCreate: { | ||
originToken: '54b3a724-59c5-4cf2-adbd-660483010a87', | ||
value: { | ||
'com.linkedin.voyager.messaging.create.MessageCreate': { | ||
attributedBody: { text, attributes: [] }, | ||
attachments: [], | ||
keyVersion: 'LEGACY_INBOX', | ||
conversationCreate: { | ||
eventCreate: { | ||
value: { | ||
'com.linkedin.voyager.messaging.create.MessageCreate': { | ||
attributedBody: { | ||
text, | ||
attributes: [], | ||
}, | ||
attachments: [], | ||
}, | ||
}, | ||
}, | ||
subtype: 'MEMBER_TO_MEMBER', | ||
recipients: [profileId], | ||
}, | ||
dedupeByClientGeneratedToken: false, | ||
}; | ||
return this.request.post(`messaging/conversations/${conversationId}/events`, payload, { | ||
return this.request.post('messaging/conversations', payload, { | ||
params: queryParams, | ||
@@ -28,0 +34,0 @@ }); |
@@ -0,4 +1,6 @@ | ||
import { ProfileId } from '../entities'; | ||
import { Conversation } from '../entities/conversation.entity'; | ||
import { CreatedBeforeScroller } from './created-before-scroller'; | ||
declare type FetchConversations = ({ createdBefore }: { | ||
declare type FetchConversations = ({ createdBefore, }: { | ||
recipients?: ProfileId | ProfileId[]; | ||
createdBefore?: Date; | ||
@@ -9,4 +11,6 @@ }) => Promise<Conversation[]>; | ||
fieldName: 'lastActivityAt'; | ||
constructor({ fetchConversations, createdBefore, }: { | ||
recipients?: ProfileId | ProfileId[]; | ||
constructor({ fetchConversations, recipients, createdBefore, }: { | ||
fetchConversations: FetchConversations; | ||
recipients?: ProfileId | ProfileId[]; | ||
createdBefore?: Date; | ||
@@ -13,0 +17,0 @@ }); |
@@ -7,5 +7,6 @@ "use strict"; | ||
class ConversationScroller extends created_before_scroller_1.CreatedBeforeScroller { | ||
constructor({ fetchConversations, createdBefore, }) { | ||
constructor({ fetchConversations, recipients, createdBefore, }) { | ||
super({ createdBefore }); | ||
this.fieldName = 'lastActivityAt'; | ||
this.recipients = recipients; | ||
this.fetchConversations = fetchConversations; | ||
@@ -16,2 +17,3 @@ } | ||
...(lodash_1.isUndefined(this.createdBefore) ? {} : { createdBefore: new Date(this.createdBefore) }), | ||
...(this.recipients && { recipients: this.recipients }), | ||
}); | ||
@@ -18,0 +20,0 @@ } |
@@ -9,5 +9,8 @@ "use strict"; | ||
const encodedParams = lodash_1.mapValues(params, value => { | ||
if (!lodash_1.isPlainObject(value)) { | ||
return value; | ||
if (!lodash_1.isArray(value) && !lodash_1.isPlainObject(value)) { | ||
return value.toString(); | ||
} | ||
if (lodash_1.isArray(value)) { | ||
return `List(${value.join(',')})`; | ||
} | ||
const encodedList = lodash_1.reduce(value, (res, filterVal, filterKey) => `${res}${res ? ',' : ''}${encodeFilter(filterVal, filterKey)}`, ''); | ||
@@ -14,0 +17,0 @@ return `List(${encodedList})`; |
{ | ||
"name": "linkedin-private-api", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -13,3 +13,3 @@ # NodeJS LinkedIn Private API | ||
## Example usage | ||
See a list of examples here [here](TBD). | ||
See a list of examples here [here](https://github.com/eilonmore/linkedin-private-api/tree/master/examples). | ||
```typescript | ||
@@ -26,3 +26,3 @@ import { Client } from 'linkedin-private-api'; | ||
// Search for profiles and send invitation | ||
// Search for profiles and send an invitation | ||
const peopleScroller = await client.search.searchPeople({ keywords: 'Bill Gates' }); | ||
@@ -40,13 +40,15 @@ const [billGates] = await peopleScroller.scrollNext(); | ||
// Get conversations and send message | ||
const conversationScroller = await client.conversation.getConversations(); | ||
const conversations = await conversationScroller.scrollNext(); | ||
const billGatesConversation = conversations.find( | ||
conversation => conversation.participants.find(participant => participant.profileId === billGates.profileId) | ||
) | ||
// Get conversation | ||
const [billConversation] = await client.conversation.getConversations({ | ||
recipients: billGates.profileId | ||
}).scrollNext(); | ||
const conversationMessages = await client.message.getMessages({ | ||
conversationId: billConversation.conversationId | ||
}).scrollNext() | ||
// Send a message | ||
const sentMessage = await client.message.sendMessage({ | ||
conversationId: billGatesConversation.conversationId, | ||
text: 'Hey!', | ||
profileId: billGates.profileId, | ||
text: 'Hey Bill!', | ||
}); | ||
@@ -64,18 +66,18 @@ })(); | ||
* Single entity getters - example: ``conversation.getConversation({ conversationId: CONVERSATION_ID })`` | ||
Single entity getters return a [LinkedIn Entity](TBD). | ||
Single entity getters return a [LinkedIn Entity](#entities). | ||
* Multiple entities getters - for example ``invitation.getSentInvitations({ skip: 10, limit: 5 })`` | ||
Multiple entities getters return a [Scroller](TBD). | ||
Multiple entities getters return a [Scroller](#scrollers). | ||
* Mutations - for example ``invitation.sendInvitation({ ... })`` | ||
Mutatios return a [Response entity](TBD) | ||
Mutations return a [Response entity](#entities) | ||
|Name|Example Usage|Docs Reference| | ||
|-|-|-| | ||
|`login`|`client.login.userPass(...)`|[Login Docs](TBD)| | ||
|`search`|`client.search.searchPeople()`|[Search Docs](TBD)| | ||
|`profile`|`client.profile.getOwnProfile()`|[Profile Docs](TBD)| | ||
|`invitation`|`client.invitation.getReceivedInvitations()`|[Invitation Docs](TBD)| | ||
|`conversation`|`client.conversation.getConversation(...)`|[Conversation Docs](TBD)| | ||
|`message`|`client.message.getMessages(...)`|[Conversation Docs](TBD)| | ||
|`login`|`client.login.userPass(...)`|[Login Docs](https://github.com/eilonmore/linkedin-private-api/blob/master/docs/classes/_src_core_login_.login.md)| | ||
|`search`|`client.search.searchPeople()`|[Search Docs](https://github.com/eilonmore/linkedin-private-api/blob/master/docs/classes/_src_repositories_search_repository_.searchrepository.md)| | ||
|`profile`|`client.profile.getOwnProfile()`|[Profile Docs](https://github.com/eilonmore/linkedin-private-api/blob/master/docs/classes/_src_repositories_profile_repository_.profilerepository.md)| | ||
|`invitation`|`client.invitation.getReceivedInvitations()`|[Invitation Docs](https://github.com/eilonmore/linkedin-private-api/blob/master/docs/classes/_src_repositories_invitation_repository_.invitationrepository.md)| | ||
|`conversation`|`client.conversation.getConversation(...)`|[Conversation Docs](https://github.com/eilonmore/linkedin-private-api/blob/master/docs/classes/_src_repositories_conversation_repository_.conversationrepository.md)| | ||
|`message`|`client.message.getMessages(...)`|[Message Docs](https://github.com/eilonmore/linkedin-private-api/blob/master/docs/classes/_src_repositories_message_repository_.messagerepository.md)| | ||
@@ -87,14 +89,14 @@ | ||
The full list of entities can be found [here](TBD), this is the list of the most important ones: | ||
The full list of entities can be found [here](https://github.com/eilonmore/linkedin-private-api/blob/master/docs/modules/_src_entities_index_.md#attributetext), this is the list of the most important ones: | ||
|Entities| | ||
|-| | ||
|[Profile](TBD)| | ||
|[MiniProfile](TBD)| | ||
|[Invitation](TBD)| | ||
|[Conversation](TBD)| | ||
|[Message](TBD)| | ||
|[CompanySearchHit](TBD)| | ||
|[PeopleSearchHit](TBD)| | ||
|[MessageCreateResponse](TBD)| | ||
|[Profile](https://github.com/eilonmore/linkedin-private-api/blob/master/docs/interfaces/_src_entities_profile_entity_.profile.md)| | ||
|[MiniProfile](https://github.com/eilonmore/linkedin-private-api/blob/master/docs/interfaces/_src_entities_mini_profile_entity_.miniprofile.md)| | ||
|[Invitation](https://github.com/eilonmore/linkedin-private-api/blob/master/docs/interfaces/_src_entities_invitation_entity_.invitation.md)| | ||
|[Conversation](https://github.com/eilonmore/linkedin-private-api/blob/master/docs/interfaces/_src_entities_conversation_entity_.conversation.md)| | ||
|[Message](https://github.com/eilonmore/linkedin-private-api/blob/master/docs/interfaces/_src_entities_message_event_entity_.messageevent.md)| | ||
|[CompanySearchHit](https://github.com/eilonmore/linkedin-private-api/blob/master/docs/interfaces/_src_entities_company_search_hit_entity_.companysearchhit.md)| | ||
|[PeopleSearchHit](https://github.com/eilonmore/linkedin-private-api/blob/master/docs/interfaces/_src_entities_people_search_hit_entity_.peoplesearchhit.md)| | ||
|[MessageCreateResponse](https://github.com/eilonmore/linkedin-private-api/blob/master/docs/interfaces/_src_entities_message_create_response_entity_.messageeventcreateresponse.md)| | ||
@@ -118,3 +120,3 @@ | ||
// index scroller | ||
let companiesScroller = await client.search.searchCompanies(); | ||
let companiesScroller = client.search.searchCompanies(); | ||
let companies = await companiesScroller.scrollNext(); // returns first page with 10 results | ||
@@ -125,3 +127,3 @@ companies = await companiesScroller.scrollNext(); // next page | ||
// overriding skip and limit | ||
companiesScroller = await client.search.searchCompanies({ skip: 100, limit: 1 }); | ||
companiesScroller = client.search.searchCompanies({ skip: 100, limit: 1 }); | ||
companies = await companiesScroller.scrollNext(); // returns first page with 1 results | ||
@@ -133,3 +135,3 @@ companies = await companiesScroller.scrollNext(); // next page | ||
const twoDaysAgo = moment().subtract(2, 'days').toDate(); | ||
let messagesScroller = await client.message.getMessages({ | ||
let messagesScroller = client.message.getMessages({ | ||
conversationId: CONVERSATION_ID, | ||
@@ -147,6 +149,6 @@ createdBefore: twoDaysAgo | ||
* Media support - fetch, like, comment and create a new post. | ||
* Messaging improvements - be able to send messages directly to a profile and start a new conversation. | ||
* Invitation improvements - be able to do some more actions like "remove connection". | ||
* Search improvements - support jobs searching. | ||
* Improve login API | ||
* Add services so automate common workflows | ||
@@ -153,0 +155,0 @@ Want a specific feature? Please open a feature request :) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
307652
2987
153