1- import LinkedApi , { LinkedApiError } from '@linkedapi/node' ;
1+ import LinkedApi , {
2+ INVITATION_TYPE ,
3+ LinkedApiError ,
4+ TRetrieveInvitationsResult ,
5+ } from '@linkedapi/node' ;
26
37async function connectionsExample ( ) : Promise < void > {
4-
58 const linkedapi = new LinkedApi ( {
69 linkedApiToken : process . env . LINKED_API_TOKEN ! ,
710 identificationToken : process . env . IDENTIFICATION_TOKEN ! ,
@@ -17,12 +20,11 @@ async function connectionsExample(): Promise<void> {
1720 await sendConnectionRequest ( linkedapi , targetPersonUrl ) ;
1821 await retrievePendingRequests ( linkedapi ) ;
1922 await withdrawConnectionRequest ( linkedapi , targetPersonUrl ) ;
20- await retrieveConnectionRequests ( linkedapi ) ;
21- await acceptConnectionRequest ( linkedapi , targetPersonUrl2 ) ;
22- await ignoreConnectionRequest ( linkedapi , targetPersonUrl2 ) ;
23+ await retrieveInvitations ( linkedapi ) ;
24+ await acceptInvitation ( linkedapi , targetPersonUrl2 ) ;
25+ await ignoreInvitation ( linkedapi , targetPersonUrl2 ) ;
2326 await retrieveConnections ( linkedapi ) ;
2427 await removeConnection ( linkedapi , targetPersonUrl2 ) ;
25-
2628 } catch ( error ) {
2729 if ( error instanceof LinkedApiError ) {
2830 console . error ( '🚨 Linked API Error:' , error . message ) ;
@@ -59,7 +61,7 @@ async function sendConnectionRequest(linkedapi: LinkedApi, personUrl: string): P
5961
6062 const requestParams = {
6163 personUrl : personUrl ,
62- note : ' Hi! I\ 'd love to connect and discuss potential collaboration opportunities. Looking forward to connecting with you!' ,
64+ note : " Hi! I'd love to connect and discuss potential collaboration opportunities. Looking forward to connecting with you!" ,
6365 email : 'example@gmail.com' ,
6466 } ;
6567
@@ -199,53 +201,77 @@ async function removeConnection(linkedapi: LinkedApi, personUrl: string): Promis
199201 }
200202}
201203
202- async function retrieveConnectionRequests ( linkedapi : LinkedApi ) : Promise < void > {
203- console . log ( '\n📥 Retrieving incoming connection requests ...' ) ;
204+ async function retrieveInvitations ( linkedapi : LinkedApi ) : Promise < void > {
205+ console . log ( '\n📥 Retrieving incoming invitations ...' ) ;
204206
205- const workflow = await linkedapi . retrieveConnectionRequests . execute ( ) ;
206- console . log ( '📥 Retrieve connection requests workflow started:' , workflow . workflowId ) ;
207+ const workflow = await linkedapi . retrieveInvitations . execute ( ) ;
208+ console . log ( '📥 Retrieve invitations workflow started:' , workflow . workflowId ) ;
207209
208- const requestsResult = await linkedapi . retrieveConnectionRequests . result ( workflow . workflowId ) ;
209- if ( requestsResult . data ) {
210- const requests = requestsResult . data ;
211- console . log ( '✅ Incoming requests retrieval completed' ) ;
212- console . log ( `📊 Found ${ requests . length } incoming requests` ) ;
213- requests . forEach ( ( request , index ) => {
214- console . log ( ` ${ index + 1 } . ${ request . name } ` ) ;
215- console . log ( ` Profile: ${ request . publicUrl } ` ) ;
216- console . log ( ` Headline: ${ request . headline } ` ) ;
217- } ) ;
210+ const invitationsResult = await linkedapi . retrieveInvitations . result ( workflow . workflowId ) ;
211+ if ( invitationsResult . data ) {
212+ const invitations = invitationsResult . data ;
213+ console . log ( '✅ Incoming invitations retrieval completed' ) ;
214+ console . log ( `📊 Found ${ invitations . length } incoming invitations` ) ;
215+ for ( const [ index , invitation ] of invitations . entries ( ) ) {
216+ console . log ( ` ${ index + 1 } . ${ invitation . name } ` ) ;
217+ logInvitationTarget ( invitation ) ;
218+ }
218219 }
219- if ( requestsResult . errors . length > 0 ) {
220- console . error ( '🚨 Errors:' , JSON . stringify ( requestsResult . errors , null , 2 ) ) ;
220+ if ( invitationsResult . errors . length > 0 ) {
221+ console . error ( '🚨 Errors:' , JSON . stringify ( invitationsResult . errors , null , 2 ) ) ;
221222 }
222223}
223224
224- async function acceptConnectionRequest ( linkedapi : LinkedApi , personUrl : string ) : Promise < void > {
225- console . log ( '\n🤝 Accepting incoming connection request ...' ) ;
225+ async function acceptInvitation ( linkedapi : LinkedApi , personUrl : string ) : Promise < void > {
226+ console . log ( '\n🤝 Accepting incoming invitation ...' ) ;
226227
227- const workflow = await linkedapi . acceptConnectionRequest . execute ( { personUrl } ) ;
228- console . log ( '🤝 Accept connection request workflow started:' , workflow . workflowId ) ;
228+ const workflow = await linkedapi . acceptInvitation . execute ( {
229+ invitationType : INVITATION_TYPE . connect ,
230+ personUrl,
231+ } ) ;
232+ console . log ( '🤝 Accept invitation workflow started:' , workflow . workflowId ) ;
229233
230- const acceptResult = await linkedapi . acceptConnectionRequest . result ( workflow . workflowId ) ;
234+ const acceptResult = await linkedapi . acceptInvitation . result ( workflow . workflowId ) ;
231235 if ( acceptResult . errors . length > 0 ) {
232236 console . error ( '🚨 Errors:' , JSON . stringify ( acceptResult . errors , null , 2 ) ) ;
233237 } else {
234- console . log ( '✅ Connection request accepted successfully' ) ;
238+ console . log ( '✅ Invitation accepted successfully' ) ;
235239 }
236240}
237241
238- async function ignoreConnectionRequest ( linkedapi : LinkedApi , personUrl : string ) : Promise < void > {
239- console . log ( '\n🙈 Ignoring incoming connection request ...' ) ;
242+ async function ignoreInvitation ( linkedapi : LinkedApi , personUrl : string ) : Promise < void > {
243+ console . log ( '\n🙈 Ignoring incoming invitation ...' ) ;
240244
241- const workflow = await linkedapi . ignoreConnectionRequest . execute ( { personUrl } ) ;
242- console . log ( '🙈 Ignore connection request workflow started:' , workflow . workflowId ) ;
245+ const workflow = await linkedapi . ignoreInvitation . execute ( {
246+ invitationType : INVITATION_TYPE . connect ,
247+ personUrl,
248+ } ) ;
249+ console . log ( '🙈 Ignore invitation workflow started:' , workflow . workflowId ) ;
243250
244- const ignoreResult = await linkedapi . ignoreConnectionRequest . result ( workflow . workflowId ) ;
251+ const ignoreResult = await linkedapi . ignoreInvitation . result ( workflow . workflowId ) ;
245252 if ( ignoreResult . errors . length > 0 ) {
246253 console . error ( '🚨 Errors:' , JSON . stringify ( ignoreResult . errors , null , 2 ) ) ;
247254 } else {
248- console . log ( '✅ Connection request ignored successfully' ) ;
255+ console . log ( '✅ Invitation ignored successfully' ) ;
256+ }
257+ }
258+
259+ function logInvitationTarget ( invitation : TRetrieveInvitationsResult ) : void {
260+ console . log ( ` Type: ${ invitation . invitationType } ` ) ;
261+ switch ( invitation . invitationType ) {
262+ case INVITATION_TYPE . connect :
263+ console . log ( ` Profile: ${ invitation . publicUrl } ` ) ;
264+ console . log ( ` Headline: ${ invitation . headline } ` ) ;
265+ console . log ( ` Note: ${ invitation . note } ` ) ;
266+ break ;
267+ case INVITATION_TYPE . companyFollow :
268+ console . log ( ` Company: ${ invitation . companyName } ` ) ;
269+ console . log ( ` Company URL: ${ invitation . companyUrl } ` ) ;
270+ break ;
271+ case INVITATION_TYPE . newsletterSubscribe :
272+ console . log ( ` Newsletter: ${ invitation . newsletterName } ` ) ;
273+ console . log ( ` Newsletter URL: ${ invitation . newsletterUrl } ` ) ;
274+ break ;
249275 }
250276}
251277
0 commit comments