Skip to content

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

feat: enhance api

Nevo David78b834d18f5b
diff --git a/apps/backend/src/public-api/routes/v1/public.integrations.controller.ts b/apps/backend/src/public-api/routes/v1/public.integrations.controller.ts
index 6184aff8c..4914906a5 100644
--- a/apps/backend/src/public-api/routes/v1/public.integrations.controller.ts
+++ b/apps/backend/src/public-api/routes/v1/public.integrations.controller.ts
@@ -39,6 +39,7 @@ import { getValidationSchemas } from '@gitroom/nestjs-libraries/chat/validation.
import { RefreshIntegrationService } from '@gitroom/nestjs-libraries/integrations/refresh.integration.service';
import { RefreshToken } from '@gitroom/nestjs-libraries/integrations/social.abstract';
import { timer } from '@gitroom/helpers/utils/timer';
+import { ioRedis } from '@gitroom/nestjs-libraries/redis/redis.service';
@ApiTags('Public API')
@Controller('/public/v1')
@@ -195,6 +196,49 @@ export class PublicIntegrationsController {
);
}
+ @Get('/social/:integration')
+ @CheckPolicies([AuthorizationActions.Create, Sections.CHANNEL])
+ async getIntegrationUrl(
+ @Param('integration') integration: string,
+ @Query('refresh') refresh: string,
+ @GetOrgFromRequest() org: Organization
+ ) {
+ Sentry.metrics.count('public_api-request', 1);
+ if (
+ !this._integrationManager
+ .getAllowedSocialsIntegrations()
+ .includes(integration)
+ ) {
+ throw new HttpException({ msg: 'Integration not allowed' }, 400);
+ }
+
+ const integrationProvider =
+ this._integrationManager.getSocialIntegration(integration);
+
+ if (integrationProvider.externalUrl) {
+ throw new HttpException(
+ { msg: 'This integration requires an external URL and is not supported via the public API' },
+ 400
+ );
+ }
+
+ try {
+ const { codeVerifier, state, url } =
+ await integrationProvider.generateAuthUrl();
+
+ if (refresh) {
+ await ioRedis.set(`refresh:${state}`, refresh, 'EX', 3600);
+ }
+
+ await ioRedis.set(`organization:${state}`, org.id, 'EX', 3600);
+ await ioRedis.set(`login:${state}`, codeVerifier, 'EX', 3600);
+
+ return { url };
+ } catch (err) {
+ throw new HttpException({ msg: 'Failed to generate auth URL' }, 500);
+ }
+ }
+
@Get('/notifications')
async getNotifications(
@GetOrgFromRequest() org: Organization,
@@ -226,6 +270,25 @@ export class PublicIntegrationsController {
);
}
+ @Delete('/integrations/:id')
+ async deleteChannel(
+ @GetOrgFromRequest() org: Organization,
+ @Param('id') id: string
+ ) {
+ Sentry.metrics.count('public_api-request', 1);
+ const isTherePosts = await this._integrationService.getPostsForChannel(
+ org.id,
+ id
+ );
+ if (isTherePosts.length) {
+ for (const post of isTherePosts) {
+ this._postsService.deletePost(org.id, post.group).catch(() => {});
+ }
+ }
+
+ return this._integrationService.deleteChannel(org.id, id);
+ }
+
@Get('/integration-settings/:id')
async getIntegrationSettings(
@GetOrgFromRequest() org: Organization,