Skip to content

Commit a74be79

Browse files
Delete Messaging wrapper
1 parent 63edc79 commit a74be79

File tree

4 files changed

+231
-285
lines changed

4 files changed

+231
-285
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ Send messages to LinkedIn users through standard LinkedIn messaging.
559559
- **Returns:** `Promise<WorkflowHandler<void>>` - Workflow handler (no result data)
560560

561561
```typescript
562-
await linkedapi.account.messaging.sendMessage({
562+
await linkedapi.account.sendMessage({
563563
personUrl: "https://www.linkedin.com/in/john-doe",
564564
text: "Hello! I saw your post about AI and wanted to connect.",
565565
});
@@ -576,7 +576,7 @@ Sync conversation history with a LinkedIn user for message polling.
576576
- **Related Methods:** Use with `pollConversations()` to retrieve message history
577577

578578
```typescript
579-
await linkedapi.account.messaging.syncConversation({
579+
await linkedapi.account.syncConversation({
580580
personUrl: "https://www.linkedin.com/in/john-doe",
581581
});
582582
```
@@ -591,7 +591,7 @@ Send messages through Sales Navigator with enhanced messaging capabilities.
591591
- **Returns:** `Promise<WorkflowHandler<void>>` - Workflow handler (no result data)
592592

593593
```typescript
594-
await linkedapi.account.messaging.salesNavigatorSendMessage({
594+
await linkedapi.account.salesNavigatorSendMessage({
595595
personUrl: "https://www.linkedin.com/sales/people/ABC123",
596596
subject: "Partnership Opportunity",
597597
text: "Hi! I'd love to discuss potential collaboration opportunities.",
@@ -608,7 +608,7 @@ Sync Sales Navigator conversation for message polling.
608608
- **Returns:** `Promise<WorkflowHandler<void>>` - Workflow handler (no result data)
609609

610610
```typescript
611-
await linkedapi.account.messaging.salesNavigatorSyncConversation({
611+
await linkedapi.account.salesNavigatorSyncConversation({
612612
personUrl: "https://www.linkedin.com/sales/people/ABC123",
613613
});
614614
```
@@ -624,7 +624,7 @@ Poll multiple conversations to retrieve message history and new messages.
624624
- **Prerequisites:** Must call `syncConversation()` or `salesNavigatorSyncConversation()` for each person before polling
625625

626626
```typescript
627-
const response = await linkedapi.account.messaging.pollConversations([
627+
const response = await linkedapi.account.pollConversations([
628628
{ personUrl: "https://www.linkedin.com/in/john-doe", type: "st" },
629629
{
630630
personUrl: "https://www.linkedin.com/sales/people/ABC123",

examples/messaging.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async function sendMessage(linkedapi: LinkedApi, personUrl: string): Promise<voi
4242
text: 'Hi! I hope you\'re doing well. I came across your profile and was impressed by your work. I\'d love to connect and discuss potential collaboration opportunities.',
4343
};
4444

45-
const messageWorkflow = await linkedapi.account.messaging.sendMessage(messageParams);
45+
const messageWorkflow = await linkedapi.account.sendMessage(messageParams);
4646
console.log('💬 Send message workflow started:', messageWorkflow.workflowId);
4747

4848
await messageWorkflow.result();
@@ -58,7 +58,7 @@ async function syncConversation(linkedapi: LinkedApi, personUrl: string): Promis
5858
personUrl: personUrl,
5959
};
6060

61-
const syncWorkflow = await linkedapi.account.messaging.syncConversation(syncParams);
61+
const syncWorkflow = await linkedapi.account.syncConversation(syncParams);
6262
console.log('🔄 Sync conversation workflow started:', syncWorkflow.workflowId);
6363

6464
await syncWorkflow.result();
@@ -76,7 +76,7 @@ async function salesNavigatorSendMessage(linkedapi: LinkedApi, personUrl: string
7676
subject: 'Let\'s connect!',
7777
};
7878

79-
const nvMessageWorkflow = await linkedapi.account.messaging.salesNavigatorSendMessage(nvMessageParams);
79+
const nvMessageWorkflow = await linkedapi.account.salesNavigatorSendMessage(nvMessageParams);
8080
console.log('🎯 Sales Navigator send message workflow started:', nvMessageWorkflow.workflowId);
8181

8282
await nvMessageWorkflow.result();
@@ -92,7 +92,7 @@ async function salesNavigatorSyncConversation(linkedapi: LinkedApi, personUrl: s
9292
personUrl: personUrl,
9393
};
9494

95-
const nvSyncWorkflow = await linkedapi.account.messaging.salesNavigatorSyncConversation(nvSyncParams);
95+
const nvSyncWorkflow = await linkedapi.account.salesNavigatorSyncConversation(nvSyncParams);
9696
console.log('🎯 Sales Navigator sync conversation workflow started:', nvSyncWorkflow.workflowId);
9797

9898
await nvSyncWorkflow.result();
@@ -104,7 +104,7 @@ async function salesNavigatorSyncConversation(linkedapi: LinkedApi, personUrl: s
104104
async function pollConversations(linkedapi: LinkedApi, standardPersonUrl: string, nvPersonUrl: string): Promise<void> {
105105
console.log('\n📥 Polling conversations...');
106106

107-
const pollResponse = await linkedapi.account.messaging.pollConversations([
107+
const pollResponse = await linkedapi.account.pollConversations([
108108
{
109109
personUrl: standardPersonUrl,
110110
type: 'st',

src/account-api/account-api.ts

Lines changed: 221 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,16 @@ import { SimpleWorkflowMapper } from "../core/simple-workflow-mapper";
6969
import { WorkflowHandler } from "../core/workflow-handler";
7070
import type { WorkflowExecutor } from "../core/workflow-executor";
7171
import type { TBaseActionParams } from "../types/params";
72-
import { Messaging } from "./messaging";
7372
import { HttpClient } from "../core/http-client";
73+
import {
74+
TConversationPollRequest,
75+
TConversationPollResponse,
76+
TConversationPollResult,
77+
TNvSendMessageParams,
78+
TNvSyncConversationParams,
79+
TSendMessageParams,
80+
TSyncConversationParams,
81+
} from "../types";
7482

7583
/**
7684
* Linked API Account API client for LinkedIn automation and data retrieval.
@@ -93,13 +101,6 @@ import { HttpClient } from "../core/http-client";
93101
* ```
94102
*/
95103
export class AccountApi {
96-
/**
97-
* Messaging functionality for sending messages, syncing conversations, and polling messages.
98-
*
99-
* @see {@link https://linkedapi.io/docs/account-api/working-with-conversations/ Messaging Documentation}
100-
*/
101-
public readonly messaging: Messaging;
102-
103104
/**
104105
* Creates a new AccountApi instance.
105106
*
@@ -109,9 +110,7 @@ export class AccountApi {
109110
constructor(
110111
private workflowExecutor: WorkflowExecutor,
111112
private readonly httpClient: HttpClient,
112-
) {
113-
this.messaging = new Messaging(this.workflowExecutor, this.httpClient);
114-
}
113+
) {}
115114

116115
/**
117116
* Execute a custom workflow with raw workflow definition.
@@ -188,6 +187,217 @@ export class AccountApi {
188187
return this.workflowExecutor.getWorkflowResult(workflowId);
189188
}
190189

190+
/**
191+
* Send a message to a LinkedIn user via standard LinkedIn messaging.
192+
*
193+
* This method sends a direct message to a person on LinkedIn. The recipient must be a connection
194+
* or allow messages from anyone. This uses the standard LinkedIn messaging interface.
195+
*
196+
* @param params - Parameters including the person's URL and message text
197+
* @returns Promise resolving to a WorkflowHandler for the message sending action
198+
*
199+
* @see {@link https://linkedapi.io/docs/account-api/sending-message/ Sending Messages Documentation}
200+
* @see {@link https://linkedapi.io/docs/account-api/action-st-send-message/ st.sendMessage Action Documentation}
201+
*
202+
* @example
203+
* ```typescript
204+
* const messageWorkflow = await linkedapi.account.sendMessage({
205+
* personUrl: "https://www.linkedin.com/in/john-doe",
206+
* text: "Hi John! I saw your recent post about AI and would love to discuss further."
207+
* });
208+
*
209+
* await messageWorkflow.result();
210+
* console.log("Message sent successfully");
211+
* ```
212+
*/
213+
public async sendMessage(
214+
params: TSendMessageParams,
215+
): Promise<WorkflowHandler<void>> {
216+
const sendMessageMapper = new VoidWorkflowMapper<TSendMessageParams>(
217+
"st.sendMessage",
218+
);
219+
const workflowDefinition = sendMessageMapper.mapRequest(params);
220+
const { workflowId } =
221+
await this.workflowExecutor.startWorkflow(workflowDefinition);
222+
return new WorkflowHandler<void>(
223+
workflowId,
224+
this.workflowExecutor,
225+
sendMessageMapper,
226+
);
227+
}
228+
229+
/**
230+
* Sync a conversation with a LinkedIn user for standard LinkedIn messaging.
231+
*
232+
* This method synchronizes a conversation with a person, preparing it for future message polling.
233+
* Each conversation must be synced once before you can poll it for messages. This is a time-consuming
234+
* process that retrieves the conversation history and prepares it for future updates.
235+
*
236+
* @param params - Parameters including the person's URL
237+
* @returns Promise resolving to a WorkflowHandler for the sync action
238+
*
239+
* @see {@link https://linkedapi.io/docs/account-api/working-with-conversations/ Working with Conversations Documentation}
240+
* @see {@link https://linkedapi.io/docs/account-api/action-st-sync-conversation/ st.syncConversation Action Documentation}
241+
*
242+
* @example
243+
* ```typescript
244+
* const syncWorkflow = await linkedapi.account.syncConversation({
245+
* personUrl: "https://www.linkedin.com/in/john-doe"
246+
* });
247+
*
248+
* await syncWorkflow.result();
249+
* console.log("Conversation synced and ready for polling");
250+
* ```
251+
*/
252+
public async syncConversation(
253+
params: TSyncConversationParams,
254+
): Promise<WorkflowHandler<void>> {
255+
const syncConversationMapper =
256+
new VoidWorkflowMapper<TSyncConversationParams>("st.syncConversation");
257+
const workflowDefinition = syncConversationMapper.mapRequest(params);
258+
const { workflowId } =
259+
await this.workflowExecutor.startWorkflow(workflowDefinition);
260+
return new WorkflowHandler<void>(
261+
workflowId,
262+
this.workflowExecutor,
263+
syncConversationMapper,
264+
);
265+
}
266+
267+
/**
268+
* Send a message to a LinkedIn user via Sales Navigator.
269+
*
270+
* This method sends a direct message to a person using Sales Navigator's messaging capabilities.
271+
* Sales Navigator allows messaging people who are not connections and provides enhanced messaging features.
272+
*
273+
* @param params - Parameters including the person's URL, message text, and subject line
274+
* @returns Promise resolving to a WorkflowHandler for the message sending action
275+
*
276+
* @see {@link https://linkedapi.io/docs/account-api/sending-message/ Sending Messages Documentation}
277+
* @see {@link https://linkedapi.io/docs/account-api/action-nv-send-message/ nv.sendMessage Action Documentation}
278+
*
279+
* @example
280+
* ```typescript
281+
* const nvMessageWorkflow = await linkedapi.account.salesNavigatorSendMessage({
282+
* personUrl: "https://www.linkedin.com/in/john-doe",
283+
* text: "Hi John! I'm reaching out regarding potential collaboration opportunities.",
284+
* subject: "Partnership Opportunity"
285+
* });
286+
*
287+
* await nvMessageWorkflow.result();
288+
* console.log("Sales Navigator message sent successfully");
289+
* ```
290+
*/
291+
public async salesNavigatorSendMessage(
292+
params: TNvSendMessageParams,
293+
): Promise<WorkflowHandler<void>> {
294+
const nvSendMessageMapper = new VoidWorkflowMapper<TNvSendMessageParams>(
295+
"nv.sendMessage",
296+
);
297+
const workflowDefinition = nvSendMessageMapper.mapRequest(params);
298+
const { workflowId } =
299+
await this.workflowExecutor.startWorkflow(workflowDefinition);
300+
return new WorkflowHandler<void>(
301+
workflowId,
302+
this.workflowExecutor,
303+
nvSendMessageMapper,
304+
);
305+
}
306+
307+
/**
308+
* Sync a conversation with a LinkedIn user for Sales Navigator messaging.
309+
*
310+
* This method synchronizes a Sales Navigator conversation with a person, preparing it for future message polling.
311+
* Each conversation must be synced once before you can poll it for messages. This retrieves the conversation
312+
* history from Sales Navigator and prepares it for future updates.
313+
*
314+
* @param params - Parameters including the person's URL
315+
* @returns Promise resolving to a WorkflowHandler for the sync action
316+
*
317+
* @see {@link https://linkedapi.io/docs/account-api/working-with-conversations/ Working with Conversations Documentation}
318+
* @see {@link https://linkedapi.io/docs/account-api/action-nv-sync-conversation/ nv.syncConversation Action Documentation}
319+
*
320+
* @example
321+
* ```typescript
322+
* const nvSyncWorkflow = await linkedapi.account.salesNavigatorSyncConversation({
323+
* personUrl: "https://www.linkedin.com/in/john-doe"
324+
* });
325+
*
326+
* await nvSyncWorkflow.result();
327+
* console.log("Sales Navigator conversation synced and ready for polling");
328+
* ```
329+
*/
330+
public async salesNavigatorSyncConversation(
331+
params: TNvSyncConversationParams,
332+
): Promise<WorkflowHandler<void>> {
333+
const nvSyncConversationMapper =
334+
new VoidWorkflowMapper<TNvSyncConversationParams>("nv.syncConversation");
335+
const workflowDefinition = nvSyncConversationMapper.mapRequest(params);
336+
const { workflowId } =
337+
await this.workflowExecutor.startWorkflow(workflowDefinition);
338+
return new WorkflowHandler<void>(
339+
workflowId,
340+
this.workflowExecutor,
341+
nvSyncConversationMapper,
342+
);
343+
}
344+
345+
/**
346+
* Poll multiple conversations to retrieve message history and new messages.
347+
*
348+
* This method retrieves messages from one or more previously synced conversations using direct HTTP requests.
349+
* Unlike syncing, polling is fast and can be done continuously to get real-time message updates.
350+
* You can specify a timestamp to get only messages since that time.
351+
*
352+
* @param conversations - Array of conversation requests specifying person URLs, types, and optional timestamps
353+
* @returns Promise resolving to a response containing conversation data and messages
354+
*
355+
* @see {@link https://linkedapi.io/docs/account-api/working-with-conversations/ Working with Conversations Documentation}
356+
*
357+
* @example
358+
* ```typescript
359+
* // Poll multiple conversations
360+
* const pollResponse = await linkedapi.account.pollConversations([
361+
* {
362+
* personUrl: "https://www.linkedin.com/in/john-doe",
363+
* type: "st",
364+
* since: "2023-01-01T00:00:00Z"
365+
* },
366+
* {
367+
* personUrl: "https://www.linkedin.com/in/jane-smith",
368+
* type: "nv"
369+
* }
370+
* ]);
371+
*
372+
* if (pollResponse.success) {
373+
* pollResponse.result?.forEach(conversation => {
374+
* console.log(`Conversation with ${conversation.personUrl}:`);
375+
* console.log(`Messages: ${conversation.messages.length}`);
376+
*
377+
* conversation.messages.forEach(message => {
378+
* console.log(`${message.sender}: ${message.text}`);
379+
* });
380+
* });
381+
* } else {
382+
* console.error("Polling failed:", pollResponse.error?.message);
383+
* }
384+
* ```
385+
*/
386+
public async pollConversations(
387+
conversations: TConversationPollRequest[],
388+
): Promise<TConversationPollResponse> {
389+
const response = await this.httpClient.post<TConversationPollResult[]>(
390+
"/account/conversations/poll",
391+
conversations,
392+
);
393+
394+
return {
395+
success: response.success,
396+
result: response.result,
397+
error: response.error,
398+
};
399+
}
400+
191401
/**
192402
* Retrieve detailed information about a LinkedIn person profile.
193403
*

0 commit comments

Comments
 (0)