Skip to content

Commit 16e4179

Browse files
committed
feat: linkedin repost
1 parent c23061d commit 16e4179

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

libraries/nestjs-libraries/src/integrations/social/linkedin.page.provider.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ export class LinkedinPageProvider
8383
};
8484
}
8585

86+
override async repostPostUsers(
87+
integration: Integration,
88+
originalIntegration: Integration,
89+
postId: string,
90+
information: any
91+
) {
92+
return super.repostPostUsers(integration, originalIntegration, postId, information, false);
93+
}
94+
8695
override async generateAuthUrl() {
8796
const state = makeId(6);
8897
const codeVerifier = makeId(30);

libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ import { makeId } from '@gitroom/nestjs-libraries/services/make.is';
88
import sharp from 'sharp';
99
import { lookup } from 'mime-types';
1010
import { readOrFetch } from '@gitroom/helpers/utils/read.or.fetch';
11-
import { removeMarkdown } from '@gitroom/helpers/utils/remove.markdown';
12-
import {
13-
BadBody,
14-
SocialAbstract,
15-
} from '@gitroom/nestjs-libraries/integrations/social.abstract';
11+
import { SocialAbstract } from '@gitroom/nestjs-libraries/integrations/social.abstract';
1612
import { Integration } from '@prisma/client';
13+
import { PostPlug } from '@gitroom/helpers/decorators/post.plug';
14+
1715
export class LinkedinProvider extends SocialAbstract implements SocialProvider {
1816
identifier = 'linkedin';
1917
name = 'LinkedIn';
@@ -458,4 +456,50 @@ export class LinkedinProvider extends SocialAbstract implements SocialProvider {
458456

459457
return ids;
460458
}
459+
460+
@PostPlug({
461+
identifier: 'linkedin-repost-post-users',
462+
title: 'Add Re-posters',
463+
description: 'Add accounts to repost your post',
464+
pickIntegration: ['linkedin', 'linkedin-page'],
465+
fields: [],
466+
})
467+
async repostPostUsers(
468+
integration: Integration,
469+
originalIntegration: Integration,
470+
postId: string,
471+
information: any,
472+
isPersonal = true
473+
) {
474+
try {
475+
await this.fetch(`https://api.linkedin.com/rest/posts`, {
476+
body: JSON.stringify({
477+
author:
478+
(isPersonal ? 'urn:li:person:' : `urn:li:organization:`) +
479+
`${integration.internalId}`,
480+
commentary: '',
481+
visibility: 'PUBLIC',
482+
distribution: {
483+
feedDistribution: 'MAIN_FEED',
484+
targetEntities: [],
485+
thirdPartyDistributionChannels: [],
486+
},
487+
lifecycleState: 'PUBLISHED',
488+
isReshareDisabledByAuthor: false,
489+
reshareContext: {
490+
parent: postId,
491+
},
492+
}),
493+
method: 'POST',
494+
headers: {
495+
'X-Restli-Protocol-Version': '2.0.0',
496+
'Content-Type': 'application/json',
497+
'LinkedIn-Version': '202402',
498+
Authorization: `Bearer ${integration.token}`,
499+
},
500+
});
501+
} catch (err) {
502+
return;
503+
}
504+
}
461505
}

libraries/nestjs-libraries/src/integrations/social/x.provider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export class XProvider extends SocialAbstract implements SocialProvider {
9191
try {
9292
await client.v2.retweet(id, postId);
9393
} catch (err) {
94+
/** nothing **/
9495
}
9596
}
9697

0 commit comments

Comments
 (0)