Skip to content

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

feat: WordPress post tags, categories, and status

Gilad Resisid027d6f7906c
diff --git a/apps/frontend/src/components/new-launch/providers/wordpress/wordpress.provider.tsx b/apps/frontend/src/components/new-launch/providers/wordpress/wordpress.provider.tsx
index b830f4e95..7876038fc 100644
--- a/apps/frontend/src/components/new-launch/providers/wordpress/wordpress.provider.tsx
+++ b/apps/frontend/src/components/new-launch/providers/wordpress/wordpress.provider.tsx
@@ -6,8 +6,10 @@ import {
withProvider,
} from '@gitroom/frontend/components/new-launch/providers/high.order.provider';
import { Input } from '@gitroom/react/form/input';
+import { Select } from '@gitroom/react/form/select';
import { useSettings } from '@gitroom/frontend/components/launches/helpers/use.values';
import { WordpressPostType } from '@gitroom/frontend/components/new-launch/providers/wordpress/wordpress.post.type';
+import { WordpressTerms } from '@gitroom/frontend/components/new-launch/providers/wordpress/wordpress.terms';
import { MediaComponent } from '@gitroom/frontend/components/media/media.component';
import { WordpressDto } from '@gitroom/nestjs-libraries/dtos/posts/providers-settings/wordpress.dto';
@@ -17,6 +19,22 @@ const WordpressSettings: FC = () => {
<>
<Input label="Title" {...form.register('title')} />
<WordpressPostType {...form.register('type')} />
+ <Select label="Status" {...form.register('status', { value: 'publish' })}>
+ <option value="publish">Publish</option>
+ <option value="draft">Draft</option>
+ <option value="pending">Pending</option>
+ <option value="private">Private</option>
+ </Select>
+ <WordpressTerms
+ label="Categories"
+ func="categoriesList"
+ {...form.register('categories')}
+ />
+ <WordpressTerms
+ label="WordPress Tags"
+ func="tagsList"
+ {...form.register('tags')}
+ />
<MediaComponent
label="Cover picture"
description="Add a cover picture"
diff --git a/apps/frontend/src/components/new-launch/providers/wordpress/wordpress.terms.tsx b/apps/frontend/src/components/new-launch/providers/wordpress/wordpress.terms.tsx
new file mode 100644
index 000000000..740bfea16
--- /dev/null
+++ b/apps/frontend/src/components/new-launch/providers/wordpress/wordpress.terms.tsx
@@ -0,0 +1,58 @@
+'use client';
+
+import { FC, useEffect, useState } from 'react';
+import { MultiSelect } from '@gitroom/react/form/multi.select';
+import { useCustomProviderFunction } from '@gitroom/frontend/components/launches/helpers/use.custom.provider.function';
+import { useSettings } from '@gitroom/frontend/components/launches/helpers/use.values';
+
+// Fetches WordPress terms (categories or tags) for the connected site and wires
+// the reusable MultiSelect primitive into the post settings form. Both fields
+// are optional - selecting nothing leaves the value as an empty array, which
+// the provider omits from the request entirely.
+export const WordpressTerms: FC<{
+ name: string;
+ label: string;
+ func: string;
+ onChange: (event: {
+ target: {
+ value: number[];
+ name: string;
+ };
+ }) => void;
+}> = (props) => {
+ const { name, label, func, onChange } = props;
+ const customFunc = useCustomProviderFunction();
+ const form = useSettings();
+ const { getValues } = form;
+ const [terms, setTerms] = useState<Array<{ id: number; name: string }>>([]);
+ const [selected, setSelected] = useState<Array<string | number>>([]);
+
+ useEffect(() => {
+ customFunc.get(func).then((data) => setTerms(data || []));
+ const settings = getValues()[name];
+ if (Array.isArray(settings)) {
+ setSelected(settings.map((value: any) => Number(value)));
+ }
+ }, []);
+
+ const onChangeInner = (value: Array<string | number>) => {
+ const numbers = value.map((current) => Number(current));
+ setSelected(numbers);
+ form.setValue(name, numbers, { shouldValidate: true });
+ onChange?.({ target: { name, value: numbers } });
+ };
+
+ if (!terms.length) {
+ return null;
+ }
+
+ return (
+ <MultiSelect
+ name={name}
+ label={label}
+ value={selected}
+ onChange={onChangeInner}
+ options={terms.map((term) => ({ label: term.name, value: term.id }))}
+ />
+ );
+};
diff --git a/libraries/nestjs-libraries/src/dtos/posts/providers-settings/wordpress.dto.ts b/libraries/nestjs-libraries/src/dtos/posts/providers-settings/wordpress.dto.ts
index 732b4e354..e159be48e 100644
--- a/libraries/nestjs-libraries/src/dtos/posts/providers-settings/wordpress.dto.ts
+++ b/libraries/nestjs-libraries/src/dtos/posts/providers-settings/wordpress.dto.ts
@@ -1,5 +1,8 @@
import {
+ IsArray,
IsDefined,
+ IsIn,
+ IsNumber,
IsOptional,
IsString,
MinLength,
@@ -22,4 +25,19 @@ export class WordpressDto {
@IsString()
@IsDefined()
type: string;
+
+ @IsOptional()
+ @IsArray()
+ @IsNumber({}, { each: true })
+ categories?: number[];
+
+ @IsOptional()
+ @IsArray()
+ @IsNumber({}, { each: true })
+ tags?: number[];
+
+ @IsOptional()
+ @IsString()
+ @IsIn(['publish', 'draft', 'pending', 'private'])
+ status?: string;
}
diff --git a/libraries/nestjs-libraries/src/integrations/social/wordpress.provider.ts b/libraries/nestjs-libraries/src/integrations/social/wordpress.provider.ts
index d44782ab4..161f598bb 100644
--- a/libraries/nestjs-libraries/src/integrations/social/wordpress.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/wordpress.provider.ts
@@ -194,11 +194,12 @@ export class WordpressProvider
};
}
- @Tool({
- description: 'Get list of post types',
- dataSchema: [],
- })
- async postTypes(token: string) {
+ // Custom provider functions below are invoked from the backend HTTP endpoint
+ // (`/integrations/function`) - which is NOT a Temporal activity - so they must
+ // use a plain `fetch` (with the SSRF guard) rather than `this.fetch`, which
+ // calls `Context.current()` and throws outside an activity. This mirrors how
+ // `authenticate` issues its request.
+ private async wpGet(token: string, path: string) {
const body = JSON.parse(Buffer.from(token, 'base64').toString()) as {
domain: string;
username: string;
@@ -209,13 +210,23 @@ export class WordpressProvider
'base64'
);
- const postTypes = await (
- await this.fetch(`${body.domain}/wp-json/wp/v2/types`, {
- headers: {
- Authorization: `Basic ${auth}`,
- },
- })
- ).json();
+ const response = await fetch(`${body.domain}${path}`, {
+ headers: {
+ Authorization: `Basic ${auth}`,
+ },
+ // @ts-ignore - undici-only option; blocks SSRF to internal IPs
+ dispatcher: getSsrfSafeDispatcher(),
+ });
+
+ return response.json();
+ }
+
+ @Tool({
+ description: 'Get list of post types',
+ dataSchema: [],
+ })
+ async postTypes(token: string) {
+ const postTypes = await this.wpGet(token, '/wp-json/wp/v2/types');
return Object.entries<any>(postTypes).reduce((all, [key, value]) => {
if (
@@ -235,6 +246,37 @@ export class WordpressProvider
}, []);
}
+ @Tool({
+ description: 'Get list of categories',
+ dataSchema: [],
+ })
+ async categoriesList(token: string) {
+ const categories = await this.wpGet(
+ token,
+ '/wp-json/wp/v2/categories?per_page=100'
+ );
+
+ return (Array.isArray(categories) ? categories : []).map(
+ (category: any) => ({
+ id: category.id,
+ name: category.name,
+ })
+ );
+ }
+
+ @Tool({
+ description: 'Get list of tags',
+ dataSchema: [],
+ })
+ async tagsList(token: string) {
+ const tags = await this.wpGet(token, '/wp-json/wp/v2/tags?per_page=100');
+
+ return (Array.isArray(tags) ? tags : []).map((tag: any) => ({
+ id: tag.id,
+ name: tag.name,
+ }));
+ }
+
async post(
id: string,
accessToken: string,
@@ -279,6 +321,13 @@ export class WordpressProvider
mediaId = mediaResponse.id;
}
+ const categories = (postDetails?.[0]?.settings?.categories || [])
+ .map((category) => Number(category))
+ .filter((category) => !isNaN(category));
+ const tags = (postDetails?.[0]?.settings?.tags || [])
+ .map((tag) => Number(tag))
+ .filter((tag) => !isNaN(tag));
+
const submit = await (
await this.fetch(
`${body.domain}/wp-json/wp/v2/${postDetails?.[0]?.settings?.type}`,
@@ -296,7 +345,9 @@ export class WordpressProvider
strict: true,
trim: true,
}),
- status: 'publish',
+ status: postDetails?.[0]?.settings?.status || 'publish',
+ ...(categories.length ? { categories } : {}),
+ ...(tags.length ? { tags } : {}),
...(mediaId ? { featured_media: mediaId } : {}),
}),
}