π¨ The ultimate agentic social media scheduling tool π€
TypeScript nextjsopen-sourceopen-source-social-media-scheduling-toolosspostiz-cloudpostiz-hostedredisscheduling-toolsocial-media-scheduling-tooltypescript
feat: discord mention roles
Nevo David5bf30484b63d
diff --git a/apps/backend/src/api/routes/integrations.controller.ts b/apps/backend/src/api/routes/integrations.controller.tsindex 1f90e65f8..fb3eee3b2 100644--- a/apps/backend/src/api/routes/integrations.controller.ts+++ b/apps/backend/src/api/routes/integrations.controller.ts@@ -263,8 +263,10 @@ export class IntegrationsController {let newList: any[] | {none: true} = [];try {- newList = await this.functionIntegration(org, body);- } catch (err) {}+ newList = (await this.functionIntegration(org, body)) || [];+ } catch (err) {+ console.log(err);+ }if (!Array.isArray(newList) && newList?.none) {return newList;@@ -283,8 +285,9 @@ export class IntegrationsController {name: p.label || '',username: p.id || '',image: p.image || '',+ doNotCache: p.doNotCache || false,}))- .filter((f: any) => f.name)+ .filter((f: any) => f.name && !f.doNotCache));}@@ -298,7 +301,7 @@ export class IntegrationsController {...newList as any[],],(p) => p.id- ).filter((f) => f.label && f.image && f.id);+ ).filter((f) => f.label && f.id);}@Post('/function')diff --git a/apps/frontend/src/components/new-launch/mention.component.tsx b/apps/frontend/src/components/new-launch/mention.component.tsxindex 3f93caeb4..8e1ddca74 100644--- a/apps/frontend/src/components/new-launch/mention.component.tsx+++ b/apps/frontend/src/components/new-launch/mention.component.tsx@@ -100,7 +100,7 @@ const MentionList: FC = (props: any) => {onClick={() => selectItem(index)}><img- src={item.image}+ src={item.image || '/no-picture.jpg'}alt={item.label}className="w-[30px] h-[30px] rounded-full object-cover"/>diff --git a/libraries/helpers/src/utils/strip.html.validation.ts b/libraries/helpers/src/utils/strip.html.validation.tsindex 97e4eb661..870494d18 100644--- a/libraries/helpers/src/utils/strip.html.validation.ts+++ b/libraries/helpers/src/utils/strip.html.validation.ts@@ -161,6 +161,8 @@ export const stripHtmlValidation = (.replace(/<h1>([.\s\S]*?)<\/h1>/g, (match, p1) => {return `<h1># ${p1}</h1>\n`;})+ .replace(/&/gi, '&')+ .replace(/ /gi, ' ').replace(/<h2>([.\s\S]*?)<\/h2>/g, (match, p1) => {return `<h2>## ${p1}</h2>\n`;})diff --git a/libraries/nestjs-libraries/src/integrations/social.abstract.ts b/libraries/nestjs-libraries/src/integrations/social.abstract.tsindex 193c3ee99..cd14c6e85 100644--- a/libraries/nestjs-libraries/src/integrations/social.abstract.ts+++ b/libraries/nestjs-libraries/src/integrations/social.abstract.ts@@ -37,7 +37,7 @@ export abstract class SocialAbstract {d: { query: string },id: string,integration: Integration- ): Promise<{ id: string; label: string; image: string }[] | { none: true }> {+ ): Promise<{ id: string; label: string; image: string, doNotCache?: boolean }[] | { none: true }> {return { none: true };}diff --git a/libraries/nestjs-libraries/src/integrations/social/discord.provider.ts b/libraries/nestjs-libraries/src/integrations/social/discord.provider.tsindex 74da1f991..4c685d5e6 100644--- a/libraries/nestjs-libraries/src/integrations/social/discord.provider.ts+++ b/libraries/nestjs-libraries/src/integrations/social/discord.provider.ts@@ -159,7 +159,7 @@ export class DiscordProvider extends SocialAbstract implements SocialProvider {form.append('payload_json',JSON.stringify({- content: post.message.replace(/\[\[\[(@\d.*?)]]]/g, (match, p1) => {+ content: post.message.replace(/\[\[\[(@.*?)]]]/g, (match, p1) => {return `<${p1}>`;}),attachments: post.media?.map((p, index) => ({@@ -228,6 +228,21 @@ export class DiscordProvider extends SocialAbstract implements SocialProvider {id: string,integration: Integration) {+ const allRoles = await (+ await fetch(`https://discord.com/api/guilds/${id}/roles`, {+ headers: {+ Authorization: `Bot ${process.env.DISCORD_BOT_TOKEN_ID}`,+ 'Content-Type': 'application/json',+ },+ })+ ).json();++ const matching = allRoles+ .filter((role: any) =>+ role.name.toLowerCase().includes(data.query.toLowerCase())+ )+ .filter((f) => f.name !== '@everyone' && f.name !== '@here');+const list = await (await fetch(`https://discord.com/api/guilds/${id}/members/search?query=${data.query}`,@@ -240,14 +255,41 @@ export class DiscordProvider extends SocialAbstract implements SocialProvider {)).json();- return list.map((p: any) => ({- id: String(p.user.id),- label: p.user.global_name || p.user.username,- image: `https://cdn.discordapp.com/avatars/${p.user.id}/${p.user.avatar}.png`,- }));+ return [+ ...[+ {+ id: String('here'),+ label: 'here',+ image: '',+ doNotCache: true,+ },+ {+ id: String('everyone'),+ label: 'everyone',+ image: '',+ doNotCache: true,+ },+ ].filter((role: any) => {+ return role.label.toLowerCase().includes(data.query.toLowerCase());+ }),+ ...matching.map((p: any) => ({+ id: String('&' + p.id),+ label: p.name.split('@')[1],+ image: '',+ doNotCache: true,+ })),+ ...list.map((p: any) => ({+ id: String(p.user.id),+ label: p.user.global_name || p.user.username,+ image: `https://cdn.discordapp.com/avatars/${p.user.id}/${p.user.avatar}.png`,+ })),+ ];}mentionFormat(idOrHandle: string, name: string) {- return `[[[@${idOrHandle}]]]`;+ if (name === '@here' || name === '@everyone') {+ return name;+ }+ return `[[[@${idOrHandle.replace('@', '')}]]]`;}}diff --git a/libraries/nestjs-libraries/src/integrations/social/social.integrations.interface.ts b/libraries/nestjs-libraries/src/integrations/social/social.integrations.interface.tsindex 20add6544..79f9da3ad 100644--- a/libraries/nestjs-libraries/src/integrations/social/social.integrations.interface.ts+++ b/libraries/nestjs-libraries/src/integrations/social/social.integrations.interface.ts@@ -134,6 +134,6 @@ export interface SocialProvider) => Promise<{ client_id: string; client_secret: string }>;mention?: (token: string, data: { query: string }, id: string, integration: Integration- ) => Promise<{ id: string; label: string; image: string }[] | {none: true}>;+ ) => Promise<{ id: string; label: string; image: string, doNotCache?: boolean }[] | {none: true}>;mentionFormat?(idOrHandle: string, name: string): string;}