Skip to content

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

feat: send tests

Nevo Davidd7764faf157c
diff --git a/apps/backend/src/api/routes/webhooks.controller.ts b/apps/backend/src/api/routes/webhooks.controller.ts
index 19a787301..6b341d6ab 100644
--- a/apps/backend/src/api/routes/webhooks.controller.ts
+++ b/apps/backend/src/api/routes/webhooks.controller.ts
@@ -1,4 +1,13 @@
-import { Body, Controller, Delete, Get, Param, Post, Put } from '@nestjs/common';
+import {
+ Body,
+ Controller,
+ Delete,
+ Get,
+ Param,
+ Post,
+ Put,
+ Query,
+} from '@nestjs/common';
import { GetOrgFromRequest } from '@gitroom/nestjs-libraries/user/org.from.request';
import { Organization } from '@prisma/client';
import { ApiTags } from '@nestjs/swagger';
@@ -47,4 +56,19 @@ export class WebhookController {
) {
return this._webhooksService.deleteWebhook(org.id, id);
}
+
+ @Post('/send')
+ async sendWebhook(@Body() body: any, @Query('url') url: string) {
+ try {
+ await fetch(url, {
+ method: 'POST',
+ body: JSON.stringify(body),
+ headers: { 'Content-Type': 'application/json' },
+ });
+ } catch (err) {
+ /** sent **/
+ }
+
+ return { send: true };
+ }
}
diff --git a/apps/frontend/src/components/webhooks/webhooks.tsx b/apps/frontend/src/components/webhooks/webhooks.tsx
index 6d964d99a..a1792854f 100644
--- a/apps/frontend/src/components/webhooks/webhooks.tsx
+++ b/apps/frontend/src/components/webhooks/webhooks.tsx
@@ -175,6 +175,51 @@ export const AddOrEditWebhook: FC<{ data?: any; reload: () => void }> = (
[data, integrations]
);
+ const sendTest = useCallback(async () => {
+ const url = form.getValues('url');
+ toast.show('Webhook send', 'success');
+ try {
+ await fetch(`/webhooks/send?url=${encodeURIComponent(url)}`, {
+ method: 'POST',
+ headers: {
+ contentType: 'application/json',
+ },
+ body: JSON.stringify([
+ {
+ id: 'cm6tcts4f0005qcwit25cis26',
+ content: 'This is the first post to instagram',
+ publishDate: '2025-02-06T13:09:00.000Z',
+ releaseURL: 'https://facebook.com/release/release',
+ state: 'PUBLISHED',
+ integration: {
+ id: 'cm6s4uyou0001i2r47pxix6z1',
+ name: 'test',
+ providerIdentifier: 'instagram',
+ picture: 'https://uploads.gitroom.com/F6LSCD8wrrQ.jpeg',
+ type: 'social',
+ },
+ },
+ {
+ id: 'cm6tcts4f0005qcwit25cis26',
+ content: 'This is the second post to facebook',
+ publishDate: '2025-02-06T13:09:00.000Z',
+ releaseURL: 'https://facebook.com/release2/release2',
+ state: 'PUBLISHED',
+ integration: {
+ id: 'cm6s4uyou0001i2r47pxix6z1',
+ name: 'test2',
+ providerIdentifier: 'facebook',
+ picture: 'https://uploads.gitroom.com/F6LSCD8wrrQ.jpeg',
+ type: 'social',
+ },
+ },
+ ]),
+ });
+ } catch (e: any) {
+ /** empty **/
+ }
+ }, []);
+
return (
<FormProvider {...form}>
<form onSubmit={form.handleSubmit(callBack)}>
@@ -227,16 +272,32 @@ export const AddOrEditWebhook: FC<{ data?: any; reload: () => void }> = (
isMain={true}
/>
)}
- <Button
- type="submit"
- className="mt-[24px]"
- disabled={
- !form.formState.isValid ||
- (allIntegrations.value === 'specific' && !integrations?.length)
- }
- >
- Save
- </Button>
+ <div className="flex gap-[10px]">
+ <Button
+ type="submit"
+ className="mt-[24px]"
+ disabled={
+ !form.formState.isValid ||
+ (allIntegrations.value === 'specific' &&
+ !integrations?.length)
+ }
+ >
+ Save
+ </Button>
+ <Button
+ type="button"
+ secondary={true}
+ className="mt-[24px]"
+ onClick={sendTest}
+ disabled={
+ !form.formState.isValid ||
+ (allIntegrations.value === 'specific' &&
+ !integrations?.length)
+ }
+ >
+ Send Test
+ </Button>
+ </div>
</div>
</div>
</form>
diff --git a/libraries/nestjs-libraries/src/database/prisma/webhooks/webhooks.service.ts b/libraries/nestjs-libraries/src/database/prisma/webhooks/webhooks.service.ts
index d23bed29a..54672b5e2 100644
--- a/libraries/nestjs-libraries/src/database/prisma/webhooks/webhooks.service.ts
+++ b/libraries/nestjs-libraries/src/database/prisma/webhooks/webhooks.service.ts
@@ -73,10 +73,12 @@ export class WebhooksService {
);
}
- sendList.push({
- url: webhook.url,
- data: toSend,
- });
+ if (toSend.length) {
+ sendList.push({
+ url: webhook.url,
+ data: toSend,
+ });
+ }
}
return Promise.all(