Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

feat: strip links

Nevo Davide986d9e49340
diff --git a/apps/backend/src/api/routes/integrations.controller.ts b/apps/backend/src/api/routes/integrations.controller.ts
index 5bd2f52ef..024a89043 100644
--- a/apps/backend/src/api/routes/integrations.controller.ts
+++ b/apps/backend/src/api/routes/integrations.controller.ts
@@ -101,6 +101,7 @@ export class IntegrationsController {
internalId: p.internalId,
disabled: p.disabled,
editor: findIntegration.editor,
+ stripLinks: !!findIntegration?.stripLinks?.(),
picture: p.picture || '/no-picture.jpg',
identifier: p.providerIdentifier,
inBetweenSteps: p.inBetweenSteps,
diff --git a/apps/frontend/src/components/launches/calendar.context.tsx b/apps/frontend/src/components/launches/calendar.context.tsx
index 5515b2c45..8c81c99e5 100644
--- a/apps/frontend/src/components/launches/calendar.context.tsx
+++ b/apps/frontend/src/components/launches/calendar.context.tsx
@@ -86,6 +86,7 @@ export interface Integrations {
disabled?: boolean;
inBetweenSteps: boolean;
editor: 'none' | 'normal' | 'markdown' | 'html';
+ stripLinks?: boolean;
display: string;
identifier: string;
type: string;
diff --git a/apps/frontend/src/components/launches/information.component.tsx b/apps/frontend/src/components/launches/information.component.tsx
index 5a5190e4c..c734429f4 100644
--- a/apps/frontend/src/components/launches/information.component.tsx
+++ b/apps/frontend/src/components/launches/information.component.tsx
@@ -7,6 +7,7 @@ import clsx from 'clsx';
import SafeImage from '@gitroom/react/helpers/safe.image';
import { capitalize } from 'lodash';
import { useT } from '@gitroom/react/translation/get.transation.service.client';
+import { hasLinks } from '@gitroom/helpers/utils/strip.links';
const Valid: FC = () => {
return (
@@ -59,15 +60,36 @@ export const InformationComponent: FC<{
totalChars: number;
totalAllowedChars: number;
isPicture: boolean;
-}> = ({ totalChars, totalAllowedChars, chars, isPicture }) => {
+ text?: string;
+}> = ({ totalChars, totalAllowedChars, chars, isPicture, text }) => {
const t = useT();
- const { isGlobal, selectedIntegrations, internal } = useLaunchStore(
- useShallow((state) => ({
- isGlobal: state.current === 'global',
- selectedIntegrations: state.selectedIntegrations,
- internal: state.internal,
- }))
- );
+ const { isGlobal, selectedIntegrations, internal, currentIntegration } =
+ useLaunchStore(
+ useShallow((state) => ({
+ isGlobal: state.current === 'global',
+ selectedIntegrations: state.selectedIntegrations,
+ internal: state.internal,
+ currentIntegration: state.integrations.find(
+ (p) => p.id === state.current
+ ),
+ }))
+ );
+
+ const stripLinkNames = useMemo(() => {
+ if (!hasLinks(text)) {
+ return [] as string[];
+ }
+
+ if (!isGlobal) {
+ return currentIntegration?.stripLinks ? [currentIntegration.name] : [];
+ }
+
+ return selectedIntegrations
+ .filter((p) => p.integration.stripLinks)
+ .map((p) => p.integration.name);
+ }, [text, isGlobal, currentIntegration, selectedIntegrations]);
+
+ const showStripLinkWarning = stripLinkNames.length > 0;
const isInternal = useMemo(() => {
if (!isGlobal) {
@@ -83,6 +105,10 @@ export const InformationComponent: FC<{
}, [isGlobal, internal, selectedIntegrations]);
const isValid = useMemo(() => {
+ if (showStripLinkWarning) {
+ return false;
+ }
+
if (!isPicture && !totalChars) {
return false;
}
@@ -108,7 +134,14 @@ export const InformationComponent: FC<{
}
return true;
- }, [totalAllowedChars, totalChars, isInternal, isPicture, chars]);
+ }, [
+ totalAllowedChars,
+ totalChars,
+ isInternal,
+ isPicture,
+ chars,
+ showStripLinkWarning,
+ ]);
const globalDisplayLimit = useMemo(() => {
if (!isGlobal || !selectedIntegrations.length) {
@@ -230,6 +263,19 @@ export const InformationComponent: FC<{
))}
</div>
)}
+ {showStripLinkWarning && (
+ <div
+ className={clsx(
+ 'text-sm text-[#FF3F3F] whitespace-nowrap',
+ ((isGlobal && selectedIntegrations.length) ||
+ (!isPicture && !totalChars)) &&
+ 'mt-[12px]'
+ )}
+ >
+ {t('links_will_be_removed_from', 'Links will be removed from')}:{' '}
+ {stripLinkNames.join(', ')}
+ </div>
+ )}
</div>
)}
</div>
diff --git a/apps/frontend/src/components/new-launch/editor.tsx b/apps/frontend/src/components/new-launch/editor.tsx
index 69027bee5..5c357b7c5 100644
--- a/apps/frontend/src/components/new-launch/editor.tsx
+++ b/apps/frontend/src/components/new-launch/editor.tsx
@@ -772,6 +772,7 @@ export const Editor: FC<{
chars={chars}
totalChars={valueWithoutHtml.length}
totalAllowedChars={props.totalChars}
+ text={valueWithoutHtml}
/>
}
toolBar={
diff --git a/apps/frontend/src/components/new-launch/manage.modal.tsx b/apps/frontend/src/components/new-launch/manage.modal.tsx
index 0af6af152..f8edb218a 100644
--- a/apps/frontend/src/components/new-launch/manage.modal.tsx
+++ b/apps/frontend/src/components/new-launch/manage.modal.tsx
@@ -341,9 +341,12 @@ export const ManageModal: FC<AddEditModalProps> = (props) => {
await fetch('/posts/should-shortlink', {
method: 'POST',
body: JSON.stringify({
- messages: checkAllValid.flatMap((p: any) =>
- p.values.flatMap((a: any) => a.content)
- ),
+ messages: checkAllValid
+ // platforms that remove links won't keep shortlinks either
+ .filter((p: any) => !p?.integration?.stripLinks)
+ .flatMap((p: any) =>
+ p.values.flatMap((a: any) => a.content)
+ ),
}),
})
).json();
diff --git a/libraries/helpers/src/utils/strip.links.ts b/libraries/helpers/src/utils/strip.links.ts
new file mode 100644
index 000000000..337a52a13
--- /dev/null
+++ b/libraries/helpers/src/utils/strip.links.ts
@@ -0,0 +1,17 @@
+// Keep this in sync with the URL detection used by the short linking service
+const urlRegex = () =>
+ /(https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&//=]*))/gm;
+
+export function hasLinks(text?: string | null): boolean {
+ return !!(text || '').match(urlRegex());
+}
+
+export function stripLinks(text?: string | null): string {
+ return (text || '')
+ .replace(urlRegex(), '')
+ // collapse the whitespace / empty anchor leftovers the removed link left behind
+ .replace(/<a\b[^>]*>\s*<\/a>/gi, '')
+ .replace(/[ \t]{2,}/g, ' ')
+ .replace(/ +\n/g, '\n')
+ .trim();
+}
diff --git a/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts b/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts
index 2ca5c875e..41caa6017 100644
--- a/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts
+++ b/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts
@@ -37,6 +37,7 @@ import { timer } from '@gitroom/helpers/utils/timer';
import { ioRedis } from '@gitroom/nestjs-libraries/redis/redis.service';
import { RefreshToken } from '@gitroom/nestjs-libraries/integrations/social.abstract';
import { RefreshIntegrationService } from '@gitroom/nestjs-libraries/integrations/refresh.integration.service';
+import { stripLinks } from '@gitroom/helpers/utils/strip.links';
type PostWithConditionals = Post & {
integration?: Integration;
@@ -734,14 +735,24 @@ export class PostsService {
async createPost(orgId: string, body: CreatePostDto): Promise<any[]> {
const postList = [];
for (const post of body.posts) {
+ const provider = this._integrationManager.getSocialIntegration(
+ (post.settings as any)?.__type
+ );
+ const removeLinks = !!provider?.stripLinks?.();
+
const messages = (post.value || []).map((p) => p.content);
- const updateContent = !body.shortLink
- ? messages
- : await this._shortLinkService.convertTextToShortLinks(orgId, messages);
+ // No point shortlinking links on platforms that strip them out anyway
+ const updateContent =
+ !body.shortLink || removeLinks
+ ? messages
+ : await this._shortLinkService.convertTextToShortLinks(
+ orgId,
+ messages
+ );
post.value = (post.value || []).map((p, i) => ({
...p,
- content: updateContent[i],
+ content: removeLinks ? stripLinks(updateContent[i]) : updateContent[i],
}));
const { posts } = await this._postRepository.createOrUpdatePost(
diff --git a/libraries/nestjs-libraries/src/integrations/social/social.integrations.interface.ts b/libraries/nestjs-libraries/src/integrations/social/social.integrations.interface.ts
index 29d8356b6..a48598a8d 100644
--- a/libraries/nestjs-libraries/src/integrations/social/social.integrations.interface.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/social.integrations.interface.ts
@@ -141,6 +141,7 @@ export interface SocialProvider
identifier: string;
refreshWait?: boolean;
convertToJPEG?: boolean;
+ stripLinks?: () => boolean;
refreshCron?: boolean;
dto?: any;
maxLength: (additionalSettings?: any) => number;
diff --git a/libraries/nestjs-libraries/src/integrations/social/x.provider.ts b/libraries/nestjs-libraries/src/integrations/social/x.provider.ts
index 682845080..c6ba39d2f 100644
--- a/libraries/nestjs-libraries/src/integrations/social/x.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/x.provider.ts
@@ -18,6 +18,7 @@ import { PostPlug } from '@gitroom/helpers/decorators/post.plug';
import dayjs from 'dayjs';
import { uniqBy } from 'lodash';
import { stripHtmlValidation } from '@gitroom/helpers/utils/strip.html.validation';
+import { stripLinks as removeLinks } from '@gitroom/helpers/utils/strip.links';
import { XDto } from '@gitroom/nestjs-libraries/dtos/posts/providers-settings/x.dto';
import { Rules } from '@gitroom/nestjs-libraries/chat/rules.description.decorator';
@@ -29,6 +30,7 @@ export class XProvider extends SocialAbstract implements SocialProvider {
name = 'X';
isBetweenSteps = false;
scopes = [] as string[];
+ stripLinks = () => !!process.env.STRIP_LINKS_FROM_X_POSTS;
override maxConcurrentJob = 1; // X has strict rate limits (300 posts per 3 hours)
toolTip =
'You will be logged in into your current account, if you would like a different account, change it first on X';
@@ -227,8 +229,9 @@ export class XProvider extends SocialAbstract implements SocialProvider {
) {
await timer(2000);
+ const plugText = stripHtmlValidation('normal', fields.post, true);
await client.v2.tweet({
- text: stripHtmlValidation('normal', fields.post, true),
+ text: this.stripLinks() ? removeLinks(plugText) : plugText,
reply: { in_reply_to_tweet_id: id },
});
return true;
@@ -469,7 +472,9 @@ export class XProvider extends SocialAbstract implements SocialProvider {
firstPost?.settings?.community?.split('/').pop() || '',
}
: {}),
- text: firstPost.message,
+ text: this.stripLinks()
+ ? removeLinks(firstPost.message)
+ : firstPost.message,
...(media_ids.length ? { media: { media_ids } } : {}),
made_with_ai: !!firstPost?.settings?.made_with_ai,
paid_partnership: !!firstPost?.settings?.paid_partnership,
@@ -536,7 +541,9 @@ export class XProvider extends SocialAbstract implements SocialProvider {
const tweetUrl = 'https://api.x.com/2/tweets';
const tweetBody = {
- text: commentPost.message,
+ text: this.stripLinks()
+ ? removeLinks(commentPost.message)
+ : commentPost.message,
...(media_ids.length ? { media: { media_ids } } : {}),
reply: { in_reply_to_tweet_id: replyToId },
made_with_ai: !!commentPost?.settings?.made_with_ai,