@@ -69,8 +69,16 @@ import { SimpleWorkflowMapper } from "../core/simple-workflow-mapper";
6969import { WorkflowHandler } from "../core/workflow-handler" ;
7070import type { WorkflowExecutor } from "../core/workflow-executor" ;
7171import type { TBaseActionParams } from "../types/params" ;
72- import { Messaging } from "./messaging" ;
7372import { 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 */
95103export 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