Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

feat(reddit): add AI actions and output schemas (#16100)

Kishan Parmara78ede33cde2
diff --git a/packages/pieces/community/reddit/package.json b/packages/pieces/community/reddit/package.json
index f327f8fbbb1..ae16c83519b 100644
--- a/packages/pieces/community/reddit/package.json
+++ b/packages/pieces/community/reddit/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/piece-reddit",
- "version": "0.3.0",
+ "version": "0.4.0",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"scripts": {
diff --git a/packages/pieces/community/reddit/src/index.ts b/packages/pieces/community/reddit/src/index.ts
index 26e907fe591..253956735d0 100644
--- a/packages/pieces/community/reddit/src/index.ts
+++ b/packages/pieces/community/reddit/src/index.ts
@@ -1,5 +1,5 @@
import { createCustomApiCallAction } from '@activepieces/pieces-common';
-import { createPiece, PieceAuth, OAuth2AuthorizationMethod, Property, OAuth2PropertyValue } from "@activepieces/pieces-framework";
+import { createPiece, OAuth2PropertyValue } from '@activepieces/pieces-framework';
import { retrieveRedditPost } from './lib/actions/retrieve-reddit-post';
import { getRedditPostDetails } from './lib/actions/get-reddit-post-details';
import { createRedditPost } from './lib/actions/create-reddit-post';
@@ -10,29 +10,61 @@ import { editRedditComment } from './lib/actions/edit-reddit-comment';
import { deleteRedditPost } from './lib/actions/delete-reddit-post';
import { deleteRedditComment } from './lib/actions/delete-reddit-comment';
import { PieceCategory } from '@activepieces/pieces-framework';
-import { OAuth2GrantType } from '@activepieces/pieces-framework';
import { redditAuth } from './lib/auth';
+import { redditCreateComment } from './lib/actions/ai/create-comment';
+import { redditCreatePost } from './lib/actions/ai/create-post';
+import { redditCrosspost } from './lib/actions/ai/crosspost';
+import { redditDeleteComment } from './lib/actions/ai/delete-comment';
+import { redditDeleteMessage } from './lib/actions/ai/delete-message';
+import { redditDeletePost } from './lib/actions/ai/delete-post';
+import { redditEditText } from './lib/actions/ai/edit-text';
+import { redditExpandMoreComments } from './lib/actions/ai/expand-more-comments';
+import { redditGetContent } from './lib/actions/ai/get-content';
+import { redditGetMe } from './lib/actions/ai/get-me';
+import { redditGetMyKarma } from './lib/actions/ai/get-my-karma';
+import { redditGetMyPreferences } from './lib/actions/ai/get-my-preferences';
+import { redditGetPostRequirements } from './lib/actions/ai/get-post-requirements';
+import { redditGetSubmitText } from './lib/actions/ai/get-submit-text';
+import { redditGetSubredditRules } from './lib/actions/ai/get-subreddit-rules';
+import { redditGetSubreddit } from './lib/actions/ai/get-subreddit';
+import { redditGetUserTrophies } from './lib/actions/ai/get-user-trophies';
+import { redditGetUser } from './lib/actions/ai/get-user';
+import { redditGetWikiPage } from './lib/actions/ai/get-wiki-page';
+import { redditHidePost } from './lib/actions/ai/hide-post';
+import { redditListDuplicates } from './lib/actions/ai/list-duplicates';
+import { redditListMessages } from './lib/actions/ai/list-messages';
+import { redditListMySubreddits } from './lib/actions/ai/list-my-subreddits';
+import { redditListPostComments } from './lib/actions/ai/list-post-comments';
+import { redditListPostFlairs } from './lib/actions/ai/list-post-flairs';
+import { redditListPosts } from './lib/actions/ai/list-posts';
+import { redditListSavedCategories } from './lib/actions/ai/list-saved-categories';
+import { redditListSubredditComments } from './lib/actions/ai/list-subreddit-comments';
+import { redditListSubredditModerators } from './lib/actions/ai/list-subreddit-moderators';
+import { redditListSubreddits } from './lib/actions/ai/list-subreddits';
+import { redditListUserContent } from './lib/actions/ai/list-user-content';
+import { redditListUserFlairs } from './lib/actions/ai/list-user-flairs';
+import { redditListWikiPages } from './lib/actions/ai/list-wiki-pages';
+import { redditMarkAllMessagesRead } from './lib/actions/ai/mark-all-messages-read';
+import { redditMarkMessageRead } from './lib/actions/ai/mark-message-read';
+import { redditReportContent } from './lib/actions/ai/report-content';
+import { redditSaveContent } from './lib/actions/ai/save-content';
+import { redditSearchPosts } from './lib/actions/ai/search-posts';
+import { redditSearchSubreddits } from './lib/actions/ai/search-subreddits';
+import { redditSearchUsers } from './lib/actions/ai/search-users';
+import { redditSendMessage } from './lib/actions/ai/send-message';
+import { redditSetInboxReplies } from './lib/actions/ai/set-inbox-replies';
+import { redditSetPostFlair } from './lib/actions/ai/set-post-flair';
+import { redditSubscribeSubreddit } from './lib/actions/ai/subscribe-subreddit';
+import { redditUnhidePost } from './lib/actions/ai/unhide-post';
+import { redditUnsaveContent } from './lib/actions/ai/unsave-content';
+import { redditUnsubscribeSubreddit } from './lib/actions/ai/unsubscribe-subreddit';
-const markdown = `
-To obtain your Reddit API credentials:
-
-1. Go to https://www.reddit.com/prefs/apps.
-2. Click "create another app..." at the bottom.
-3. Select "script" as the app type.
-4. Fill in the required information:
- - name: Your app name
- - description: Brief description
- - about url: Can be left blank
- - redirect uri: as shown in Redirect URL field
-5. Click "create app".
-6. Note down the client ID (under the app name) and client secret.
-`;
export const reddit = createPiece({
displayName: 'Reddit',
description: 'Interact with Reddit - fetch and submit posts.',
logoUrl: 'https://cdn.activepieces.com/pieces/reddit.png',
- minimumSupportedRelease: '0.36.1',
+ minimumSupportedRelease: '0.88.2',
categories: [PieceCategory.COMMUNICATION],
authors: ['bhaviksingla1403'],
auth: redditAuth,
@@ -46,6 +78,53 @@ export const reddit = createPiece({
editRedditComment,
deleteRedditPost,
deleteRedditComment,
+ redditCreateComment,
+ redditCreatePost,
+ redditCrosspost,
+ redditDeleteComment,
+ redditDeleteMessage,
+ redditDeletePost,
+ redditEditText,
+ redditExpandMoreComments,
+ redditGetContent,
+ redditGetMe,
+ redditGetMyKarma,
+ redditGetMyPreferences,
+ redditGetPostRequirements,
+ redditGetSubmitText,
+ redditGetSubredditRules,
+ redditGetSubreddit,
+ redditGetUserTrophies,
+ redditGetUser,
+ redditGetWikiPage,
+ redditHidePost,
+ redditListDuplicates,
+ redditListMessages,
+ redditListMySubreddits,
+ redditListPostComments,
+ redditListPostFlairs,
+ redditListPosts,
+ redditListSavedCategories,
+ redditListSubredditComments,
+ redditListSubredditModerators,
+ redditListSubreddits,
+ redditListUserContent,
+ redditListUserFlairs,
+ redditListWikiPages,
+ redditMarkAllMessagesRead,
+ redditMarkMessageRead,
+ redditReportContent,
+ redditSaveContent,
+ redditSearchPosts,
+ redditSearchSubreddits,
+ redditSearchUsers,
+ redditSendMessage,
+ redditSetInboxReplies,
+ redditSetPostFlair,
+ redditSubscribeSubreddit,
+ redditUnhidePost,
+ redditUnsaveContent,
+ redditUnsubscribeSubreddit,
createCustomApiCallAction({
auth: redditAuth,
baseUrl: () => {
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/create-comment.ts b/packages/pieces/community/reddit/src/lib/actions/ai/create-comment.ts
new file mode 100644
index 00000000000..5daff3e2c9b
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/create-comment.ts
@@ -0,0 +1,42 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi, RedditThing } from '../../common/client';
+import { redditCreateCommentOutputSchema } from '../../output-schemas';
+
+export const redditCreateComment = createAction({
+ auth: redditAuth,
+ name: 'reddit_create_comment',
+ outputSchema: redditCreateCommentOutputSchema,
+ displayName: 'Create Comment',
+ description: 'Replies to a post, a comment or a private message.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Posts a reply: to a post (t3_ parent), a comment (t1_ parent) or a private message (t4_ parent). The parent id must carry its type prefix; it is the `name` field of the item. Fails on locked or archived threads. Not idempotent: every call posts a new reply.',
+ idempotent: false,
+ },
+ props: {
+ parent_id: Property.ShortText({ displayName: 'Parent Fullname', description: 'Fullname to reply to, e.g. "t3_abc123", "t1_def456" or "t4_ghi789".', required: true }),
+ text: Property.LongText({ displayName: 'Text', description: 'Markdown body of the reply.', required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const response = await redditApi.request<ThingsResponse>({
+ auth,
+ method: HttpMethod.POST,
+ path: '/api/comment',
+ form: {
+ api_type: 'json',
+ thing_id: redditApi.requireFullname({ value: propsValue.parent_id, label: 'Parent Fullname' }),
+ text: propsValue.text,
+ },
+ });
+ const thing = response.json.data?.things?.[0];
+ return thing ? redditApi.toThing({ thing }) : { success: true };
+ },
+});
+
+type ThingsResponse = {
+ json: { data?: { things?: RedditThing[] } };
+};
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/create-post.ts b/packages/pieces/community/reddit/src/lib/actions/ai/create-post.ts
new file mode 100644
index 00000000000..67d6dcff3f7
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/create-post.ts
@@ -0,0 +1,61 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditCreatePostOutputSchema } from '../../output-schemas';
+
+export const redditCreatePost = createAction({
+ auth: redditAuth,
+ name: 'reddit_create_post',
+ outputSchema: redditCreatePostOutputSchema,
+ displayName: 'Create Post',
+ description: 'Publishes a text or link post to a subreddit.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Publishes a new post to a subreddit: a text post when Text is given, a link post when URL is given (not both). Publishes immediately and publicly. Check Get Post Requirements first for required flair or title rules; Flair ID comes from List Post Flairs. Not idempotent: every call creates a new post.',
+ idempotent: false,
+ },
+ props: {
+ subreddit: redditAiProps.subreddit({ required: true }),
+ title: Property.ShortText({ displayName: 'Title', description: 'Post title (max 300 characters).', required: true }),
+ text: Property.LongText({ displayName: 'Text', description: 'Markdown body for a text post. Leave empty for a link post.', required: false }),
+ url: Property.ShortText({ displayName: 'URL', description: 'Link for a link post. Leave empty for a text post.', required: false }),
+ flair_id: Property.ShortText({ displayName: 'Flair ID', description: 'Flair template id from List Post Flairs.', required: false }),
+ flair_text: Property.ShortText({ displayName: 'Flair Text', description: 'Custom flair text, when the flair template allows editing.', required: false }),
+ nsfw: redditAiProps.optionalBoolean({ displayName: 'NSFW', description: 'Mark the post as not safe for work.' }),
+ spoiler: redditAiProps.optionalBoolean({ displayName: 'Spoiler', description: 'Mark the post as a spoiler.' }),
+ send_replies: redditAiProps.optionalBoolean({ displayName: 'Send Replies to Inbox', description: 'Receive inbox notifications for replies (Reddit default: yes).' }),
+ },
+ async run({ auth, propsValue }) {
+ if (propsValue.text && propsValue.url) {
+ throw new Error('Provide either Text (text post) or URL (link post), not both.');
+ }
+ const response = await redditApi.request<SubmitResponse>({
+ auth,
+ method: HttpMethod.POST,
+ path: '/api/submit',
+ form: {
+ api_type: 'json',
+ sr: redditApi.cleanSubreddit({ value: propsValue.subreddit }),
+ title: propsValue.title,
+ kind: propsValue.url ? 'link' : 'self',
+ text: propsValue.text,
+ url: propsValue.url,
+ flair_id: propsValue.flair_id,
+ flair_text: propsValue.flair_text,
+ nsfw: propsValue.nsfw,
+ spoiler: propsValue.spoiler,
+ sendreplies: propsValue.send_replies,
+ },
+ });
+ const data = response.json.data;
+ return { id: data?.id ?? null, name: data?.name ?? null, url: data?.url ?? null };
+ },
+});
+
+type SubmitResponse = {
+ json: { data?: { id?: string; name?: string; url?: string } };
+};
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/crosspost.ts b/packages/pieces/community/reddit/src/lib/actions/ai/crosspost.ts
new file mode 100644
index 00000000000..64ae39f795a
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/crosspost.ts
@@ -0,0 +1,52 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditCreatePostOutputSchema } from '../../output-schemas';
+
+export const redditCrosspost = createAction({
+ auth: redditAuth,
+ name: 'reddit_crosspost',
+ outputSchema: redditCreatePostOutputSchema,
+ displayName: 'Crosspost',
+ description: 'Shares an existing post into another subreddit as a crosspost.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Crossposts an existing post into another subreddit under a new title, linking back to the original. The target subreddit must allow crossposts. Post ID comes from List Posts or Search Posts. Not idempotent: every call creates a new post.',
+ idempotent: false,
+ },
+ props: {
+ post_id: Property.ShortText({ displayName: 'Original Post ID', description: 'Post to crosspost, e.g. "abc123" or "t3_abc123".', required: true }),
+ subreddit: redditAiProps.subreddit({ required: true, description: 'Target subreddit without r/.' }),
+ title: Property.ShortText({ displayName: 'Title', description: 'Title for the crosspost (max 300 characters).', required: true }),
+ flair_id: Property.ShortText({ displayName: 'Flair ID', description: 'Flair template id from List Post Flairs for the target subreddit.', required: false }),
+ nsfw: redditAiProps.optionalBoolean({ displayName: 'NSFW', description: 'Mark the crosspost as not safe for work.' }),
+ spoiler: redditAiProps.optionalBoolean({ displayName: 'Spoiler', description: 'Mark the crosspost as a spoiler.' }),
+ },
+ async run({ auth, propsValue }) {
+ const response = await redditApi.request<SubmitResponse>({
+ auth,
+ method: HttpMethod.POST,
+ path: '/api/submit',
+ form: {
+ api_type: 'json',
+ kind: 'crosspost',
+ sr: redditApi.cleanSubreddit({ value: propsValue.subreddit }),
+ title: propsValue.title,
+ crosspost_fullname: redditApi.toFullname({ value: propsValue.post_id, prefix: 't3_' }),
+ flair_id: propsValue.flair_id,
+ nsfw: propsValue.nsfw,
+ spoiler: propsValue.spoiler,
+ },
+ });
+ const data = response.json.data;
+ return { id: data?.id ?? null, name: data?.name ?? null, url: data?.url ?? null };
+ },
+});
+
+type SubmitResponse = {
+ json: { data?: { id?: string; name?: string; url?: string } };
+};
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/delete-comment.ts b/packages/pieces/community/reddit/src/lib/actions/ai/delete-comment.ts
new file mode 100644
index 00000000000..0dbfd4cd1de
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/delete-comment.ts
@@ -0,0 +1,28 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditDeleteMessageOutputSchema } from '../../output-schemas';
+
+export const redditDeleteComment = createAction({
+ auth: redditAuth,
+ name: 'reddit_delete_comment',
+ outputSchema: redditDeleteMessageOutputSchema,
+ displayName: 'Delete Comment',
+ description: 'Permanently deletes one of your comments.',
+ audience: 'ai',
+ classification: 'DESTRUCTIVE',
+ aiMetadata: {
+ description:
+ 'Permanently deletes a comment you authored; this cannot be undone. Accepts the comment id with or without the t1_ prefix. Reddit reports success even when the comment is not yours or already deleted.',
+ idempotent: false,
+ },
+ props: {
+ comment_id: Property.ShortText({ displayName: 'Comment ID', description: 'Comment id, e.g. "def456" or "t1_def456".', required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const id = redditApi.toFullname({ value: propsValue.comment_id, prefix: 't1_' });
+ await redditApi.request<unknown>({ auth, method: HttpMethod.POST, path: '/api/del', form: { id } });
+ return { success: true, id };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/delete-message.ts b/packages/pieces/community/reddit/src/lib/actions/ai/delete-message.ts
new file mode 100644
index 00000000000..a625ab14b65
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/delete-message.ts
@@ -0,0 +1,28 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditDeleteMessageOutputSchema } from '../../output-schemas';
+
+export const redditDeleteMessage = createAction({
+ auth: redditAuth,
+ name: 'reddit_delete_message',
+ outputSchema: redditDeleteMessageOutputSchema,
+ displayName: 'Delete Message',
+ description: 'Deletes a private message from your inbox.',
+ audience: 'ai',
+ classification: 'DESTRUCTIVE',
+ aiMetadata: {
+ description:
+ 'Deletes a received private message from your inbox; the other party keeps their copy. Accepts the message id with or without the t4_ prefix, from List Messages. Cannot be undone. Needs the `privatemessages` scope: older connections must reconnect.',
+ idempotent: false,
+ },
+ props: {
+ message_id: Property.ShortText({ displayName: 'Message ID', description: 'Message id, e.g. "abc123" or "t4_abc123".', required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const id = redditApi.toFullname({ value: propsValue.message_id, prefix: 't4_' });
+ await redditApi.request<unknown>({ auth, method: HttpMethod.POST, path: '/api/del_msg', form: { id } });
+ return { success: true, id };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/delete-post.ts b/packages/pieces/community/reddit/src/lib/actions/ai/delete-post.ts
new file mode 100644
index 00000000000..1eaa213202f
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/delete-post.ts
@@ -0,0 +1,28 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditDeleteMessageOutputSchema } from '../../output-schemas';
+
+export const redditDeletePost = createAction({
+ auth: redditAuth,
+ name: 'reddit_delete_post',
+ outputSchema: redditDeleteMessageOutputSchema,
+ displayName: 'Delete Post',
+ description: 'Permanently deletes one of your posts.',
+ audience: 'ai',
+ classification: 'DESTRUCTIVE',
+ aiMetadata: {
+ description:
+ 'Permanently deletes a post you authored; this cannot be undone. Accepts the post id with or without the t3_ prefix. Reddit reports success even when the post is not yours or already deleted, so confirm with Get Posts or Comments by ID if it matters.',
+ idempotent: false,
+ },
+ props: {
+ post_id: Property.ShortText({ displayName: 'Post ID', description: 'Post id, e.g. "abc123" or "t3_abc123".', required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const id = redditApi.toFullname({ value: propsValue.post_id, prefix: 't3_' });
+ await redditApi.request<unknown>({ auth, method: HttpMethod.POST, path: '/api/del', form: { id } });
+ return { success: true, id };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/edit-text.ts b/packages/pieces/community/reddit/src/lib/actions/ai/edit-text.ts
new file mode 100644
index 00000000000..299e37125bf
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/edit-text.ts
@@ -0,0 +1,42 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi, RedditThing } from '../../common/client';
+import { redditEditTextOutputSchema } from '../../output-schemas';
+
+export const redditEditText = createAction({
+ auth: redditAuth,
+ name: 'reddit_edit_text',
+ outputSchema: redditEditTextOutputSchema,
+ displayName: 'Edit Post or Comment Text',
+ description: 'Replaces the body text of one of your text posts or comments.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Replaces the full markdown body of a text post (t3_) or comment (t1_) you authored. Titles and link posts cannot be edited. The id must carry its type prefix; the `name` field of a post or comment is its fullname.',
+ idempotent: true,
+ },
+ props: {
+ thing_id: Property.ShortText({ displayName: 'Fullname', description: 'Fullname of your post or comment, e.g. "t3_abc123" or "t1_def456".', required: true }),
+ text: Property.LongText({ displayName: 'New Text', description: 'New markdown body; replaces the existing text.', required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const response = await redditApi.request<ThingsResponse>({
+ auth,
+ method: HttpMethod.POST,
+ path: '/api/editusertext',
+ form: {
+ api_type: 'json',
+ thing_id: redditApi.requireFullname({ value: propsValue.thing_id, label: 'Fullname' }),
+ text: propsValue.text,
+ },
+ });
+ const thing = response.json.data?.things?.[0];
+ return thing ? redditApi.toThing({ thing }) : { success: true };
+ },
+});
+
+type ThingsResponse = {
+ json: { data?: { things?: RedditThing[] } };
+};
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/expand-more-comments.ts b/packages/pieces/community/reddit/src/lib/actions/ai/expand-more-comments.ts
new file mode 100644
index 00000000000..f78bf58590e
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/expand-more-comments.ts
@@ -0,0 +1,67 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi, RedditThing } from '../../common/client';
+import { redditExpandMoreCommentsOutputSchema } from '../../output-schemas';
+
+export const redditExpandMoreComments = createAction({
+ auth: redditAuth,
+ name: 'reddit_expand_more_comments',
+ outputSchema: redditExpandMoreCommentsOutputSchema,
+ displayName: 'Expand More Comments',
+ description: 'Loads comments hidden behind a "load more comments" placeholder.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ 'Loads the comments behind a `more` placeholder returned by List Post Comments: pass the post id and the placeholder\'s `children` ids (up to 100). Returns the loaded comments flat, plus any further `more` placeholders.',
+ idempotent: true,
+ },
+ props: {
+ post_id: Property.ShortText({ displayName: 'Post ID', description: 'Post id, e.g. "abc123" or "t3_abc123".', required: true }),
+ children: Property.ShortText({ displayName: 'Comment IDs', description: 'Comma-separated ids from a `more` placeholder\'s `children`.', required: true }),
+ sort: Property.StaticDropdown({
+ displayName: 'Sort',
+ description: 'Comment sort order (default best).',
+ required: false,
+ options: {
+ options: [
+ { label: 'Best', value: 'confidence' },
+ { label: 'Top', value: 'top' },
+ { label: 'New', value: 'new' },
+ { label: 'Controversial', value: 'controversial' },
+ { label: 'Old', value: 'old' },
+ { label: 'Q&A', value: 'qa' },
+ ],
+ },
+ }),
+ },
+ async run({ auth, propsValue }) {
+ const children = propsValue.children
+ .split(',')
+ .map((id) => redditApi.toBaseId({ value: id }))
+ .filter((id) => id !== '');
+ if (children.length === 0 || children.length > 100) {
+ throw new Error('Provide between 1 and 100 comment ids.');
+ }
+ const response = await redditApi.request<MoreChildrenResponse>({
+ auth,
+ method: HttpMethod.GET,
+ path: '/api/morechildren',
+ query: {
+ api_type: 'json',
+ link_id: redditApi.toFullname({ value: propsValue.post_id, prefix: 't3_' }),
+ children: children.join(','),
+ sort: propsValue.sort,
+ },
+ });
+ const things = response.json.data?.things ?? [];
+ const comments = things.filter((thing) => thing.kind !== 'more').map((thing) => redditApi.toThing({ thing }));
+ const more = things.filter((thing) => thing.kind === 'more').map((thing) => redditApi.toThing({ thing }));
+ return { comments, count: comments.length, more };
+ },
+});
+
+type MoreChildrenResponse = {
+ json: { data?: { things?: RedditThing[] } };
+};
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/get-content.ts b/packages/pieces/community/reddit/src/lib/actions/ai/get-content.ts
new file mode 100644
index 00000000000..8c9a092a85e
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/get-content.ts
@@ -0,0 +1,44 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi, RedditListing } from '../../common/client';
+import { redditGetContentOutputSchema } from '../../output-schemas';
+
+export const redditGetContent = createAction({
+ auth: redditAuth,
+ name: 'reddit_get_content',
+ outputSchema: redditGetContentOutputSchema,
+ displayName: 'Get Posts or Comments by ID',
+ description: 'Gets one or more posts, comments or subreddits by their Reddit fullname.',
+ audience: 'ai',
+ classification: 'READ',
+ aiMetadata: {
+ description:
+ 'Fetches posts (t3_), comments (t1_) or subreddits (t5_) by fullname, up to 100 at once, without the surrounding thread. Ids must carry their type prefix; the `name` field of any listed item is its fullname. Use List Post Comments to read a whole discussion.',
+ idempotent: true,
+ },
+ props: {
+ ids: Property.ShortText({
+ displayName: 'Fullnames',
+ description: 'Comma-separated fullnames, e.g. "t3_abc123,t1_def456".',
+ required: true,
+ }),
+ },
+ async run({ auth, propsValue }) {
+ const ids = propsValue.ids
+ .split(',')
+ .filter((id) => id.trim() !== '')
+ .map((id) => redditApi.requireFullname({ value: id, label: 'Each id' }));
+ if (ids.length === 0 || ids.length > 100) {
+ throw new Error('Provide between 1 and 100 fullnames.');
+ }
+ const listing = await redditApi.request<RedditListing>({
+ auth,
+ method: HttpMethod.GET,
+ path: '/api/info',
+ query: { id: ids.join(',') },
+ });
+ const { items, count } = redditApi.toListing({ listing });
+ return { items, count };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/get-me.ts b/packages/pieces/community/reddit/src/lib/actions/ai/get-me.ts
new file mode 100644
index 00000000000..b18a0b0cabd
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/get-me.ts
@@ -0,0 +1,26 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditGetMeOutputSchema } from '../../output-schemas';
+
+export const redditGetMe = createAction({
+ auth: redditAuth,
+ name: 'reddit_get_me',
+ outputSchema: redditGetMeOutputSchema,
+ displayName: 'Get My Account',
+ description: 'Gets the connected Reddit account: username, karma and inbox status.',
+ audience: 'ai',
+ classification: 'READ',
+ aiMetadata: {
+ description:
+ 'Returns the connected account\'s profile: username (`name`), id, karma, account age, verification and unread inbox count. Use it to learn which username the agent acts as, e.g. before List User Content on yourself.',
+ idempotent: true,
+ },
+ props: {},
+ async run({ auth }) {
+ const data = await redditApi.request<Record<string, unknown>>({ auth, method: HttpMethod.GET, path: '/api/v1/me' });
+ const { kind, ...profile } = redditApi.toThing({ thing: { kind: 't2', data } });
+ return { ...profile, inbox_count: data['inbox_count'] ?? null, has_mail: data['has_mail'] ?? null, over_18: data['over_18'] ?? null };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/get-my-karma.ts b/packages/pieces/community/reddit/src/lib/actions/ai/get-my-karma.ts
new file mode 100644
index 00000000000..3bac3c2e8df
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/get-my-karma.ts
@@ -0,0 +1,34 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditGetMyKarmaOutputSchema } from '../../output-schemas';
+
+export const redditGetMyKarma = createAction({
+ auth: redditAuth,
+ name: 'reddit_get_my_karma',
+ outputSchema: redditGetMyKarmaOutputSchema,
+ displayName: 'Get My Karma by Subreddit',
+ description: 'Breaks down the connected account\'s karma by subreddit.',
+ audience: 'ai',
+ classification: 'READ',
+ aiMetadata: {
+ description:
+ 'Returns the connected account\'s post and comment karma per subreddit, useful for checking eligibility in subreddits with karma thresholds. Needs the `mysubreddits` scope: older connections must reconnect.',
+ idempotent: true,
+ },
+ props: {},
+ async run({ auth }) {
+ const response = await redditApi.request<{ data?: { sr?: string; link_karma?: number; comment_karma?: number }[] }>({
+ auth,
+ method: HttpMethod.GET,
+ path: '/api/v1/me/karma',
+ });
+ const karma = (response.data ?? []).map((entry) => ({
+ subreddit: entry.sr ?? null,
+ link_karma: entry.link_karma ?? 0,
+ comment_karma: entry.comment_karma ?? 0,
+ }));
+ return { karma, count: karma.length };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/get-my-preferences.ts b/packages/pieces/community/reddit/src/lib/actions/ai/get-my-preferences.ts
new file mode 100644
index 00000000000..e7038ee4847
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/get-my-preferences.ts
@@ -0,0 +1,24 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditGetMyPreferencesOutputSchema } from '../../output-schemas';
+
+export const redditGetMyPreferences = createAction({
+ auth: redditAuth,
+ name: 'reddit_get_my_preferences',
+ outputSchema: redditGetMyPreferencesOutputSchema,
+ displayName: 'Get My Preferences',
+ description: 'Gets the connected account\'s Reddit preference settings.',
+ audience: 'ai',
+ classification: 'READ',
+ aiMetadata: {
+ description:
+ 'Returns the connected account\'s settings as one object: language, NSFW visibility, default comment sort, inbox and email notification switches, who can message you, and similar preferences. Read-only.',
+ idempotent: true,
+ },
+ props: {},
+ async run({ auth }) {
+ return redditApi.request<Record<string, unknown>>({ auth, method: HttpMethod.GET, path: '/api/v1/me/prefs' });
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/get-post-requirements.ts b/packages/pieces/community/reddit/src/lib/actions/ai/get-post-requirements.ts
new file mode 100644
index 00000000000..3421b0061cd
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/get-post-requirements.ts
@@ -0,0 +1,31 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditGetPostRequirementsOutputSchema } from '../../output-schemas';
+
+export const redditGetPostRequirements = createAction({
+ auth: redditAuth,
+ name: 'reddit_get_post_requirements',
+ outputSchema: redditGetPostRequirementsOutputSchema,
+ displayName: 'Get Post Requirements',
+ description: 'Gets the validation rules a new post in a subreddit must meet.',
+ audience: 'ai',
+ classification: 'READ',
+ aiMetadata: {
+ description:
+ 'Returns the machine-checked requirements for posting in a subreddit: title length and required or banned words, body rules, whether flair is required, banned and allowed domains, and link repost rules. Call before Create Post to avoid rejected submissions.',
+ idempotent: true,
+ },
+ props: {
+ subreddit: redditAiProps.subreddit({ required: true }),
+ },
+ async run({ auth, propsValue }) {
+ return redditApi.request<Record<string, unknown>>({
+ auth,
+ method: HttpMethod.GET,
+ path: `/api/v1/${redditApi.cleanSubreddit({ value: propsValue.subreddit })}/post_requirements`,
+ });
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/get-submit-text.ts b/packages/pieces/community/reddit/src/lib/actions/ai/get-submit-text.ts
new file mode 100644
index 00000000000..8ab3ac631b5
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/get-submit-text.ts
@@ -0,0 +1,33 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditGetSubmitTextOutputSchema } from '../../output-schemas';
+
+export const redditGetSubmitText = createAction({
+ auth: redditAuth,
+ name: 'reddit_get_submit_text',
+ outputSchema: redditGetSubmitTextOutputSchema,
+ displayName: 'Get Submission Guidelines',
+ description: 'Gets the guideline text a subreddit shows on its submit page.',
+ audience: 'ai',
+ classification: 'READ',
+ aiMetadata: {
+ description:
+ 'Returns the free-text submission guidelines moderators show on a subreddit\'s submit page (often empty). Complements Get Subreddit Rules and Get Post Requirements, which hold the structured rules.',
+ idempotent: true,
+ },
+ props: {
+ subreddit: redditAiProps.subreddit({ required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const subreddit = redditApi.cleanSubreddit({ value: propsValue.subreddit });
+ const response = await redditApi.request<{ submit_text?: string; submit_text_html?: string | null }>({
+ auth,
+ method: HttpMethod.GET,
+ path: `/r/${subreddit}/api/submit_text`,
+ });
+ return { subreddit, submit_text: response.submit_text ?? '', submit_text_html: response.submit_text_html ?? null };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/get-subreddit-rules.ts b/packages/pieces/community/reddit/src/lib/actions/ai/get-subreddit-rules.ts
new file mode 100644
index 00000000000..0d2ab2a50d9
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/get-subreddit-rules.ts
@@ -0,0 +1,52 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditGetSubredditRulesOutputSchema } from '../../output-schemas';
+
+export const redditGetSubredditRules = createAction({
+ auth: redditAuth,
+ name: 'reddit_get_subreddit_rules',
+ outputSchema: redditGetSubredditRulesOutputSchema,
+ displayName: 'Get Subreddit Rules',
+ description: 'Gets a subreddit\'s posting rules.',
+ audience: 'ai',
+ classification: 'READ',
+ aiMetadata: {
+ description:
+ 'Returns a subreddit\'s rules in priority order (short name, description, and whether each applies to posts, comments or both), plus Reddit\'s site-wide rules. Check before posting or commenting; rule short names are also valid report reasons.',
+ idempotent: true,
+ },
+ props: {
+ subreddit: redditAiProps.subreddit({ required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const response = await redditApi.request<RulesResponse>({
+ auth,
+ method: HttpMethod.GET,
+ path: `/r/${redditApi.cleanSubreddit({ value: propsValue.subreddit })}/about/rules`,
+ });
+ const rules = (response.rules ?? []).map((rule) => ({
+ short_name: rule.short_name ?? null,
+ description: rule.description ?? null,
+ kind: rule.kind ?? null,
+ priority: rule.priority ?? null,
+ violation_reason: rule.violation_reason ?? null,
+ created_utc: rule.created_utc ?? null,
+ }));
+ return { rules, count: rules.length, site_rules: response.site_rules ?? [] };
+ },
+});
+
+type RulesResponse = {
+ rules?: {
+ short_name?: string;
+ description?: string;
+ kind?: string;
+ priority?: number;
+ violation_reason?: string;
+ created_utc?: number;
+ }[];
+ site_rules?: string[];
+};
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/get-subreddit.ts b/packages/pieces/community/reddit/src/lib/actions/ai/get-subreddit.ts
new file mode 100644
index 00000000000..773bd584d71
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/get-subreddit.ts
@@ -0,0 +1,32 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi, RedditThing } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditGetSubredditOutputSchema } from '../../output-schemas';
+
+export const redditGetSubreddit = createAction({
+ auth: redditAuth,
+ name: 'reddit_get_subreddit',
+ outputSchema: redditGetSubredditOutputSchema,
+ displayName: 'Get Subreddit',
+ description: 'Gets a subreddit\'s details: title, description, subscribers and settings.',
+ audience: 'ai',
+ classification: 'READ',
+ aiMetadata: {
+ description:
+ 'Returns one subreddit\'s profile: title, public description, subscriber and active counts, type (public/restricted/private), allowed submission types, NSFW flag, and whether you are subscribed or a moderator. Use Get Subreddit Rules and Get Post Requirements before posting.',
+ idempotent: true,
+ },
+ props: {
+ subreddit: redditAiProps.subreddit({ required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const thing = await redditApi.request<RedditThing>({
+ auth,
+ method: HttpMethod.GET,
+ path: `/r/${redditApi.cleanSubreddit({ value: propsValue.subreddit })}/about`,
+ });
+ return redditApi.toThing({ thing });
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/get-user-trophies.ts b/packages/pieces/community/reddit/src/lib/actions/ai/get-user-trophies.ts
new file mode 100644
index 00000000000..2d3c82f36ec
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/get-user-trophies.ts
@@ -0,0 +1,37 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi, RedditThing } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditGetUserTrophiesOutputSchema } from '../../output-schemas';
+
+export const redditGetUserTrophies = createAction({
+ auth: redditAuth,
+ name: 'reddit_get_user_trophies',
+ outputSchema: redditGetUserTrophiesOutputSchema,
+ displayName: 'Get User Trophies',
+ description: 'Lists the trophies shown on a user\'s profile.',
+ audience: 'ai',
+ classification: 'READ',
+ aiMetadata: {
+ description:
+ 'Lists a user\'s profile trophies (e.g. account-age milestones, Verified Email), with name, description and grant time. Works for your own username too.',
+ idempotent: true,
+ },
+ props: {
+ username: redditAiProps.username({}),
+ },
+ async run({ auth, propsValue }) {
+ const response = await redditApi.request<{ data?: { trophies?: RedditThing[] } }>({
+ auth,
+ method: HttpMethod.GET,
+ path: `/api/v1/user/${redditApi.cleanUsername({ value: propsValue.username })}/trophies`,
+ });
+ const trophies = (response.data?.trophies ?? []).map((trophy) =>
+ Object.fromEntries(TROPHY_FIELDS.map((key) => [key, trophy.data[key] ?? null])),
+ );
+ return { trophies, count: trophies.length };
+ },
+});
+
+const TROPHY_FIELDS = ['id', 'name', 'description', 'award_id', 'granted_at', 'url', 'icon_70'] as const;
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/get-user.ts b/packages/pieces/community/reddit/src/lib/actions/ai/get-user.ts
new file mode 100644
index 00000000000..edff64c0027
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/get-user.ts
@@ -0,0 +1,32 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi, RedditThing } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditGetUserOutputSchema } from '../../output-schemas';
+
+export const redditGetUser = createAction({
+ auth: redditAuth,
+ name: 'reddit_get_user',
+ outputSchema: redditGetUserOutputSchema,
+ displayName: 'Get User',
+ description: 'Gets a Reddit user\'s public profile and karma.',
+ audience: 'ai',
+ classification: 'READ',
+ aiMetadata: {
+ description:
+ 'Returns a user\'s public profile: id, karma (post, comment, total), account creation time, and premium, moderator and verified flags. Fails with 404 for deleted or suspended accounts. Use List User Content for their posts and comments.',
+ idempotent: true,
+ },
+ props: {
+ username: redditAiProps.username({}),
+ },
+ async run({ auth, propsValue }) {
+ const thing = await redditApi.request<RedditThing>({
+ auth,
+ method: HttpMethod.GET,
+ path: `/user/${redditApi.cleanUsername({ value: propsValue.username })}/about`,
+ });
+ return redditApi.toThing({ thing });
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/get-wiki-page.ts b/packages/pieces/community/reddit/src/lib/actions/ai/get-wiki-page.ts
new file mode 100644
index 00000000000..80098463b4c
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/get-wiki-page.ts
@@ -0,0 +1,54 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi, RedditThing } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditGetWikiPageOutputSchema } from '../../output-schemas';
+
+export const redditGetWikiPage = createAction({
+ auth: redditAuth,
+ name: 'reddit_get_wiki_page',
+ outputSchema: redditGetWikiPageOutputSchema,
+ displayName: 'Get Wiki Page',
+ description: 'Gets the content of a subreddit wiki page.',
+ audience: 'ai',
+ classification: 'READ',
+ aiMetadata: {
+ description:
+ 'Returns a subreddit wiki page\'s markdown content and its latest revision (author, date, id). Page names come from List Wiki Pages; nested pages use slashes (e.g. "config/sidebar"). Needs the `wikiread` scope: older connections must reconnect.',
+ idempotent: true,
+ },
+ props: {
+ subreddit: redditAiProps.subreddit({ required: true }),
+ page: Property.ShortText({ displayName: 'Page', description: 'Wiki page name, e.g. "index" or "faq".', required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const subreddit = redditApi.cleanSubreddit({ value: propsValue.subreddit });
+ const page = propsValue.page.trim().replace(/^\/+|\/+$/g, '');
+ const response = await redditApi.request<WikiPageResponse>({
+ auth,
+ method: HttpMethod.GET,
+ path: `/r/${subreddit}/wiki/${page.split('/').map(encodeURIComponent).join('/')}`,
+ });
+ const data = response.data ?? {};
+ return {
+ subreddit,
+ page,
+ content_md: data.content_md ?? '',
+ revision_id: data.revision_id ?? null,
+ revision_date: data.revision_date ?? null,
+ revision_by: data.revision_by?.data['name'] ?? null,
+ may_revise: data.may_revise ?? null,
+ };
+ },
+});
+
+type WikiPageResponse = {
+ data?: {
+ content_md?: string;
+ revision_id?: string;
+ revision_date?: number;
+ revision_by?: RedditThing;
+ may_revise?: boolean;
+ };
+};
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/hide-post.ts b/packages/pieces/community/reddit/src/lib/actions/ai/hide-post.ts
new file mode 100644
index 00000000000..85a1336324c
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/hide-post.ts
@@ -0,0 +1,39 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditHidePostOutputSchema } from '../../output-schemas';
+
+export const redditHidePost = createAction({
+ auth: redditAuth,
+ name: 'reddit_hide_post',
+ outputSchema: redditHidePostOutputSchema,
+ displayName: 'Hide Posts',
+ description: 'Hides one or more posts from your listings.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Hides posts from your own front page and subreddit listings; nobody else is affected and Unhide Posts reverses it. Accepts comma-separated post ids with or without t3_. Needs the `report` scope: older connections must reconnect.',
+ idempotent: true,
+ },
+ props: {
+ post_ids: Property.ShortText({ displayName: 'Post IDs', description: 'Comma-separated post ids, e.g. "abc123,t3_def456".', required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const ids = toPostFullnames({ value: propsValue.post_ids });
+ await redditApi.request<unknown>({ auth, method: HttpMethod.POST, path: '/api/hide', form: { id: ids.join(',') } });
+ return { success: true, ids, hidden: true };
+ },
+});
+
+function toPostFullnames({ value }: { value: string }): string[] {
+ const ids = value
+ .split(',')
+ .filter((id) => id.trim() !== '')
+ .map((id) => redditApi.toFullname({ value: id, prefix: 't3_' }));
+ if (ids.length === 0) {
+ throw new Error('Provide at least one post id.');
+ }
+ return ids;
+}
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/list-duplicates.ts b/packages/pieces/community/reddit/src/lib/actions/ai/list-duplicates.ts
new file mode 100644
index 00000000000..5db97fb9d1b
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/list-duplicates.ts
@@ -0,0 +1,54 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi, RedditListing } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditListDuplicatesOutputSchema } from '../../output-schemas';
+
+export const redditListDuplicates = createAction({
+ auth: redditAuth,
+ name: 'reddit_list_duplicates',
+ outputSchema: redditListDuplicatesOutputSchema,
+ displayName: 'List Duplicates and Crossposts',
+ description: 'Lists other submissions of the same link, including crossposts of a post.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ 'Lists where else a post was shared: other submissions of the same link and crossposts of it. Set Crossposts Only to Yes for crossposts alone. Pages with the returned `after` cursor.',
+ idempotent: true,
+ },
+ props: {
+ post_id: Property.ShortText({ displayName: 'Post ID', description: 'Post id, e.g. "abc123" or "t3_abc123".', required: true }),
+ crossposts_only: redditAiProps.optionalBoolean({ displayName: 'Crossposts Only', description: 'Only return crossposts of this post.' }),
+ sort: Property.StaticDropdown({
+ displayName: 'Sort',
+ description: 'Sort order (default most comments).',
+ required: false,
+ options: {
+ options: [
+ { label: 'Most Comments', value: 'num_comments' },
+ { label: 'New', value: 'new' },
+ ],
+ },
+ }),
+ limit: redditAiProps.limit(),
+ after: redditAiProps.after(),
+ },
+ async run({ auth, propsValue }) {
+ const [postListing, duplicatesListing] = await redditApi.request<[RedditListing, RedditListing]>({
+ auth,
+ method: HttpMethod.GET,
+ path: `/duplicates/${redditApi.toBaseId({ value: propsValue.post_id })}`,
+ query: {
+ crossposts_only: propsValue.crossposts_only,
+ sort: propsValue.sort,
+ limit: redditAiProps.clampLimit({ value: propsValue.limit }),
+ after: propsValue.after,
+ },
+ });
+ const post = postListing.data.children[0];
+ const { items, ...page } = redditApi.toListing({ listing: duplicatesListing });
+ return { post: post ? redditApi.toThing({ thing: post }) : null, duplicates: items, ...page };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/list-messages.ts b/packages/pieces/community/reddit/src/lib/actions/ai/list-messages.ts
new file mode 100644
index 00000000000..3f4897701be
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/list-messages.ts
@@ -0,0 +1,51 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi, RedditListing } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditListMessagesOutputSchema } from '../../output-schemas';
+
+export const redditListMessages = createAction({
+ auth: redditAuth,
+ name: 'reddit_list_messages',
+ outputSchema: redditListMessagesOutputSchema,
+ displayName: 'List Messages',
+ description: 'Lists private messages, comment replies and mentions from your inbox.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ 'Lists items from one inbox folder: everything (inbox), unread, sent, private messages only, comment replies, post replies (selfreply) or username mentions. Items are messages (t4_) or comments (t1_); `new` is true when unread. Listing does not mark items read; use Mark Messages Read. Needs the `privatemessages` scope: older connections must reconnect.',
+ idempotent: true,
+ },
+ props: {
+ folder: Property.StaticDropdown({
+ displayName: 'Folder',
+ description: 'Inbox folder (default inbox).',
+ required: false,
+ options: {
+ options: [
+ { label: 'Inbox (all)', value: 'inbox' },
+ { label: 'Unread', value: 'unread' },
+ { label: 'Sent', value: 'sent' },
+ { label: 'Private Messages', value: 'messages' },
+ { label: 'Comment Replies', value: 'comments' },
+ { label: 'Post Replies', value: 'selfreply' },
+ { label: 'Username Mentions', value: 'mentions' },
+ ],
+ },
+ }),
+ limit: redditAiProps.limit(),
+ after: redditAiProps.after(),
+ },
+ async run({ auth, propsValue }) {
+ const listing = await redditApi.request<RedditListing>({
+ auth,
+ method: HttpMethod.GET,
+ path: `/message/${propsValue.folder ?? 'inbox'}`,
+ query: { mark: 'false', limit: redditAiProps.clampLimit({ value: propsValue.limit }), after: propsValue.after },
+ });
+ const { items, ...page } = redditApi.toListing({ listing });
+ return { messages: items, ...page };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/list-my-subreddits.ts b/packages/pieces/community/reddit/src/lib/actions/ai/list-my-subreddits.ts
new file mode 100644
index 00000000000..44fc3110407
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/list-my-subreddits.ts
@@ -0,0 +1,47 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi, RedditListing } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditListMySubredditsOutputSchema } from '../../output-schemas';
+
+export const redditListMySubreddits = createAction({
+ auth: redditAuth,
+ name: 'reddit_list_my_subreddits',
+ outputSchema: redditListMySubredditsOutputSchema,
+ displayName: 'List My Subreddits',
+ description: 'Lists the subreddits you subscribe to, moderate or contribute to.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ 'Lists subreddits tied to your account: the ones you joined (subscriber), moderate, or are an approved contributor in. Pages with the returned `after` cursor. Needs the `mysubreddits` scope: older connections must reconnect.',
+ idempotent: true,
+ },
+ props: {
+ where: Property.StaticDropdown({
+ displayName: 'Relationship',
+ description: 'Which subreddits to list (default subscriber).',
+ required: false,
+ options: {
+ options: [
+ { label: 'Subscribed', value: 'subscriber' },
+ { label: 'Moderated', value: 'moderator' },
+ { label: 'Approved Contributor', value: 'contributor' },
+ ],
+ },
+ }),
+ limit: redditAiProps.limit(),
+ after: redditAiProps.after(),
+ },
+ async run({ auth, propsValue }) {
+ const listing = await redditApi.request<RedditListing>({
+ auth,
+ method: HttpMethod.GET,
+ path: `/subreddits/mine/${propsValue.where ?? 'subscriber'}`,
+ query: { limit: redditAiProps.clampLimit({ value: propsValue.limit }), after: propsValue.after },
+ });
+ const { items, ...page } = redditApi.toListing({ listing });
+ return { subreddits: items, ...page };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/list-post-comments.ts b/packages/pieces/community/reddit/src/lib/actions/ai/list-post-comments.ts
new file mode 100644
index 00000000000..0bda869b788
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/list-post-comments.ts
@@ -0,0 +1,58 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi, RedditListing } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditListPostCommentsOutputSchema } from '../../output-schemas';
+
+export const redditListPostComments = createAction({
+ auth: redditAuth,
+ name: 'reddit_list_post_comments',
+ outputSchema: redditListPostCommentsOutputSchema,
+ displayName: 'List Post Comments',
+ description: 'Gets a post and its comment thread, flattened with depth and parent ids.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ 'Returns a post and its comments as a flat list, each with `depth` and `parent_id` to rebuild the thread. Large threads are truncated: `more` lists placeholders whose `children` ids can be loaded with Expand More Comments. Accepts the post id with or without t3_. Pass Comment ID to focus on one comment\'s subthread.',
+ idempotent: true,
+ },
+ props: {
+ post_id: Property.ShortText({ displayName: 'Post ID', description: 'Post id, e.g. "abc123" or "t3_abc123".', required: true }),
+ sort: Property.StaticDropdown({
+ displayName: 'Sort',
+ description: 'Comment sort order (default best).',
+ required: false,
+ options: {
+ options: [
+ { label: 'Best', value: 'confidence' },
+ { label: 'Top', value: 'top' },
+ { label: 'New', value: 'new' },
+ { label: 'Controversial', value: 'controversial' },
+ { label: 'Old', value: 'old' },
+ { label: 'Q&A', value: 'qa' },
+ ],
+ },
+ }),
+ comment_id: Property.ShortText({ displayName: 'Comment ID', description: 'Only return this comment and its replies (id without t1_).', required: false }),
+ depth: Property.Number({ displayName: 'Depth', description: 'Maximum reply depth to include.', required: false }),
+ limit: Property.Number({ displayName: 'Limit', description: 'Maximum number of comments to load.', required: false }),
+ },
+ async run({ auth, propsValue }) {
+ const [postListing, commentListing] = await redditApi.request<[RedditListing, RedditListing]>({
+ auth,
+ method: HttpMethod.GET,
+ path: `/comments/${redditApi.toBaseId({ value: propsValue.post_id })}`,
+ query: {
+ sort: propsValue.sort,
+ comment: propsValue.comment_id ? redditApi.toBaseId({ value: propsValue.comment_id }) : undefined,
+ depth: propsValue.depth,
+ limit: redditAiProps.clampLimit({ value: propsValue.limit }),
+ },
+ });
+ const post = postListing.data.children[0];
+ const { comments, more } = redditApi.flattenCommentTree({ children: commentListing.data.children });
+ return { post: post ? redditApi.toThing({ thing: post }) : null, comments, count: comments.length, more };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/list-post-flairs.ts b/packages/pieces/community/reddit/src/lib/actions/ai/list-post-flairs.ts
new file mode 100644
index 00000000000..5d2441634f2
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/list-post-flairs.ts
@@ -0,0 +1,35 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditListPostFlairsOutputSchema } from '../../output-schemas';
+
+export const redditListPostFlairs = createAction({
+ auth: redditAuth,
+ name: 'reddit_list_post_flairs',
+ outputSchema: redditListPostFlairsOutputSchema,
+ displayName: 'List Post Flairs',
+ description: 'Lists the post flair templates available in a subreddit.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ 'Lists a subreddit\'s post flair templates. Each `id` is the Flair ID for Create Post, Crosspost and Set Post Flair; `text_editable` tells whether custom text is allowed and `mod_only` whether only moderators can use it. Fails with 403 when the subreddit does not let users pick flair.',
+ idempotent: true,
+ },
+ props: {
+ subreddit: redditAiProps.subreddit({ required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const response = await redditApi.request<Record<string, unknown>[]>({
+ auth,
+ method: HttpMethod.GET,
+ path: `/r/${redditApi.cleanSubreddit({ value: propsValue.subreddit })}/api/link_flair_v2`,
+ });
+ const flairs = response.map((flair) => Object.fromEntries(FLAIR_FIELDS.map((key) => [key, flair[key] ?? null])));
+ return { flairs, count: flairs.length };
+ },
+});
+
+const FLAIR_FIELDS = ['id', 'text', 'text_editable', 'type', 'mod_only', 'allowable_content', 'max_emojis', 'background_color', 'text_color', 'css_class'] as const;
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/list-posts.ts b/packages/pieces/community/reddit/src/lib/actions/ai/list-posts.ts
new file mode 100644
index 00000000000..049b1abb5e4
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/list-posts.ts
@@ -0,0 +1,57 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi, RedditListing } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditListPostsOutputSchema } from '../../output-schemas';
+
+export const redditListPosts = createAction({
+ auth: redditAuth,
+ name: 'reddit_list_posts',
+ outputSchema: redditListPostsOutputSchema,
+ displayName: 'List Posts',
+ description: 'Lists posts from a subreddit or the front page, sorted by hot, new, top, rising, controversial or best.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ 'Lists posts from one subreddit, or from the front page when no subreddit is given, in a chosen sort order. Use "top" or "controversial" with a time range for the best or most divisive posts of a period; "best" works only on the front page. Pages with the returned `after` cursor. Use Search Posts instead to find posts by keyword.',
+ idempotent: true,
+ },
+ props: {
+ subreddit: redditAiProps.subreddit({ required: false, description: 'Subreddit name without r/. Leave empty for the front page.' }),
+ sort: Property.StaticDropdown({
+ displayName: 'Sort',
+ description: 'Sort order (default hot).',
+ required: false,
+ options: {
+ options: [
+ { label: 'Hot', value: 'hot' },
+ { label: 'New', value: 'new' },
+ { label: 'Top', value: 'top' },
+ { label: 'Rising', value: 'rising' },
+ { label: 'Controversial', value: 'controversial' },
+ { label: 'Best (front page only)', value: 'best' },
+ ],
+ },
+ }),
+ time: redditAiProps.timeFilter(),
+ limit: redditAiProps.limit(),
+ after: redditAiProps.after(),
+ },
+ async run({ auth, propsValue }) {
+ const sort = propsValue.sort ?? 'hot';
+ const subreddit = propsValue.subreddit ? redditApi.cleanSubreddit({ value: propsValue.subreddit }) : undefined;
+ if (subreddit && sort === 'best') {
+ throw new Error('The "best" sort is only available on the front page; leave Subreddit empty or pick another sort.');
+ }
+ const listing = await redditApi.request<RedditListing>({
+ auth,
+ method: HttpMethod.GET,
+ path: subreddit ? `/r/${subreddit}/${sort}` : `/${sort}`,
+ query: { t: propsValue.time, limit: redditAiProps.clampLimit({ value: propsValue.limit }), after: propsValue.after },
+ });
+ const { items, ...page } = redditApi.toListing({ listing });
+ return { posts: items, ...page };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/list-saved-categories.ts b/packages/pieces/community/reddit/src/lib/actions/ai/list-saved-categories.ts
new file mode 100644
index 00000000000..12ebc3a0691
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/list-saved-categories.ts
@@ -0,0 +1,31 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, tryCatch } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditListSavedCategoriesOutputSchema } from '../../output-schemas';
+
+export const redditListSavedCategories = createAction({
+ auth: redditAuth,
+ name: 'reddit_list_saved_categories',
+ outputSchema: redditListSavedCategoriesOutputSchema,
+ displayName: 'List Saved Categories',
+ description: 'Lists the categories you use for saved items.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ 'Lists your saved-item categories, for the Category input of Save Post or Comment. Categories are a Reddit Premium feature, so the list is empty for other accounts. Needs the `save` scope: older connections must reconnect.',
+ idempotent: true,
+ },
+ props: {},
+ async run({ auth }) {
+ const { data: response, error } = await tryCatch(() =>
+ redditApi.request<{ categories?: unknown[] }>({ auth, method: HttpMethod.GET, path: '/api/saved_categories' }),
+ );
+ if (error && !error.message.includes('404')) {
+ throw error;
+ }
+ const categories = response?.categories ?? [];
+ return { categories, count: categories.length };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/list-subreddit-comments.ts b/packages/pieces/community/reddit/src/lib/actions/ai/list-subreddit-comments.ts
new file mode 100644
index 00000000000..8944bf9d52b
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/list-subreddit-comments.ts
@@ -0,0 +1,36 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi, RedditListing } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditListSubredditCommentsOutputSchema } from '../../output-schemas';
+
+export const redditListSubredditComments = createAction({
+ auth: redditAuth,
+ name: 'reddit_list_subreddit_comments',
+ outputSchema: redditListSubredditCommentsOutputSchema,
+ displayName: 'List Subreddit Comments',
+ description: 'Lists the newest comments across all posts in a subreddit.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ 'Lists the most recent comments posted anywhere in a subreddit, newest first, each with its post (`link_id`, `link_title`). Use to monitor activity; use List Post Comments for one post\'s thread. Pages with the returned `after` cursor.',
+ idempotent: true,
+ },
+ props: {
+ subreddit: redditAiProps.subreddit({ required: true }),
+ limit: redditAiProps.limit(),
+ after: redditAiProps.after(),
+ },
+ async run({ auth, propsValue }) {
+ const listing = await redditApi.request<RedditListing>({
+ auth,
+ method: HttpMethod.GET,
+ path: `/r/${redditApi.cleanSubreddit({ value: propsValue.subreddit })}/comments`,
+ query: { limit: redditAiProps.clampLimit({ value: propsValue.limit }), after: propsValue.after },
+ });
+ const { items, ...page } = redditApi.toListing({ listing });
+ return { comments: items, ...page };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/list-subreddit-moderators.ts b/packages/pieces/community/reddit/src/lib/actions/ai/list-subreddit-moderators.ts
new file mode 100644
index 00000000000..5ed32627664
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/list-subreddit-moderators.ts
@@ -0,0 +1,44 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditListSubredditModeratorsOutputSchema } from '../../output-schemas';
+
+export const redditListSubredditModerators = createAction({
+ auth: redditAuth,
+ name: 'reddit_list_subreddit_moderators',
+ outputSchema: redditListSubredditModeratorsOutputSchema,
+ displayName: 'List Subreddit Moderators',
+ description: 'Lists a subreddit\'s moderators.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ 'Lists the moderators of a subreddit with their permissions and the date they were added. To contact them, use Send Private Message with To set to "/r/<subreddit>".',
+ idempotent: true,
+ },
+ props: {
+ subreddit: redditAiProps.subreddit({ required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const response = await redditApi.request<ModeratorsResponse>({
+ auth,
+ method: HttpMethod.GET,
+ path: `/r/${redditApi.cleanSubreddit({ value: propsValue.subreddit })}/about/moderators`,
+ });
+ const moderators = (response.data?.children ?? []).map((moderator) => ({
+ name: moderator.name ?? null,
+ id: moderator.id ?? null,
+ mod_permissions: moderator.mod_permissions ?? [],
+ date: moderator.date ?? null,
+ }));
+ return { moderators, count: moderators.length };
+ },
+});
+
+type ModeratorsResponse = {
+ data?: {
+ children?: { name?: string; id?: string; mod_permissions?: string[]; date?: number }[];
+ };
+};
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/list-subreddits.ts b/packages/pieces/community/reddit/src/lib/actions/ai/list-subreddits.ts
new file mode 100644
index 00000000000..142130994d4
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/list-subreddits.ts
@@ -0,0 +1,47 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi, RedditListing } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditListSubredditsOutputSchema } from '../../output-schemas';
+
+export const redditListSubreddits = createAction({
+ auth: redditAuth,
+ name: 'reddit_list_subreddits',
+ outputSchema: redditListSubredditsOutputSchema,
+ displayName: 'List Subreddits',
+ description: 'Lists popular, new or default subreddits.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ 'Lists subreddits Reddit-wide: the most popular, the newest, or the defaults. Use Search Subreddits to find by topic and List My Subreddits for the ones you joined. Pages with the returned `after` cursor.',
+ idempotent: true,
+ },
+ props: {
+ where: Property.StaticDropdown({
+ displayName: 'Type',
+ description: 'Which subreddits to list (default popular).',
+ required: false,
+ options: {
+ options: [
+ { label: 'Popular', value: 'popular' },
+ { label: 'New', value: 'new' },
+ { label: 'Default', value: 'default' },
+ ],
+ },
+ }),
+ limit: redditAiProps.limit(),
+ after: redditAiProps.after(),
+ },
+ async run({ auth, propsValue }) {
+ const listing = await redditApi.request<RedditListing>({
+ auth,
+ method: HttpMethod.GET,
+ path: `/subreddits/${propsValue.where ?? 'popular'}`,
+ query: { limit: redditAiProps.clampLimit({ value: propsValue.limit }), after: propsValue.after },
+ });
+ const { items, ...page } = redditApi.toListing({ listing });
+ return { subreddits: items, ...page };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/list-user-content.ts b/packages/pieces/community/reddit/src/lib/actions/ai/list-user-content.ts
new file mode 100644
index 00000000000..425be6a5b5f
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/list-user-content.ts
@@ -0,0 +1,72 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi, RedditListing } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditListUserContentOutputSchema } from '../../output-schemas';
+
+export const redditListUserContent = createAction({
+ auth: redditAuth,
+ name: 'reddit_list_user_content',
+ outputSchema: redditListUserContentOutputSchema,
+ displayName: 'List User Content',
+ description: 'Lists a user\'s posts and comments, or your own saved, upvoted or hidden items.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ 'Lists a user\'s activity: everything (overview), posts (submitted) or comments, sorted. For your own account (username from Get My Account) it can also list saved, upvoted, downvoted, hidden and gilded items; those fail with 403 for other users. Items are posts (t3) or comments (t1). Pages with the returned `after` cursor.',
+ idempotent: true,
+ },
+ props: {
+ username: redditAiProps.username({}),
+ where: Property.StaticDropdown({
+ displayName: 'Content',
+ description: 'What to list (default overview).',
+ required: false,
+ options: {
+ options: [
+ { label: 'Overview (posts and comments)', value: 'overview' },
+ { label: 'Posts', value: 'submitted' },
+ { label: 'Comments', value: 'comments' },
+ { label: 'Saved (own account)', value: 'saved' },
+ { label: 'Upvoted (own account)', value: 'upvoted' },
+ { label: 'Downvoted (own account)', value: 'downvoted' },
+ { label: 'Hidden (own account)', value: 'hidden' },
+ { label: 'Gilded', value: 'gilded' },
+ ],
+ },
+ }),
+ sort: Property.StaticDropdown({
+ displayName: 'Sort',
+ description: 'Sort order (default new).',
+ required: false,
+ options: {
+ options: [
+ { label: 'New', value: 'new' },
+ { label: 'Hot', value: 'hot' },
+ { label: 'Top', value: 'top' },
+ { label: 'Controversial', value: 'controversial' },
+ ],
+ },
+ }),
+ time: redditAiProps.timeFilter(),
+ limit: redditAiProps.limit(),
+ after: redditAiProps.after(),
+ },
+ async run({ auth, propsValue }) {
+ const listing = await redditApi.request<RedditListing>({
+ auth,
+ method: HttpMethod.GET,
+ path: `/user/${redditApi.cleanUsername({ value: propsValue.username })}/${propsValue.where ?? 'overview'}`,
+ query: {
+ sort: propsValue.sort,
+ t: propsValue.time,
+ limit: redditAiProps.clampLimit({ value: propsValue.limit }),
+ after: propsValue.after,
+ },
+ });
+ const { items, ...page } = redditApi.toListing({ listing });
+ return { items, ...page };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/list-user-flairs.ts b/packages/pieces/community/reddit/src/lib/actions/ai/list-user-flairs.ts
new file mode 100644
index 00000000000..5b9448ef576
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/list-user-flairs.ts
@@ -0,0 +1,35 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditListUserFlairsOutputSchema } from '../../output-schemas';
+
+export const redditListUserFlairs = createAction({
+ auth: redditAuth,
+ name: 'reddit_list_user_flairs',
+ outputSchema: redditListUserFlairsOutputSchema,
+ displayName: 'List User Flairs',
+ description: 'Lists the user flair templates available in a subreddit.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ 'Lists a subreddit\'s user flair templates (the badge shown next to usernames there), with id, text, whether the text is editable and whether it is moderator-only. Fails with 403 when the subreddit does not let users pick flair.',
+ idempotent: true,
+ },
+ props: {
+ subreddit: redditAiProps.subreddit({ required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const response = await redditApi.request<Record<string, unknown>[]>({
+ auth,
+ method: HttpMethod.GET,
+ path: `/r/${redditApi.cleanSubreddit({ value: propsValue.subreddit })}/api/user_flair_v2`,
+ });
+ const flairs = response.map((flair) => Object.fromEntries(FLAIR_FIELDS.map((key) => [key, flair[key] ?? null])));
+ return { flairs, count: flairs.length };
+ },
+});
+
+const FLAIR_FIELDS = ['id', 'text', 'text_editable', 'type', 'mod_only', 'allowable_content', 'max_emojis', 'background_color', 'text_color', 'css_class'] as const;
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/list-wiki-pages.ts b/packages/pieces/community/reddit/src/lib/actions/ai/list-wiki-pages.ts
new file mode 100644
index 00000000000..81c5c39b974
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/list-wiki-pages.ts
@@ -0,0 +1,33 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditListWikiPagesOutputSchema } from '../../output-schemas';
+
+export const redditListWikiPages = createAction({
+ auth: redditAuth,
+ name: 'reddit_list_wiki_pages',
+ outputSchema: redditListWikiPagesOutputSchema,
+ displayName: 'List Wiki Pages',
+ description: 'Lists the wiki pages of a subreddit.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ 'Lists the names of a subreddit\'s wiki pages (e.g. "index", "faq"); read one with Get Wiki Page. Fails with 403 or 404 when the wiki is disabled or private. Needs the `wikiread` scope: older connections must reconnect.',
+ idempotent: true,
+ },
+ props: {
+ subreddit: redditAiProps.subreddit({ required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const response = await redditApi.request<{ data?: string[] }>({
+ auth,
+ method: HttpMethod.GET,
+ path: `/r/${redditApi.cleanSubreddit({ value: propsValue.subreddit })}/wiki/pages`,
+ });
+ const pages = response.data ?? [];
+ return { pages, count: pages.length };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/mark-all-messages-read.ts b/packages/pieces/community/reddit/src/lib/actions/ai/mark-all-messages-read.ts
new file mode 100644
index 00000000000..c25b2fa4933
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/mark-all-messages-read.ts
@@ -0,0 +1,25 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditMarkAllMessagesReadOutputSchema } from '../../output-schemas';
+
+export const redditMarkAllMessagesRead = createAction({
+ auth: redditAuth,
+ name: 'reddit_mark_all_messages_read',
+ outputSchema: redditMarkAllMessagesReadOutputSchema,
+ displayName: 'Mark All Messages Read',
+ description: 'Marks every item in your inbox as read.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Marks every unread inbox item (messages, replies, mentions) as read. Reddit processes it asynchronously, so List Messages may show unread items for a few seconds. Needs the `privatemessages` scope: older connections must reconnect.',
+ idempotent: true,
+ },
+ props: {},
+ async run({ auth }) {
+ await redditApi.request<unknown>({ auth, method: HttpMethod.POST, path: '/api/read_all_messages', form: {} });
+ return { success: true };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/mark-message-read.ts b/packages/pieces/community/reddit/src/lib/actions/ai/mark-message-read.ts
new file mode 100644
index 00000000000..a3d93118e65
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/mark-message-read.ts
@@ -0,0 +1,34 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditMarkMessageReadOutputSchema } from '../../output-schemas';
+
+export const redditMarkMessageRead = createAction({
+ auth: redditAuth,
+ name: 'reddit_mark_message_read',
+ outputSchema: redditMarkMessageReadOutputSchema,
+ displayName: 'Mark Messages Read',
+ description: 'Marks inbox items as read.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Marks inbox items as read: private messages (t4_) or comment replies and mentions (t1_), comma-separated with their prefixes, from List Messages. Use Mark All Messages Read to clear the whole inbox. Needs the `privatemessages` scope: older connections must reconnect.',
+ idempotent: true,
+ },
+ props: {
+ ids: Property.ShortText({ displayName: 'Fullnames', description: 'Comma-separated fullnames, e.g. "t4_abc123,t1_def456".', required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const ids = propsValue.ids
+ .split(',')
+ .filter((id) => id.trim() !== '')
+ .map((id) => redditApi.requireFullname({ value: id, label: 'Each id' }));
+ if (ids.length === 0) {
+ throw new Error('Provide at least one fullname.');
+ }
+ await redditApi.request<unknown>({ auth, method: HttpMethod.POST, path: '/api/read_message', form: { id: ids.join(',') } });
+ return { success: true, ids, read: true };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/report-content.ts b/packages/pieces/community/reddit/src/lib/actions/ai/report-content.ts
new file mode 100644
index 00000000000..0f14de88645
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/report-content.ts
@@ -0,0 +1,37 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditReportContentOutputSchema } from '../../output-schemas';
+
+export const redditReportContent = createAction({
+ auth: redditAuth,
+ name: 'reddit_report_content',
+ outputSchema: redditReportContentOutputSchema,
+ displayName: 'Report Post, Comment or Message',
+ description: 'Reports a post, comment or message to the subreddit moderators.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Files a report on a post (t3_), comment (t1_) or private message (t4_) for the subreddit\'s moderators, with a reason (often one of the subreddit\'s rule names from Get Subreddit Rules). Only report when a human asked to. Not idempotent: each call files a report. Needs the `report` scope: older connections must reconnect.',
+ idempotent: false,
+ },
+ props: {
+ thing_id: Property.ShortText({ displayName: 'Fullname', description: 'Fullname of the item to report, e.g. "t3_abc123".', required: true }),
+ reason: Property.ShortText({ displayName: 'Reason', description: 'Report reason, max 100 characters (e.g. a subreddit rule name).', required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const thingId = redditApi.requireFullname({ value: propsValue.thing_id, label: 'Fullname' });
+ if (propsValue.reason.length > 100) {
+ throw new Error('Reason must be at most 100 characters.');
+ }
+ await redditApi.request<unknown>({
+ auth,
+ method: HttpMethod.POST,
+ path: '/api/report',
+ form: { api_type: 'json', thing_id: thingId, reason: propsValue.reason },
+ });
+ return { success: true, id: thingId, reason: propsValue.reason };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/save-content.ts b/packages/pieces/community/reddit/src/lib/actions/ai/save-content.ts
new file mode 100644
index 00000000000..d9db13e15b0
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/save-content.ts
@@ -0,0 +1,29 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditSaveContentOutputSchema } from '../../output-schemas';
+
+export const redditSaveContent = createAction({
+ auth: redditAuth,
+ name: 'reddit_save_content',
+ outputSchema: redditSaveContentOutputSchema,
+ displayName: 'Save Post or Comment',
+ description: 'Saves a post or comment to your saved items.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Saves a post (t3_) or comment (t1_) to your account\'s saved items; saving twice is harmless. Category only applies to Reddit Premium accounts (see List Saved Categories). Read saved items with List User Content (where = saved). Needs the `save` scope: older connections must reconnect.',
+ idempotent: true,
+ },
+ props: {
+ thing_id: Property.ShortText({ displayName: 'Fullname', description: 'Fullname of the post or comment, e.g. "t3_abc123".', required: true }),
+ category: Property.ShortText({ displayName: 'Category', description: 'Saved category (Reddit Premium only).', required: false }),
+ },
+ async run({ auth, propsValue }) {
+ const id = redditApi.requireFullname({ value: propsValue.thing_id, label: 'Fullname' });
+ await redditApi.request<unknown>({ auth, method: HttpMethod.POST, path: '/api/save', form: { id, category: propsValue.category } });
+ return { success: true, id, saved: true };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/search-posts.ts b/packages/pieces/community/reddit/src/lib/actions/ai/search-posts.ts
new file mode 100644
index 00000000000..a7166d1d947
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/search-posts.ts
@@ -0,0 +1,65 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi, RedditListing } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditListPostsOutputSchema } from '../../output-schemas';
+
+export const redditSearchPosts = createAction({
+ auth: redditAuth,
+ name: 'reddit_search_posts',
+ outputSchema: redditListPostsOutputSchema,
+ displayName: 'Search Posts',
+ description: 'Searches Reddit posts by keyword, across Reddit or within one subreddit.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ 'Searches posts by keyword across all of Reddit, or only within one subreddit when given. Supports Reddit search syntax (e.g. author:name, title:word, flair:name). Pages with the returned `after` cursor. Use Search Subreddits to find communities instead of posts.',
+ idempotent: true,
+ },
+ props: {
+ query: Property.ShortText({
+ displayName: 'Query',
+ description: 'Search terms (Reddit search syntax supported).',
+ required: true,
+ }),
+ subreddit: redditAiProps.subreddit({ required: false, description: 'Limit the search to this subreddit (without r/).' }),
+ sort: Property.StaticDropdown({
+ displayName: 'Sort',
+ description: 'Sort order (default relevance).',
+ required: false,
+ options: {
+ options: [
+ { label: 'Relevance', value: 'relevance' },
+ { label: 'Hot', value: 'hot' },
+ { label: 'Top', value: 'top' },
+ { label: 'New', value: 'new' },
+ { label: 'Most Comments', value: 'comments' },
+ ],
+ },
+ }),
+ time: redditAiProps.timeFilter(),
+ limit: redditAiProps.limit(),
+ after: redditAiProps.after(),
+ },
+ async run({ auth, propsValue }) {
+ const subreddit = propsValue.subreddit ? redditApi.cleanSubreddit({ value: propsValue.subreddit }) : undefined;
+ const listing = await redditApi.request<RedditListing>({
+ auth,
+ method: HttpMethod.GET,
+ path: subreddit ? `/r/${subreddit}/search` : '/search',
+ query: {
+ q: propsValue.query,
+ type: 'link',
+ restrict_sr: subreddit ? 'true' : undefined,
+ sort: propsValue.sort,
+ t: propsValue.time,
+ limit: redditAiProps.clampLimit({ value: propsValue.limit }),
+ after: propsValue.after,
+ },
+ });
+ const { items, ...page } = redditApi.toListing({ listing });
+ return { posts: items, ...page };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/search-subreddits.ts b/packages/pieces/community/reddit/src/lib/actions/ai/search-subreddits.ts
new file mode 100644
index 00000000000..b51b6e83652
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/search-subreddits.ts
@@ -0,0 +1,47 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi, RedditListing } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditListSubredditsOutputSchema } from '../../output-schemas';
+
+export const redditSearchSubreddits = createAction({
+ auth: redditAuth,
+ name: 'reddit_search_subreddits',
+ outputSchema: redditListSubredditsOutputSchema,
+ displayName: 'Search Subreddits',
+ description: 'Searches subreddits by name, title and description.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ 'Finds subreddits matching a topic or keyword in their name, title or description. Returns each subreddit\'s `display_name` (the value other actions take as Subreddit) and subscriber count. Pages with the returned `after` cursor.',
+ idempotent: true,
+ },
+ props: {
+ query: Property.ShortText({ displayName: 'Query', description: 'Topic or keyword to search for.', required: true }),
+ sort: Property.StaticDropdown({
+ displayName: 'Sort',
+ description: 'Sort order (default relevance).',
+ required: false,
+ options: {
+ options: [
+ { label: 'Relevance', value: 'relevance' },
+ { label: 'Activity', value: 'activity' },
+ ],
+ },
+ }),
+ limit: redditAiProps.limit(),
+ after: redditAiProps.after(),
+ },
+ async run({ auth, propsValue }) {
+ const listing = await redditApi.request<RedditListing>({
+ auth,
+ method: HttpMethod.GET,
+ path: '/subreddits/search',
+ query: { q: propsValue.query, sort: propsValue.sort, limit: redditAiProps.clampLimit({ value: propsValue.limit }), after: propsValue.after },
+ });
+ const { items, ...page } = redditApi.toListing({ listing });
+ return { subreddits: items, ...page };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/search-users.ts b/packages/pieces/community/reddit/src/lib/actions/ai/search-users.ts
new file mode 100644
index 00000000000..35eaadf3f22
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/search-users.ts
@@ -0,0 +1,36 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi, RedditListing } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditSearchUsersOutputSchema } from '../../output-schemas';
+
+export const redditSearchUsers = createAction({
+ auth: redditAuth,
+ name: 'reddit_search_users',
+ outputSchema: redditSearchUsersOutputSchema,
+ displayName: 'Search Users',
+ description: 'Searches Reddit users by name.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ 'Finds Reddit accounts whose username or profile matches a query, returning each `name` (the Username for Get User and List User Content) with karma. Pages with the returned `after` cursor.',
+ idempotent: true,
+ },
+ props: {
+ query: Property.ShortText({ displayName: 'Query', description: 'Name or keyword to search for.', required: true }),
+ limit: redditAiProps.limit(),
+ after: redditAiProps.after(),
+ },
+ async run({ auth, propsValue }) {
+ const listing = await redditApi.request<RedditListing>({
+ auth,
+ method: HttpMethod.GET,
+ path: '/users/search',
+ query: { q: propsValue.query, limit: redditAiProps.clampLimit({ value: propsValue.limit }), after: propsValue.after },
+ });
+ const { items, ...page } = redditApi.toListing({ listing });
+ return { users: items, ...page };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/send-message.ts b/packages/pieces/community/reddit/src/lib/actions/ai/send-message.ts
new file mode 100644
index 00000000000..d027eddb668
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/send-message.ts
@@ -0,0 +1,35 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditSendMessageOutputSchema } from '../../output-schemas';
+
+export const redditSendMessage = createAction({
+ auth: redditAuth,
+ name: 'reddit_send_message',
+ outputSchema: redditSendMessageOutputSchema,
+ displayName: 'Send Private Message',
+ description: 'Sends a private message to a Reddit user or a subreddit\'s moderators.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Sends a new private message to a user, or to a subreddit\'s moderators when To is "/r/<subreddit>". To reply within an existing conversation, use Create Comment with the message\'s t4_ fullname. Reddit does not return the new message id; find it with List Messages (folder = sent). Not idempotent. Needs the `privatemessages` scope: older connections must reconnect.',
+ idempotent: false,
+ },
+ props: {
+ to: Property.ShortText({ displayName: 'To', description: 'Recipient username without u/, or "/r/<subreddit>" for its moderators.', required: true }),
+ subject: Property.ShortText({ displayName: 'Subject', description: 'Message subject (max 100 characters).', required: true }),
+ text: Property.LongText({ displayName: 'Text', description: 'Markdown message body.', required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const to = propsValue.to.trim().startsWith('/r/') ? propsValue.to.trim() : redditApi.cleanUsername({ value: propsValue.to });
+ await redditApi.request<unknown>({
+ auth,
+ method: HttpMethod.POST,
+ path: '/api/compose',
+ form: { api_type: 'json', to, subject: propsValue.subject, text: propsValue.text },
+ });
+ return { success: true, to, subject: propsValue.subject };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/set-inbox-replies.ts b/packages/pieces/community/reddit/src/lib/actions/ai/set-inbox-replies.ts
new file mode 100644
index 00000000000..c5e9b97e881
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/set-inbox-replies.ts
@@ -0,0 +1,44 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditSetInboxRepliesOutputSchema } from '../../output-schemas';
+
+export const redditSetInboxReplies = createAction({
+ auth: redditAuth,
+ name: 'reddit_set_inbox_replies',
+ outputSchema: redditSetInboxRepliesOutputSchema,
+ displayName: 'Set Inbox Replies',
+ description: 'Turns inbox notifications for replies to one of your posts or comments on or off.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Enables or disables inbox notifications for replies to a post (t3_) or comment (t1_) you authored. The id must carry its type prefix.',
+ idempotent: true,
+ },
+ props: {
+ thing_id: Property.ShortText({ displayName: 'Fullname', description: 'Fullname of your post or comment, e.g. "t3_abc123".', required: true }),
+ enabled: Property.StaticDropdown({
+ displayName: 'Inbox Replies',
+ description: 'Whether replies should notify your inbox.',
+ required: true,
+ options: {
+ options: [
+ { label: 'Enabled', value: 'true' },
+ { label: 'Disabled', value: 'false' },
+ ],
+ },
+ }),
+ },
+ async run({ auth, propsValue }) {
+ const id = redditApi.requireFullname({ value: propsValue.thing_id, label: 'Fullname' });
+ await redditApi.request<unknown>({
+ auth,
+ method: HttpMethod.POST,
+ path: '/api/sendreplies',
+ form: { id, state: propsValue.enabled },
+ });
+ return { success: true, id, inbox_replies: propsValue.enabled === 'true' };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/set-post-flair.ts b/packages/pieces/community/reddit/src/lib/actions/ai/set-post-flair.ts
new file mode 100644
index 00000000000..6b32689a545
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/set-post-flair.ts
@@ -0,0 +1,47 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditSetPostFlairOutputSchema } from '../../output-schemas';
+
+export const redditSetPostFlair = createAction({
+ auth: redditAuth,
+ name: 'reddit_set_post_flair',
+ outputSchema: redditSetPostFlairOutputSchema,
+ displayName: 'Set Post Flair',
+ description: 'Sets or clears the flair on one of your posts.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Sets the flair on a post you authored (or any post if you moderate the subreddit). Flair Template ID comes from List Post Flairs; Text overrides the label when the template is editable. Leaving both empty clears the flair.',
+ idempotent: true,
+ },
+ props: {
+ subreddit: redditAiProps.subreddit({ required: true, description: 'Subreddit the post is in, without r/.' }),
+ post_id: Property.ShortText({ displayName: 'Post ID', description: 'Post id, e.g. "abc123" or "t3_abc123".', required: true }),
+ flair_template_id: Property.ShortText({ displayName: 'Flair Template ID', description: 'Flair template id from List Post Flairs.', required: false }),
+ text: Property.ShortText({ displayName: 'Text', description: 'Flair label (max 64 characters), for editable templates.', required: false }),
+ },
+ async run({ auth, propsValue }) {
+ const link = redditApi.toFullname({ value: propsValue.post_id, prefix: 't3_' });
+ await redditApi.request<unknown>({
+ auth,
+ method: HttpMethod.POST,
+ path: `/r/${redditApi.cleanSubreddit({ value: propsValue.subreddit })}/api/selectflair`,
+ form: {
+ api_type: 'json',
+ link,
+ flair_template_id: propsValue.flair_template_id,
+ text: propsValue.text,
+ },
+ });
+ return {
+ success: true,
+ post: link,
+ flair_template_id: propsValue.flair_template_id ?? null,
+ text: propsValue.text ?? null,
+ };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/subscribe-subreddit.ts b/packages/pieces/community/reddit/src/lib/actions/ai/subscribe-subreddit.ts
new file mode 100644
index 00000000000..0bbb8fb1edb
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/subscribe-subreddit.ts
@@ -0,0 +1,34 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditSubscribeSubredditOutputSchema } from '../../output-schemas';
+
+export const redditSubscribeSubreddit = createAction({
+ auth: redditAuth,
+ name: 'reddit_subscribe_subreddit',
+ outputSchema: redditSubscribeSubredditOutputSchema,
+ displayName: 'Join Subreddit',
+ description: 'Subscribes your account to a subreddit.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Subscribes (joins) your account to a subreddit; joining one you already follow is harmless. Undo with Leave Subreddit. Needs the `subscribe` scope: older connections must reconnect.',
+ idempotent: true,
+ },
+ props: {
+ subreddit: redditAiProps.subreddit({ required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const subreddit = redditApi.cleanSubreddit({ value: propsValue.subreddit });
+ await redditApi.request<unknown>({
+ auth,
+ method: HttpMethod.POST,
+ path: '/api/subscribe',
+ form: { action: 'sub', sr_name: subreddit, skip_initial_defaults: 'true' },
+ });
+ return { success: true, subreddit, subscribed: true };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/unhide-post.ts b/packages/pieces/community/reddit/src/lib/actions/ai/unhide-post.ts
new file mode 100644
index 00000000000..b59a81e62a1
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/unhide-post.ts
@@ -0,0 +1,34 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditHidePostOutputSchema } from '../../output-schemas';
+
+export const redditUnhidePost = createAction({
+ auth: redditAuth,
+ name: 'reddit_unhide_post',
+ outputSchema: redditHidePostOutputSchema,
+ displayName: 'Unhide Posts',
+ description: 'Unhides one or more posts you previously hid.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Restores posts hidden with Hide Posts to your listings. Accepts comma-separated post ids with or without t3_; List User Content (where = hidden) lists hidden posts. Needs the `report` scope: older connections must reconnect.',
+ idempotent: true,
+ },
+ props: {
+ post_ids: Property.ShortText({ displayName: 'Post IDs', description: 'Comma-separated post ids, e.g. "abc123,t3_def456".', required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const ids = propsValue.post_ids
+ .split(',')
+ .filter((id) => id.trim() !== '')
+ .map((id) => redditApi.toFullname({ value: id, prefix: 't3_' }));
+ if (ids.length === 0) {
+ throw new Error('Provide at least one post id.');
+ }
+ await redditApi.request<unknown>({ auth, method: HttpMethod.POST, path: '/api/unhide', form: { id: ids.join(',') } });
+ return { success: true, ids, hidden: false };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/unsave-content.ts b/packages/pieces/community/reddit/src/lib/actions/ai/unsave-content.ts
new file mode 100644
index 00000000000..b071fac1763
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/unsave-content.ts
@@ -0,0 +1,28 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction, Property } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditSaveContentOutputSchema } from '../../output-schemas';
+
+export const redditUnsaveContent = createAction({
+ auth: redditAuth,
+ name: 'reddit_unsave_content',
+ outputSchema: redditSaveContentOutputSchema,
+ displayName: 'Unsave Post or Comment',
+ description: 'Removes a post or comment from your saved items.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Removes a post (t3_) or comment (t1_) from your saved items; harmless when it is not saved. Needs the `save` scope: older connections must reconnect.',
+ idempotent: true,
+ },
+ props: {
+ thing_id: Property.ShortText({ displayName: 'Fullname', description: 'Fullname of the post or comment, e.g. "t3_abc123".', required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const id = redditApi.requireFullname({ value: propsValue.thing_id, label: 'Fullname' });
+ await redditApi.request<unknown>({ auth, method: HttpMethod.POST, path: '/api/unsave', form: { id } });
+ return { success: true, id, saved: false };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/ai/unsubscribe-subreddit.ts b/packages/pieces/community/reddit/src/lib/actions/ai/unsubscribe-subreddit.ts
new file mode 100644
index 00000000000..b8df80db259
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/actions/ai/unsubscribe-subreddit.ts
@@ -0,0 +1,34 @@
+import { HttpMethod } from '@activepieces/pieces-common';
+import { createAction } from '@activepieces/pieces-framework';
+import { redditAuth } from '../../auth';
+import { redditApi } from '../../common/client';
+import { redditAiProps } from '../../common/ai-props';
+import { redditSubscribeSubredditOutputSchema } from '../../output-schemas';
+
+export const redditUnsubscribeSubreddit = createAction({
+ auth: redditAuth,
+ name: 'reddit_unsubscribe_subreddit',
+ outputSchema: redditSubscribeSubredditOutputSchema,
+ displayName: 'Leave Subreddit',
+ description: 'Unsubscribes your account from a subreddit.',
+ audience: 'ai',
+ classification: 'DESTRUCTIVE',
+ aiMetadata: {
+ description:
+ 'Unsubscribes (leaves) your account from a subreddit; harmless when not subscribed. Rejoin with Join Subreddit. Needs the `subscribe` scope: older connections must reconnect.',
+ idempotent: true,
+ },
+ props: {
+ subreddit: redditAiProps.subreddit({ required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const subreddit = redditApi.cleanSubreddit({ value: propsValue.subreddit });
+ await redditApi.request<unknown>({
+ auth,
+ method: HttpMethod.POST,
+ path: '/api/subscribe',
+ form: { action: 'unsub', sr_name: subreddit },
+ });
+ return { success: true, subreddit, subscribed: false };
+ },
+});
diff --git a/packages/pieces/community/reddit/src/lib/actions/create-reddit-comment.ts b/packages/pieces/community/reddit/src/lib/actions/create-reddit-comment.ts
index 8e5ac1c5b9f..7360aa87d2d 100644
--- a/packages/pieces/community/reddit/src/lib/actions/create-reddit-comment.ts
+++ b/packages/pieces/community/reddit/src/lib/actions/create-reddit-comment.ts
@@ -1,14 +1,17 @@
import { createAction, Property } from '@activepieces/pieces-framework';
-import { httpClient, HttpMethod } from '@activepieces/pieces-common';
+import { HttpMethod } from '@activepieces/pieces-common';
import { redditAuth } from '../auth';
+import { redditApi } from '../common/client';
+import { createRedditCommentOutputSchema } from '../output-schemas';
export const createRedditComment = createAction({
auth: redditAuth,
name: 'createRedditComment',
+ outputSchema: createRedditCommentOutputSchema,
classification: 'WRITE',
displayName: 'Create Comment',
description: 'Comment on a Reddit post or reply to a comment.',
- audience: 'both',
+ audience: 'human',
aiMetadata: { description: 'Posts a comment from the authenticated account, either as a top-level reply to a post or as a nested reply to another comment, determined by the parent ID type (t3_ for a post, t1_ for a comment). Requires the parent ID and the comment text. Not idempotent — each call creates a separate comment.', idempotent: false },
props: {
parent_id: Property.ShortText({
@@ -23,38 +26,16 @@ export const createRedditComment = createAction({
}),
},
async run(context) {
- let parentId = context.propsValue.parent_id.trim();
-
- // If it's just a post ID, prefix it
- if (!parentId.startsWith('t1_') && !parentId.startsWith('t3_')) {
- parentId = `t3_${parentId}`;
- }
-
- const url = 'https://oauth.reddit.com/api/comment';
- const payload = new URLSearchParams({
- thing_id: parentId,
- text: context.propsValue.content,
- api_type: 'json',
- });
-
- const response = await httpClient.sendRequest({
+ return redditApi.request<unknown>({
+ auth: context.auth,
method: HttpMethod.POST,
- url,
- headers: {
- 'Authorization': `Bearer ${context.auth.access_token}`,
- 'User-Agent': 'ActivePieces Reddit Client',
- 'Content-Type': 'application/x-www-form-urlencoded',
+ allowJsonErrors: true,
+ path: '/api/comment',
+ form: {
+ api_type: 'json',
+ thing_id: redditApi.toFullname({ value: context.propsValue.parent_id, prefix: 't3_', accept: ['t1_', 't3_'] }),
+ text: context.propsValue.content,
},
- body: payload.toString(),
});
-
- if (response.status !== 200) {
- return {
- error: `Failed to create comment: ${response.status}`,
- details: response.body,
- };
- }
-
- return response.body;
},
});
diff --git a/packages/pieces/community/reddit/src/lib/actions/create-reddit-post.ts b/packages/pieces/community/reddit/src/lib/actions/create-reddit-post.ts
index 71740a232e7..27a3a7c9230 100644
--- a/packages/pieces/community/reddit/src/lib/actions/create-reddit-post.ts
+++ b/packages/pieces/community/reddit/src/lib/actions/create-reddit-post.ts
@@ -1,14 +1,17 @@
import { createAction, Property } from '@activepieces/pieces-framework';
-import { httpClient, HttpMethod } from '@activepieces/pieces-common';
+import { HttpMethod } from '@activepieces/pieces-common';
import { redditAuth } from '../auth';
+import { redditApi } from '../common/client';
+import { createRedditPostOutputSchema } from '../output-schemas';
export const createRedditPost = createAction({
auth: redditAuth,
name: 'createRedditPost',
+ outputSchema: createRedditPostOutputSchema,
classification: 'WRITE',
displayName: 'Create Post',
description: 'Submit a new self (text) post to a subreddit.',
- audience: 'both',
+ audience: 'human',
aiMetadata: { description: 'Submits a new self (text) post to a subreddit on behalf of the authenticated account. Use it to publish original text content; it cannot post links, images, or media. Requires the target subreddit, a title, and the text body. Not idempotent — each call creates a separate post.', idempotent: false },
props: {
subreddit: Property.ShortText({
@@ -29,35 +32,12 @@ export const createRedditPost = createAction({
},
async run(context) {
const { subreddit, title, content } = context.propsValue;
-
- const url = 'https://oauth.reddit.com/api/submit';
-
- const payload = new URLSearchParams({
- api_type: 'json',
- sr: subreddit,
- title,
- text: content,
- kind: 'self',
- });
-
- const response = await httpClient.sendRequest({
+ return redditApi.request<unknown>({
+ auth: context.auth,
method: HttpMethod.POST,
- url,
- headers: {
- 'Authorization': `Bearer ${context.auth.access_token}`,
- 'User-Agent': 'ActivePieces Reddit Client',
- 'Content-Type': 'application/x-www-form-urlencoded',
- },
- body: payload.toString(),
+ allowJsonErrors: true,
+ path: '/api/submit',
+ form: { api_type: 'json', sr: subreddit, title, text: content, kind: 'self' },
});
-
- if (response.status !== 200) {
- return {
- error: `Failed to create post: ${response.status}`,
- details: response.body,
- };
- }
-
- return response.body;
},
});
diff --git a/packages/pieces/community/reddit/src/lib/actions/delete-reddit-comment.ts b/packages/pieces/community/reddit/src/lib/actions/delete-reddit-comment.ts
index 78493c4e56a..591eb656684 100644
--- a/packages/pieces/community/reddit/src/lib/actions/delete-reddit-comment.ts
+++ b/packages/pieces/community/reddit/src/lib/actions/delete-reddit-comment.ts
@@ -1,14 +1,17 @@
import { createAction, Property } from '@activepieces/pieces-framework';
-import { httpClient, HttpMethod } from '@activepieces/pieces-common';
+import { HttpMethod } from '@activepieces/pieces-common';
import { redditAuth } from '../auth';
+import { redditApi } from '../common/client';
+import { deleteRedditContentOutputSchema } from '../output-schemas';
export const deleteRedditComment = createAction({
auth: redditAuth,
name: 'deleteRedditComment',
+ outputSchema: deleteRedditContentOutputSchema,
classification: 'DESTRUCTIVE',
displayName: 'Delete Comment',
description: 'Delete a specific Reddit comment by ID.',
- audience: 'both',
+ audience: 'human',
aiMetadata: { description: 'Deletes a comment owned by the authenticated account, identified by comment ID. Use it to permanently remove a comment you previously posted. Requires the comment ID (with or without the t1_ prefix). Idempotent — once deleted, repeating the call leaves the same end state.', idempotent: true },
props: {
comment_id: Property.ShortText({
@@ -18,35 +21,13 @@ export const deleteRedditComment = createAction({
}),
},
async run(context) {
- let commentId = context.propsValue.comment_id.trim();
- if (commentId.startsWith('t1_')) {
- commentId = commentId.slice(3);
- }
-
- const url = 'https://oauth.reddit.com/api/del';
- const payload = new URLSearchParams({
- api_type: 'json',
- id: `t1_${commentId}`,
- });
-
- const response = await httpClient.sendRequest({
+ const response = await redditApi.request<unknown>({
+ auth: context.auth,
method: HttpMethod.POST,
- url,
- headers: {
- 'Authorization': `Bearer ${context.auth.access_token}`,
- 'User-Agent': 'ActivePieces Reddit Client',
- 'Content-Type': 'application/x-www-form-urlencoded',
- },
- body: payload.toString(),
+ allowJsonErrors: true,
+ path: '/api/del',
+ form: { api_type: 'json', id: redditApi.toFullname({ value: context.propsValue.comment_id, prefix: 't1_' }) },
});
-
- if (response.status !== 200) {
- return {
- error: `Failed to delete comment: ${response.status}`,
- details: response.body,
- };
- }
-
- return { success: true, response: response.body };
+ return { success: true, response };
},
});
diff --git a/packages/pieces/community/reddit/src/lib/actions/delete-reddit-post.ts b/packages/pieces/community/reddit/src/lib/actions/delete-reddit-post.ts
index 2b08e9e6acb..a4a6ee11f26 100644
--- a/packages/pieces/community/reddit/src/lib/actions/delete-reddit-post.ts
+++ b/packages/pieces/community/reddit/src/lib/actions/delete-reddit-post.ts
@@ -1,14 +1,17 @@
import { createAction, Property } from '@activepieces/pieces-framework';
-import { httpClient, HttpMethod } from '@activepieces/pieces-common';
+import { HttpMethod } from '@activepieces/pieces-common';
import { redditAuth } from '../auth';
+import { redditApi } from '../common/client';
+import { deleteRedditContentOutputSchema } from '../output-schemas';
export const deleteRedditPost = createAction({
auth: redditAuth,
name: 'deleteRedditPost',
+ outputSchema: deleteRedditContentOutputSchema,
classification: 'DESTRUCTIVE',
displayName: 'Delete Post',
description: 'Delete a specific Reddit post by ID.',
- audience: 'both',
+ audience: 'human',
aiMetadata: { description: 'Deletes a post owned by the authenticated account, identified by post ID. Use it to permanently remove a post you previously created. Requires the post ID (with or without the t3_ prefix). Idempotent — once deleted, repeating the call leaves the same end state.', idempotent: true },
props: {
post_id: Property.ShortText({
@@ -18,35 +21,13 @@ export const deleteRedditPost = createAction({
}),
},
async run(context) {
- let postId = context.propsValue.post_id.trim();
- if (postId.startsWith('t3_')) {
- postId = postId.slice(3);
- }
-
- const url = 'https://oauth.reddit.com/api/del';
- const payload = new URLSearchParams({
- api_type: 'json',
- id: `t3_${postId}`,
- });
-
- const response = await httpClient.sendRequest({
+ const response = await redditApi.request<unknown>({
+ auth: context.auth,
method: HttpMethod.POST,
- url,
- headers: {
- 'Authorization': `Bearer ${context.auth.access_token}`,
- 'User-Agent': 'ActivePieces Reddit Client',
- 'Content-Type': 'application/x-www-form-urlencoded',
- },
- body: payload.toString(),
+ allowJsonErrors: true,
+ path: '/api/del',
+ form: { api_type: 'json', id: redditApi.toFullname({ value: context.propsValue.post_id, prefix: 't3_' }) },
});
-
- if (response.status !== 200) {
- return {
- error: `Failed to delete post: ${response.status}`,
- details: response.body,
- };
- }
-
- return { success: true, response: response.body };
+ return { success: true, response };
},
});
diff --git a/packages/pieces/community/reddit/src/lib/actions/edit-reddit-comment.ts b/packages/pieces/community/reddit/src/lib/actions/edit-reddit-comment.ts
index 296a59f872f..9e9fbb63082 100644
--- a/packages/pieces/community/reddit/src/lib/actions/edit-reddit-comment.ts
+++ b/packages/pieces/community/reddit/src/lib/actions/edit-reddit-comment.ts
@@ -1,14 +1,17 @@
import { createAction, Property } from '@activepieces/pieces-framework';
-import { httpClient, HttpMethod } from '@activepieces/pieces-common';
+import { HttpMethod } from '@activepieces/pieces-common';
import { redditAuth } from '../auth';
+import { redditApi } from '../common/client';
+import { createRedditCommentOutputSchema } from '../output-schemas';
export const editRedditComment = createAction({
auth: redditAuth,
name: 'editRedditComment',
+ outputSchema: createRedditCommentOutputSchema,
classification: 'WRITE',
displayName: 'Edit Comment',
description: 'Edits the content of an existing Reddit comment.',
- audience: 'both',
+ audience: 'human',
aiMetadata: { description: 'Replaces the text of an existing comment owned by the authenticated account, identified by comment ID. Use it to update a comment you previously posted. Requires the comment ID (with or without the t1_ prefix) and the new content. Idempotent — repeating with the same content leaves the comment in the same state.', idempotent: true },
props: {
comment_id: Property.ShortText({
@@ -23,36 +26,16 @@ export const editRedditComment = createAction({
}),
},
async run(context) {
- let commentId = context.propsValue.comment_id.trim();
- if (commentId.startsWith('t1_')) {
- commentId = commentId.slice(3);
- }
-
- const url = 'https://oauth.reddit.com/api/editusertext';
- const payload = new URLSearchParams({
- api_type: 'json',
- thing_id: `t1_${commentId}`,
- text: context.propsValue.content,
- });
-
- const response = await httpClient.sendRequest({
+ return redditApi.request<unknown>({
+ auth: context.auth,
method: HttpMethod.POST,
- url,
- headers: {
- 'Authorization': `Bearer ${context.auth.access_token}`,
- 'User-Agent': 'ActivePieces Reddit Client',
- 'Content-Type': 'application/x-www-form-urlencoded',
+ allowJsonErrors: true,
+ path: '/api/editusertext',
+ form: {
+ api_type: 'json',
+ thing_id: redditApi.toFullname({ value: context.propsValue.comment_id, prefix: 't1_' }),
+ text: context.propsValue.content,
},
- body: payload.toString(),
});
-
- if (response.status !== 200) {
- return {
- error: `Failed to edit comment: ${response.status}`,
- details: response.body,
- };
- }
-
- return response.body;
},
});
diff --git a/packages/pieces/community/reddit/src/lib/actions/edit-reddit-post.ts b/packages/pieces/community/reddit/src/lib/actions/edit-reddit-post.ts
index 7b7a90eead7..f0ba07393bb 100644
--- a/packages/pieces/community/reddit/src/lib/actions/edit-reddit-post.ts
+++ b/packages/pieces/community/reddit/src/lib/actions/edit-reddit-post.ts
@@ -1,14 +1,17 @@
import { createAction, Property } from '@activepieces/pieces-framework';
-import { httpClient, HttpMethod } from '@activepieces/pieces-common';
+import { HttpMethod } from '@activepieces/pieces-common';
import { redditAuth } from '../auth';
+import { redditApi } from '../common/client';
+import { editRedditPostOutputSchema } from '../output-schemas';
export const editRedditPost = createAction({
auth: redditAuth,
name: 'editRedditPost',
+ outputSchema: editRedditPostOutputSchema,
classification: 'WRITE',
displayName: 'Edit Post',
description: 'Edits the content of an existing Reddit post.',
- audience: 'both',
+ audience: 'human',
aiMetadata: { description: 'Replaces the text body of an existing self post owned by the authenticated account, identified by post ID. Use it to update a post you previously created; it only edits text posts, not link or media posts. Requires the post ID (with or without the t3_ prefix) and the new content. Idempotent — repeating with the same content leaves the post in the same state.', idempotent: true },
props: {
post_id: Property.ShortText({
@@ -23,36 +26,16 @@ export const editRedditPost = createAction({
}),
},
async run(context) {
- let postId = context.propsValue.post_id.trim();
- if (postId.startsWith('t3_')) {
- postId = postId.slice(3);
- }
-
- const url = 'https://oauth.reddit.com/api/editusertext';
- const payload = new URLSearchParams({
- api_type: 'json',
- thing_id: `t3_${postId}`,
- text: context.propsValue.content,
- });
-
- const response = await httpClient.sendRequest({
+ return redditApi.request<unknown>({
+ auth: context.auth,
method: HttpMethod.POST,
- url,
- headers: {
- 'Authorization': `Bearer ${context.auth.access_token}`,
- 'User-Agent': 'ActivePieces Reddit Client',
- 'Content-Type': 'application/x-www-form-urlencoded',
+ allowJsonErrors: true,
+ path: '/api/editusertext',
+ form: {
+ api_type: 'json',
+ thing_id: redditApi.toFullname({ value: context.propsValue.post_id, prefix: 't3_' }),
+ text: context.propsValue.content,
},
- body: payload.toString(),
});
-
- if (response.status !== 200) {
- return {
- error: `Failed to edit post: ${response.status}`,
- details: response.body,
- };
- }
-
- return response.body;
},
});
diff --git a/packages/pieces/community/reddit/src/lib/actions/fetch-post-comments.ts b/packages/pieces/community/reddit/src/lib/actions/fetch-post-comments.ts
index a776fb4f6d6..fe33d4f4e21 100644
--- a/packages/pieces/community/reddit/src/lib/actions/fetch-post-comments.ts
+++ b/packages/pieces/community/reddit/src/lib/actions/fetch-post-comments.ts
@@ -1,14 +1,17 @@
import { createAction, Property } from '@activepieces/pieces-framework';
-import { httpClient, HttpMethod } from '@activepieces/pieces-common';
+import { HttpMethod } from '@activepieces/pieces-common';
import { redditAuth } from '../auth';
+import { redditApi, RedditListing, RedditThing } from '../common/client';
+import { fetchPostCommentsOutputSchema } from '../output-schemas';
export const fetchPostComments = createAction({
auth: redditAuth,
name: 'fetchPostComments',
+ outputSchema: fetchPostCommentsOutputSchema,
classification: 'SEARCH',
displayName: 'Fetch Post Comments',
description: 'Fetch comments from a specific Reddit post.',
- audience: 'both',
+ audience: 'human',
aiMetadata: { description: 'Retrieves the threaded comments of one Reddit post identified by its ID, including nested replies. Use it to read discussion on a known post; the sort option (new, top, hot, best, old, controversial) and a limit on top-level comments are configurable. Accepts the post ID with or without the t3_ prefix. Read-only and idempotent.', idempotent: true },
props: {
post_id: Property.ShortText({
@@ -40,57 +43,54 @@ export const fetchPostComments = createAction({
}),
},
async run(context) {
- let postId = context.propsValue.post_id.trim();
- if (postId.startsWith('t3_')) {
- postId = postId.slice(3);
- }
-
- const response = await httpClient.sendRequest({
+ const listings = await redditApi.request<[RedditListing, RedditListing]>({
+ auth: context.auth,
method: HttpMethod.GET,
- url: `https://oauth.reddit.com/comments/${postId}`,
- headers: {
- 'Authorization': `Bearer ${context.auth.access_token}`,
- 'User-Agent': 'ActivePieces Reddit Client',
- 'Content-Type': 'application/json',
- },
- queryParams: {
+ path: `/comments/${redditApi.toBaseId({ value: context.propsValue.post_id })}`,
+ query: {
sort: context.propsValue.sort ?? 'new',
- limit: (context.propsValue.limit ?? 10).toString(),
+ limit: context.propsValue.limit ?? 10,
},
});
- if (response.status !== 200) {
+ return processComments({ comments: listings[1]?.data?.children ?? [] });
+ },
+});
+
+function processComments({ comments }: { comments: RedditThing[] }): ProcessedComment[] {
+ return comments
+ .filter((comment) => comment.kind === 't1')
+ .map((comment) => {
+ const d = comment.data;
+ const replies = d['replies'];
return {
- error: `Failed to retrieve comments: ${response.status}`,
- details: response.body,
+ id: d['id'],
+ author: d['author'],
+ body: d['body'],
+ score: d['score'],
+ created_utc: d['created_utc'],
+ permalink: d['permalink'],
+ edited: d['edited'],
+ is_submitter: d['is_submitter'],
+ stickied: d['stickied'],
+ replies: isReplyListing(replies) ? processComments({ comments: replies.data.children }) : [],
};
- }
-
- function processComments(comments: any[]): any[] {
- return comments
- .filter(c => c.kind === 't1')
- .map(c => {
- const d = c.data;
- return {
- id: d.id,
- author: d.author,
- body: d.body,
- score: d.score,
- created_utc: d.created_utc,
- permalink: d.permalink,
- edited: d.edited,
- is_submitter: d.is_submitter,
- stickied: d.stickied,
- replies: d.replies && typeof d.replies === 'object'
- ? processComments(d.replies.data.children)
- : [],
- };
- });
- }
+ });
+}
- const data = response.body;
- const commentsTree = data[1]?.data?.children ?? [];
+function isReplyListing(value: unknown): value is RedditListing {
+ return typeof value === 'object' && value !== null && 'data' in value && typeof value.data === 'object' && value.data !== null && 'children' in value.data && Array.isArray(value.data.children);
+}
- return processComments(commentsTree);
- },
-});
+type ProcessedComment = {
+ id: unknown;
+ author: unknown;
+ body: unknown;
+ score: unknown;
+ created_utc: unknown;
+ permalink: unknown;
+ edited: unknown;
+ is_submitter: unknown;
+ stickied: unknown;
+ replies: ProcessedComment[];
+};
diff --git a/packages/pieces/community/reddit/src/lib/actions/get-reddit-post-details.ts b/packages/pieces/community/reddit/src/lib/actions/get-reddit-post-details.ts
index 221f4453572..3811ca32c29 100644
--- a/packages/pieces/community/reddit/src/lib/actions/get-reddit-post-details.ts
+++ b/packages/pieces/community/reddit/src/lib/actions/get-reddit-post-details.ts
@@ -1,14 +1,17 @@
import { createAction, Property } from '@activepieces/pieces-framework';
-import { httpClient, HttpMethod } from '@activepieces/pieces-common';
+import { HttpMethod } from '@activepieces/pieces-common';
import { redditAuth } from '../auth';
+import { redditApi, RedditListing } from '../common/client';
+import { getRedditPostDetailsOutputSchema } from '../output-schemas';
export const getRedditPostDetails = createAction({
auth: redditAuth,
name: 'getRedditPostDetails',
+ outputSchema: getRedditPostDetailsOutputSchema,
classification: 'READ',
displayName: 'Get Post Details',
description: 'Fetch detailed information about a specific Reddit post using its ID.',
- audience: 'both',
+ audience: 'human',
aiMetadata: { description: 'Looks up one specific Reddit post by its ID and returns its full metadata (title, author, body, score, counts, flags). Use it when you already have a post ID and need details for that single post, not to browse a subreddit. Accepts the ID with or without the t3_ prefix. Read-only and idempotent.', idempotent: true },
props: {
post_id: Property.ShortText({
@@ -18,73 +21,29 @@ export const getRedditPostDetails = createAction({
}),
},
async run(context) {
- let postId = context.propsValue.post_id.trim();
- if (postId.startsWith('t3_')) {
- postId = postId.slice(3);
- }
-
- const url = `https://oauth.reddit.com/api/info?id=t3_${postId}`;
-
- const response = await httpClient.sendRequest({
+ const listing = await redditApi.request<RedditListing>({
+ auth: context.auth,
method: HttpMethod.GET,
- url,
- headers: {
- 'Authorization': `Bearer ${context.auth.access_token}`,
- 'User-Agent': 'ActivePieces Reddit Client',
- 'Content-Type': 'application/json',
- },
- timeout: 5000,
+ path: '/api/info',
+ query: { id: redditApi.toFullname({ value: context.propsValue.post_id, prefix: 't3_' }) },
});
- if (response.status !== 200) {
- return {
- error: `Failed to retrieve post details: ${response.status}`,
- details: response.body,
- };
- }
-
- const children = response.body?.data?.children ?? [];
-
- if (children.length === 0) {
+ const post = listing.data.children[0];
+ if (!post) {
return { error: 'No post found with the given ID' };
}
- const data = children[0].data;
-
- const result: Record<string, unknown> = {
- id: data.id,
- title: data.title,
- author: data.author,
- author_fullname: data.author_fullname,
- subreddit: data.subreddit,
- subreddit_id: data.subreddit_id,
- selftext: data.selftext,
- selftext_html: data.selftext_html,
- score: data.score,
- upvote_ratio: data.upvote_ratio,
- created_utc: data.created_utc,
- permalink: data.permalink,
- url: data.url,
- domain: data.domain,
- num_comments: data.num_comments,
- is_self: data.is_self,
- is_video: data.is_video,
- is_original_content: data.is_original_content,
- over_18: data.over_18,
- spoiler: data.spoiler,
- locked: data.locked,
- stickied: data.stickied,
- post_hint: data.post_hint,
+ const data = post.data;
+ return {
+ ...Object.fromEntries(POST_DETAIL_FIELDS.map((key) => [key, data[key]])),
+ ...(data['media'] ? { media: data['media'] } : {}),
+ ...(data['gallery_data'] ? { gallery_data: data['gallery_data'] } : {}),
};
-
- if (data.media) {
- result['media'] = data.media;
- }
-
- if (data.gallery_data) {
- result['gallery_data'] = data.gallery_data;
- }
-
- return result;
},
});
+
+const POST_DETAIL_FIELDS = [
+ 'id', 'title', 'author', 'author_fullname', 'subreddit', 'subreddit_id', 'selftext', 'selftext_html', 'score',
+ 'upvote_ratio', 'created_utc', 'permalink', 'url', 'domain', 'num_comments', 'is_self', 'is_video',
+ 'is_original_content', 'over_18', 'spoiler', 'locked', 'stickied', 'post_hint',
+] as const;
diff --git a/packages/pieces/community/reddit/src/lib/actions/retrieve-reddit-post.ts b/packages/pieces/community/reddit/src/lib/actions/retrieve-reddit-post.ts
index 595365022ae..4a2edb3d3b8 100644
--- a/packages/pieces/community/reddit/src/lib/actions/retrieve-reddit-post.ts
+++ b/packages/pieces/community/reddit/src/lib/actions/retrieve-reddit-post.ts
@@ -1,18 +1,17 @@
import { createAction, Property } from '@activepieces/pieces-framework';
-import {
- httpClient,
- HttpMethod,
- AuthenticationType,
-} from '@activepieces/pieces-common';
+import { HttpMethod } from '@activepieces/pieces-common';
import { redditAuth } from '../auth';
+import { redditApi } from '../common/client';
+import { retrieveRedditPostOutputSchema } from '../output-schemas';
export const retrieveRedditPost = createAction({
auth: redditAuth,
name: 'retrieveRedditPost',
+ outputSchema: retrieveRedditPostOutputSchema,
classification: 'SEARCH',
displayName: 'Retrieve Post',
description: 'Fetch top posts in a subreddit with optional size limit.',
- audience: 'both',
+ audience: 'human',
aiMetadata: { description: 'Lists posts from a given subreddit, choosing the listing via a category (hot, new, top, rising, or controversial). Use it to read or monitor a subreddit\'s feed rather than to look up one known post. Requires the subreddit name; an optional size caps how many posts are returned (max 100). Read-only and idempotent.', idempotent: true },
props: {
post_category: Property.StaticDropdown({
@@ -43,27 +42,11 @@ export const retrieveRedditPost = createAction({
}),
},
async run(context) {
- const baseUrl = `https://oauth.reddit.com/r/${context.propsValue.subreddit}/${context.propsValue.post_category}`;
- const limit = context.propsValue.size || 10;
-
- const response = await httpClient.sendRequest({
+ return redditApi.request<unknown>({
+ auth: context.auth,
method: HttpMethod.GET,
- url: baseUrl,
- queryParams: {
- limit: limit.toString(),
- },
- headers: {
- 'Authorization': `Bearer ${context.auth.access_token}`,
- 'User-Agent': 'ActivePieces Reddit Client',
- 'Content-Type': 'application/json',
- },
- timeout: 5000,
+ path: `/r/${context.propsValue.subreddit}/${context.propsValue.post_category}`,
+ query: { limit: context.propsValue.size || 10 },
});
-
- if (response.status !== 200) {
- throw new Error(`Reddit API error: ${response.status} ${JSON.stringify(response.body)}`);
- }
-
- return response.body;
},
});
diff --git a/packages/pieces/community/reddit/src/lib/auth.ts b/packages/pieces/community/reddit/src/lib/auth.ts
index a52889301f6..7f0f09dda24 100644
--- a/packages/pieces/community/reddit/src/lib/auth.ts
+++ b/packages/pieces/community/reddit/src/lib/auth.ts
@@ -21,7 +21,7 @@ export const redditAuth = PieceAuth.OAuth2({
authUrl: 'https://www.reddit.com/api/v1/authorize',
tokenUrl: 'https://www.reddit.com/api/v1/access_token',
required: true,
- scope: ['identity', 'read', 'submit', 'edit', 'history', 'flair'],
+ scope: ['identity', 'read', 'submit', 'edit', 'history', 'flair', 'save', 'report', 'subscribe', 'privatemessages', 'mysubreddits', 'wikiread'],
authorizationMethod: OAuth2AuthorizationMethod.HEADER,
extra: {
grantType: OAuth2GrantType.AUTHORIZATION_CODE,
diff --git a/packages/pieces/community/reddit/src/lib/common/ai-props.ts b/packages/pieces/community/reddit/src/lib/common/ai-props.ts
new file mode 100644
index 00000000000..6adf158980f
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/common/ai-props.ts
@@ -0,0 +1,82 @@
+import { Property } from '@activepieces/pieces-framework';
+
+function subreddit<R extends boolean>({ required, description }: { required: R; description?: string }) {
+ return Property.ShortText({
+ displayName: 'Subreddit',
+ description: description ?? 'Subreddit name without the r/ prefix (e.g. "programming").',
+ required,
+ });
+}
+
+function username({ description }: { description?: string }) {
+ return Property.ShortText({
+ displayName: 'Username',
+ description: description ?? 'Reddit username without the u/ prefix.',
+ required: true,
+ });
+}
+
+function limit() {
+ return Property.Number({
+ displayName: 'Limit',
+ description: 'Maximum number of items to return (1-100, default 25).',
+ required: false,
+ });
+}
+
+function after() {
+ return Property.ShortText({
+ displayName: 'After',
+ description: 'Pagination cursor: pass the `after` value from the previous response to get the next page.',
+ required: false,
+ });
+}
+
+function timeFilter() {
+ return Property.StaticDropdown({
+ displayName: 'Time Range',
+ description: 'Time window for "top" and "controversial" sorts.',
+ required: false,
+ options: {
+ options: [
+ { label: 'Past Hour', value: 'hour' },
+ { label: 'Past 24 Hours', value: 'day' },
+ { label: 'Past Week', value: 'week' },
+ { label: 'Past Month', value: 'month' },
+ { label: 'Past Year', value: 'year' },
+ { label: 'All Time', value: 'all' },
+ ],
+ },
+ });
+}
+
+function optionalBoolean({ displayName, description }: { displayName: string; description: string }) {
+ return Property.StaticDropdown({
+ displayName,
+ description,
+ required: false,
+ options: {
+ options: [
+ { label: 'Yes', value: 'true' },
+ { label: 'No', value: 'false' },
+ ],
+ },
+ });
+}
+
+function clampLimit({ value }: { value: number | undefined }): number | undefined {
+ if (value === undefined || value === null) {
+ return undefined;
+ }
+ return Math.min(Math.max(Math.trunc(value), 1), 100);
+}
+
+export const redditAiProps = {
+ subreddit,
+ username,
+ limit,
+ after,
+ timeFilter,
+ optionalBoolean,
+ clampLimit,
+};
diff --git a/packages/pieces/community/reddit/src/lib/common/client.ts b/packages/pieces/community/reddit/src/lib/common/client.ts
new file mode 100644
index 00000000000..b7aa61671ed
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/common/client.ts
@@ -0,0 +1,207 @@
+import { httpClient, HttpError, HttpMethod } from '@activepieces/pieces-common';
+
+async function request<T>({ auth, method, path, query, form, allowJsonErrors = false }: RequestParams): Promise<T> {
+ const isForm = form !== undefined;
+ try {
+ const response = await httpClient.sendRequest<T>({
+ method,
+ url: `${BASE_URL}${path}`,
+ headers: {
+ Authorization: `Bearer ${auth.access_token}`,
+ 'User-Agent': USER_AGENT,
+ ...(isForm ? { 'Content-Type': 'application/x-www-form-urlencoded' } : {}),
+ },
+ queryParams: { raw_json: '1', ...compact({ values: query ?? {} }) },
+ body: isForm ? new URLSearchParams(compact({ values: form })).toString() : undefined,
+ });
+ if (!allowJsonErrors) {
+ assertNoJsonErrors({ body: response.body });
+ }
+ return response.body;
+ } catch (error: unknown) {
+ if (error instanceof HttpError) {
+ throw new Error(describeHttpError({ status: error.response.status, body: error.response.body }));
+ }
+ throw error;
+ }
+}
+
+function toFullname({ value, prefix, accept = [prefix] }: { value: string; prefix: ThingPrefix; accept?: ThingPrefix[] }): string {
+ const trimmed = value.trim();
+ if (!FULLNAME_PATTERN.test(trimmed)) {
+ return `${prefix}${trimmed}`;
+ }
+ if (!accept.some((allowed) => trimmed.startsWith(allowed))) {
+ throw new Error(`Expected a ${accept.join(' or ')} fullname, got "${trimmed}".`);
+ }
+ return trimmed;
+}
+
+function requireFullname({ value, label }: { value: string; label: string }): string {
+ const trimmed = value.trim();
+ if (!FULLNAME_PATTERN.test(trimmed)) {
+ throw new Error(`${label} must be a Reddit fullname with its type prefix (t1_ comment, t3_ post, t4_ message), got "${trimmed}".`);
+ }
+ return trimmed;
+}
+
+function toBaseId({ value }: { value: string }): string {
+ return value.trim().replace(FULLNAME_PATTERN, '');
+}
+
+function cleanSubreddit({ value }: { value: string }): string {
+ return value.trim().replace(/^\/?r\//i, '');
+}
+
+function cleanUsername({ value }: { value: string }): string {
+ return value.trim().replace(/^\/?u(ser)?\//i, '');
+}
+
+function toThing({ thing }: { thing: RedditThing }): Record<string, unknown> {
+ const fields = FIELDS_BY_KIND[thing.kind];
+ if (fields === undefined) {
+ return { kind: thing.kind, ...thing.data };
+ }
+ return { kind: thing.kind, ...pick({ data: thing.data, keys: fields }) };
+}
+
+function toListing({ listing }: { listing: RedditListing }) {
+ const items = listing.data.children.map((thing) => toThing({ thing }));
+ return { items, count: items.length, after: listing.data.after ?? null, before: listing.data.before ?? null };
+}
+
+function flattenCommentTree({ children }: { children: RedditThing[] }): { comments: Record<string, unknown>[]; more: Record<string, unknown>[] } {
+ return children.reduce<{ comments: Record<string, unknown>[]; more: Record<string, unknown>[] }>(
+ (acc, thing) => {
+ if (thing.kind === 'more') {
+ return { comments: acc.comments, more: [...acc.more, pick({ data: thing.data, keys: MORE_FIELDS })] };
+ }
+ const replies = thing.data['replies'];
+ const nested = isListing(replies) ? flattenCommentTree({ children: replies.data.children }) : { comments: [], more: [] };
+ return {
+ comments: [...acc.comments, toThing({ thing }), ...nested.comments],
+ more: [...acc.more, ...nested.more],
+ };
+ },
+ { comments: [], more: [] },
+ );
+}
+
+function isListing(value: unknown): value is RedditListing {
+ if (typeof value !== 'object' || value === null || !('data' in value)) {
+ return false;
+ }
+ const data = value.data;
+ return typeof data === 'object' && data !== null && 'children' in data && Array.isArray(data.children);
+}
+
+function pick({ data, keys }: { data: Record<string, unknown>; keys: readonly string[] }): Record<string, unknown> {
+ return Object.fromEntries(keys.map((key) => [key, data[key] ?? null]));
+}
+
+function compact({ values }: { values: Record<string, string | number | boolean | undefined | null> }): Record<string, string> {
+ return Object.fromEntries(
+ Object.entries(values)
+ .filter((entry): entry is [string, string | number | boolean] => entry[1] !== undefined && entry[1] !== null && entry[1] !== '')
+ .map(([key, value]) => [key, String(value)]),
+ );
+}
+
+function assertNoJsonErrors({ body }: { body: unknown }): void {
+ if (typeof body !== 'object' || body === null || !('json' in body)) {
+ return;
+ }
+ const json = body.json;
+ if (typeof json !== 'object' || json === null || !('errors' in json) || !Array.isArray(json.errors) || json.errors.length === 0) {
+ return;
+ }
+ const messages = json.errors.map((error: unknown) => (Array.isArray(error) ? error.join(': ') : String(error)));
+ throw new Error(`Reddit rejected the request: ${messages.join('; ')}`);
+}
+
+function describeHttpError({ status, body }: { status: number; body: unknown }): string {
+ const detail = typeof body === 'string' ? body : JSON.stringify(body);
+ if (status === 401) {
+ return `Reddit returned 401 Unauthorized: the connection's token is invalid or expired. Reconnect your Reddit account. ${detail}`;
+ }
+ if (status === 403) {
+ return `Reddit returned 403 Forbidden: the account lacks permission for this item, or the connection is missing a scope added later (save, report, subscribe, privatemessages, mysubreddits, wikiread) — reconnect your Reddit account to grant it. ${detail}`;
+ }
+ if (status === 404) {
+ return `Reddit returned 404 Not Found: check the id, subreddit or username. ${detail}`;
+ }
+ if (status === 429) {
+ return `Reddit returned 429 Too Many Requests: rate limit reached, retry later. ${detail}`;
+ }
+ return `Reddit returned ${status}: ${detail}`;
+}
+
+const BASE_URL = 'https://oauth.reddit.com';
+const USER_AGENT = 'ActivePieces Reddit Client';
+const FULLNAME_PATTERN = /^t[1-6]_/;
+const POST_FIELDS = [
+ 'id', 'name', 'title', 'author', 'subreddit', 'subreddit_name_prefixed', 'selftext', 'url', 'permalink', 'domain',
+ 'score', 'upvote_ratio', 'num_comments', 'num_crossposts', 'created_utc', 'edited', 'is_self', 'over_18', 'spoiler',
+ 'stickied', 'locked', 'archived', 'link_flair_text', 'link_flair_template_id', 'crosspost_parent',
+] as const;
+const COMMENT_FIELDS = [
+ 'id', 'name', 'author', 'body', 'score', 'created_utc', 'edited', 'permalink', 'parent_id', 'link_id', 'link_title',
+ 'subreddit', 'depth', 'is_submitter', 'stickied', 'distinguished',
+] as const;
+const SUBREDDIT_FIELDS = [
+ 'id', 'name', 'display_name', 'display_name_prefixed', 'title', 'public_description', 'subscribers', 'active_user_count',
+ 'subreddit_type', 'submission_type', 'over18', 'lang', 'created_utc', 'url', 'user_is_subscriber', 'user_is_moderator',
+] as const;
+const USER_FIELDS = [
+ 'id', 'name', 'link_karma', 'comment_karma', 'total_karma', 'created_utc', 'is_gold', 'is_mod', 'verified',
+ 'has_verified_email', 'is_employee', 'icon_img',
+] as const;
+const MESSAGE_FIELDS = [
+ 'id', 'name', 'author', 'dest', 'subject', 'body', 'created_utc', 'new', 'was_comment', 'parent_id',
+ 'first_message_name', 'context', 'subreddit', 'distinguished',
+] as const;
+const MORE_FIELDS = ['id', 'name', 'parent_id', 'count', 'depth', 'children'] as const;
+const FIELDS_BY_KIND: Record<string, readonly string[] | undefined> = {
+ t1: COMMENT_FIELDS,
+ t2: USER_FIELDS,
+ t3: POST_FIELDS,
+ t4: MESSAGE_FIELDS,
+ t5: SUBREDDIT_FIELDS,
+};
+
+export const redditApi = {
+ request,
+ toFullname,
+ requireFullname,
+ toBaseId,
+ cleanSubreddit,
+ cleanUsername,
+ toThing,
+ toListing,
+ flattenCommentTree,
+};
+
+type ThingPrefix = 't1_' | 't3_' | 't4_' | 't5_';
+
+type RequestParams = {
+ auth: { access_token: string };
+ method: HttpMethod;
+ path: string;
+ query?: Record<string, string | number | boolean | undefined | null>;
+ form?: Record<string, string | number | boolean | undefined | null>;
+ allowJsonErrors?: boolean;
+};
+
+export type RedditThing = {
+ kind: string;
+ data: Record<string, unknown>;
+};
+
+export type RedditListing = {
+ kind?: string;
+ data: {
+ after?: string | null;
+ before?: string | null;
+ children: RedditThing[];
+ };
+};
diff --git a/packages/pieces/community/reddit/src/lib/output-schemas.ts b/packages/pieces/community/reddit/src/lib/output-schemas.ts
new file mode 100644
index 00000000000..b580a65db7d
--- /dev/null
+++ b/packages/pieces/community/reddit/src/lib/output-schemas.ts
@@ -0,0 +1,667 @@
+import { OutputSchema } from '@activepieces/pieces-framework';
+
+const pagingFields: OutputSchema['fields'] = [
+ { key: 'count', label: 'Count', format: 'number' },
+ { key: 'after', label: 'Next Page Cursor' },
+ { key: 'before', label: 'Previous Page Cursor' },
+];
+
+const postFields: OutputSchema['fields'] = [
+ { key: 'kind', label: 'Kind' },
+ { key: 'id', label: 'Post ID' },
+ { key: 'name', label: 'Fullname' },
+ { key: 'title', label: 'Title' },
+ { key: 'author', label: 'Author' },
+ { key: 'subreddit', label: 'Subreddit' },
+ { key: 'subreddit_name_prefixed', label: 'Subreddit (Prefixed)' },
+ { key: 'selftext', label: 'Body Text' },
+ { key: 'url', label: 'URL', format: 'url' },
+ { key: 'permalink', label: 'Permalink' },
+ { key: 'domain', label: 'Domain' },
+ { key: 'score', label: 'Score', format: 'number' },
+ { key: 'upvote_ratio', label: 'Upvote Ratio', format: 'number' },
+ { key: 'num_comments', label: 'Comment Count', format: 'number' },
+ { key: 'num_crossposts', label: 'Crosspost Count', format: 'number' },
+ { key: 'created_utc', label: 'Created At (Unix Seconds)', format: 'number' },
+ { key: 'edited', label: 'Edited' },
+ { key: 'is_self', label: 'Is Text Post', format: 'boolean' },
+ { key: 'over_18', label: 'NSFW', format: 'boolean' },
+ { key: 'spoiler', label: 'Spoiler', format: 'boolean' },
+ { key: 'stickied', label: 'Stickied', format: 'boolean' },
+ { key: 'locked', label: 'Locked', format: 'boolean' },
+ { key: 'archived', label: 'Archived', format: 'boolean' },
+ { key: 'link_flair_text', label: 'Flair Text' },
+ { key: 'link_flair_template_id', label: 'Flair Template ID' },
+ { key: 'crosspost_parent', label: 'Crosspost Parent' },
+];
+
+const commentOnlyFields: OutputSchema['fields'] = [
+ { key: 'body', label: 'Body' },
+ { key: 'parent_id', label: 'Parent Fullname' },
+ { key: 'link_id', label: 'Post Fullname' },
+ { key: 'link_title', label: 'Post Title' },
+ { key: 'depth', label: 'Depth', format: 'number' },
+ { key: 'is_submitter', label: 'Is Post Author', format: 'boolean' },
+ { key: 'distinguished', label: 'Distinguished' },
+];
+
+const commentFields: OutputSchema['fields'] = [
+ { key: 'kind', label: 'Kind' },
+ { key: 'id', label: 'Comment ID' },
+ { key: 'name', label: 'Fullname' },
+ { key: 'author', label: 'Author' },
+ { key: 'score', label: 'Score', format: 'number' },
+ { key: 'created_utc', label: 'Created At (Unix Seconds)', format: 'number' },
+ { key: 'edited', label: 'Edited' },
+ { key: 'permalink', label: 'Permalink' },
+ { key: 'subreddit', label: 'Subreddit' },
+ { key: 'stickied', label: 'Stickied', format: 'boolean' },
+ ...commentOnlyFields,
+];
+
+const postOrCommentFields: OutputSchema['fields'] = [...postFields, ...commentOnlyFields];
+
+const subredditFields: OutputSchema['fields'] = [
+ { key: 'kind', label: 'Kind' },
+ { key: 'id', label: 'Subreddit ID' },
+ { key: 'name', label: 'Fullname' },
+ { key: 'display_name', label: 'Name' },
+ { key: 'display_name_prefixed', label: 'Name (Prefixed)' },
+ { key: 'title', label: 'Title' },
+ { key: 'public_description', label: 'Public Description' },
+ { key: 'subscribers', label: 'Subscribers', format: 'number' },
+ { key: 'active_user_count', label: 'Active Users', format: 'number' },
+ { key: 'subreddit_type', label: 'Type' },
+ { key: 'submission_type', label: 'Allowed Submissions' },
+ { key: 'over18', label: 'NSFW', format: 'boolean' },
+ { key: 'lang', label: 'Language' },
+ { key: 'created_utc', label: 'Created At (Unix Seconds)', format: 'number' },
+ { key: 'url', label: 'Path' },
+ { key: 'user_is_subscriber', label: 'Subscribed', format: 'boolean' },
+ { key: 'user_is_moderator', label: 'Moderator', format: 'boolean' },
+];
+
+const userFields: OutputSchema['fields'] = [
+ { key: 'id', label: 'User ID' },
+ { key: 'name', label: 'Username' },
+ { key: 'link_karma', label: 'Post Karma', format: 'number' },
+ { key: 'comment_karma', label: 'Comment Karma', format: 'number' },
+ { key: 'total_karma', label: 'Total Karma', format: 'number' },
+ { key: 'created_utc', label: 'Created At (Unix Seconds)', format: 'number' },
+ { key: 'is_gold', label: 'Premium', format: 'boolean' },
+ { key: 'is_mod', label: 'Is Moderator', format: 'boolean' },
+ { key: 'verified', label: 'Verified', format: 'boolean' },
+ { key: 'has_verified_email', label: 'Verified Email', format: 'boolean' },
+ { key: 'is_employee', label: 'Reddit Employee', format: 'boolean' },
+ { key: 'icon_img', label: 'Avatar', format: 'image' },
+];
+
+const flairFields: OutputSchema['fields'] = [
+ { key: 'id', label: 'Flair Template ID' },
+ { key: 'text', label: 'Text' },
+ { key: 'text_editable', label: 'Text Editable', format: 'boolean' },
+ { key: 'type', label: 'Type' },
+ { key: 'mod_only', label: 'Mod Only', format: 'boolean' },
+ { key: 'allowable_content', label: 'Allowed Content' },
+ { key: 'max_emojis', label: 'Max Emojis', format: 'number' },
+ { key: 'background_color', label: 'Background Color' },
+ { key: 'text_color', label: 'Text Color' },
+];
+
+const rawPostFields: OutputSchema['fields'] = [
+ { key: 'id', label: 'Post ID' },
+ { key: 'name', label: 'Fullname' },
+ { key: 'title', label: 'Title' },
+ { key: 'author', label: 'Author' },
+ { key: 'subreddit', label: 'Subreddit' },
+ { key: 'selftext', label: 'Body Text' },
+ { key: 'selftext_html', label: 'Body HTML', format: 'html' },
+ { key: 'url', label: 'URL', format: 'url' },
+ { key: 'permalink', label: 'Permalink' },
+ { key: 'domain', label: 'Domain' },
+ { key: 'score', label: 'Score', format: 'number' },
+ { key: 'upvote_ratio', label: 'Upvote Ratio', format: 'number' },
+ { key: 'num_comments', label: 'Comment Count', format: 'number' },
+ { key: 'created_utc', label: 'Created At (Unix Seconds)', format: 'number' },
+ { key: 'is_self', label: 'Is Text Post', format: 'boolean' },
+ { key: 'is_video', label: 'Is Video', format: 'boolean' },
+ { key: 'over_18', label: 'NSFW', format: 'boolean' },
+ { key: 'spoiler', label: 'Spoiler', format: 'boolean' },
+ { key: 'locked', label: 'Locked', format: 'boolean' },
+ { key: 'stickied', label: 'Stickied', format: 'boolean' },
+ { key: 'link_flair_text', label: 'Flair Text' },
+];
+
+const rawCommentFields: OutputSchema['fields'] = [
+ { key: 'id', label: 'Comment ID' },
+ { key: 'name', label: 'Fullname' },
+ { key: 'author', label: 'Author' },
+ { key: 'body', label: 'Body' },
+ { key: 'body_html', label: 'Body HTML', format: 'html' },
+ { key: 'parent_id', label: 'Parent Fullname' },
+ { key: 'link_id', label: 'Post Fullname' },
+ { key: 'subreddit', label: 'Subreddit' },
+ { key: 'permalink', label: 'Permalink' },
+ { key: 'score', label: 'Score', format: 'number' },
+ { key: 'created_utc', label: 'Created At (Unix Seconds)', format: 'number' },
+];
+
+export const redditDeleteMessageOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'success', label: 'Success', format: 'boolean' },
+ { key: 'id', label: 'Fullname' },
+ ],
+};
+
+export const redditListMessagesOutputSchema: OutputSchema = {
+ fields: [
+ {
+ key: 'messages',
+ label: 'Messages',
+ labelKey: 'subject',
+ listItems: [
+ { key: 'kind', label: 'Kind' },
+ { key: 'id', label: 'Message ID' },
+ { key: 'name', label: 'Fullname' },
+ { key: 'author', label: 'From' },
+ { key: 'dest', label: 'To' },
+ { key: 'subject', label: 'Subject' },
+ { key: 'body', label: 'Body' },
+ { key: 'created_utc', label: 'Created At (Unix Seconds)', format: 'number' },
+ { key: 'new', label: 'Unread', format: 'boolean' },
+ { key: 'was_comment', label: 'Is Comment Reply', format: 'boolean' },
+ { key: 'parent_id', label: 'Parent Fullname' },
+ { key: 'first_message_name', label: 'Thread Fullname' },
+ { key: 'context', label: 'Context Path' },
+ { key: 'subreddit', label: 'Subreddit' },
+ { key: 'distinguished', label: 'Distinguished' },
+ ],
+ },
+ ...pagingFields,
+ ],
+};
+
+export const redditListPostFlairsOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'flairs', label: 'Flairs', labelKey: 'text', listItems: flairFields },
+ { key: 'count', label: 'Count', format: 'number' },
+ ],
+};
+
+export const redditSendMessageOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'success', label: 'Success', format: 'boolean' },
+ { key: 'to', label: 'To' },
+ { key: 'subject', label: 'Subject' },
+ ],
+};
+
+export const redditCreateCommentOutputSchema: OutputSchema = {
+ fields: commentFields,
+};
+
+export const redditCreatePostOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'id', label: 'Post ID' },
+ { key: 'name', label: 'Fullname' },
+ { key: 'url', label: 'URL', format: 'url' },
+ ],
+};
+
+export const redditListDuplicatesOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'post', label: 'Original Post', children: postFields },
+ { key: 'duplicates', label: 'Duplicates', labelKey: 'title', listItems: postFields },
+ ...pagingFields,
+ ],
+};
+
+export const redditEditTextOutputSchema: OutputSchema = {
+ fields: postOrCommentFields,
+};
+
+export const redditExpandMoreCommentsOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'comments', label: 'Comments', labelKey: 'author', listItems: commentFields },
+ { key: 'count', label: 'Count', format: 'number' },
+ { key: 'more', label: 'More Placeholders' },
+ ],
+};
+
+export const redditGetContentOutputSchema: OutputSchema = {
+ fields: [
+ {
+ key: 'items',
+ label: 'Items',
+ labelKey: 'name',
+ listItems: [
+ ...postOrCommentFields,
+ { key: 'display_name', label: 'Subreddit Name' },
+ { key: 'public_description', label: 'Subreddit Description' },
+ { key: 'subscribers', label: 'Subscribers', format: 'number' },
+ { key: 'subreddit_type', label: 'Subreddit Type' },
+ ],
+ },
+ { key: 'count', label: 'Count', format: 'number' },
+ ],
+};
+
+export const redditGetSubredditOutputSchema: OutputSchema = {
+ fields: subredditFields,
+};
+
+export const redditGetUserOutputSchema: OutputSchema = {
+ fields: [{ key: 'kind', label: 'Kind' }, ...userFields],
+};
+
+export const redditHidePostOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'success', label: 'Success', format: 'boolean' },
+ { key: 'ids', label: 'Fullnames' },
+ { key: 'hidden', label: 'Hidden', format: 'boolean' },
+ ],
+};
+
+export const redditSetInboxRepliesOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'success', label: 'Success', format: 'boolean' },
+ { key: 'id', label: 'Fullname' },
+ { key: 'inbox_replies', label: 'Inbox Replies Enabled', format: 'boolean' },
+ ],
+};
+
+export const redditGetMyKarmaOutputSchema: OutputSchema = {
+ fields: [
+ {
+ key: 'karma',
+ label: 'Karma by Subreddit',
+ labelKey: 'subreddit',
+ listItems: [
+ { key: 'subreddit', label: 'Subreddit' },
+ { key: 'link_karma', label: 'Post Karma', format: 'number' },
+ { key: 'comment_karma', label: 'Comment Karma', format: 'number' },
+ ],
+ },
+ { key: 'count', label: 'Count', format: 'number' },
+ ],
+};
+
+export const redditListPostsOutputSchema: OutputSchema = {
+ fields: [{ key: 'posts', label: 'Posts', labelKey: 'title', listItems: postFields }, ...pagingFields],
+};
+
+export const redditListSubredditsOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'subreddits', label: 'Subreddits', labelKey: 'display_name', listItems: subredditFields },
+ ...pagingFields,
+ ],
+};
+
+export const redditMarkAllMessagesReadOutputSchema: OutputSchema = {
+ fields: [{ key: 'success', label: 'Success', format: 'boolean' }],
+};
+
+export const redditMarkMessageReadOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'success', label: 'Success', format: 'boolean' },
+ { key: 'ids', label: 'Fullnames' },
+ { key: 'read', label: 'Read', format: 'boolean' },
+ ],
+};
+
+export const redditGetMeOutputSchema: OutputSchema = {
+ fields: [
+ ...userFields,
+ { key: 'inbox_count', label: 'Unread Inbox Count', format: 'number' },
+ { key: 'has_mail', label: 'Has Unread Mail', format: 'boolean' },
+ { key: 'over_18', label: 'NSFW Enabled', format: 'boolean' },
+ ],
+};
+
+export const redditListSubredditModeratorsOutputSchema: OutputSchema = {
+ fields: [
+ {
+ key: 'moderators',
+ label: 'Moderators',
+ labelKey: 'name',
+ listItems: [
+ { key: 'name', label: 'Username' },
+ { key: 'id', label: 'User Fullname' },
+ { key: 'mod_permissions', label: 'Permissions' },
+ { key: 'date', label: 'Added At (Unix Seconds)', format: 'number' },
+ ],
+ },
+ { key: 'count', label: 'Count', format: 'number' },
+ ],
+};
+
+export const redditListMySubredditsOutputSchema: OutputSchema = redditListSubredditsOutputSchema;
+
+export const redditListPostCommentsOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'post', label: 'Post', children: postFields },
+ { key: 'comments', label: 'Comments', labelKey: 'author', listItems: commentFields },
+ { key: 'count', label: 'Count', format: 'number' },
+ { key: 'more', label: 'More Placeholders' },
+ ],
+};
+
+export const redditGetPostRequirementsOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'is_flair_required', label: 'Flair Required', format: 'boolean' },
+ { key: 'title_text_min_length', label: 'Title Min Length', format: 'number' },
+ { key: 'title_text_max_length', label: 'Title Max Length', format: 'number' },
+ { key: 'title_required_strings', label: 'Title Required Strings' },
+ { key: 'title_blacklisted_strings', label: 'Title Banned Strings' },
+ { key: 'title_regexes', label: 'Title Regexes' },
+ { key: 'body_restriction_policy', label: 'Body Policy' },
+ { key: 'body_text_min_length', label: 'Body Min Length', format: 'number' },
+ { key: 'body_text_max_length', label: 'Body Max Length', format: 'number' },
+ { key: 'body_required_strings', label: 'Body Required Strings' },
+ { key: 'body_blacklisted_strings', label: 'Body Banned Strings' },
+ { key: 'body_regexes', label: 'Body Regexes' },
+ { key: 'link_restriction_policy', label: 'Link Policy' },
+ { key: 'domain_whitelist', label: 'Allowed Domains' },
+ { key: 'domain_blacklist', label: 'Banned Domains' },
+ { key: 'link_repost_age', label: 'Repost Age (Days)', format: 'number' },
+ { key: 'gallery_min_items', label: 'Gallery Min Items', format: 'number' },
+ { key: 'gallery_max_items', label: 'Gallery Max Items', format: 'number' },
+ { key: 'gallery_captions_requirement', label: 'Gallery Captions' },
+ { key: 'gallery_urls_requirement', label: 'Gallery URLs' },
+ { key: 'guidelines_text', label: 'Guidelines' },
+ { key: 'guidelines_display_policy', label: 'Guidelines Display Policy' },
+ ],
+};
+
+export const redditGetMyPreferencesOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'accept_pms', label: 'Accept Messages From' },
+ { key: 'country_code', label: 'Country Code' },
+ { key: 'lang', label: 'Language' },
+ { key: 'over_18', label: 'NSFW Enabled', format: 'boolean' },
+ { key: 'search_include_over_18', label: 'NSFW in Search', format: 'boolean' },
+ { key: 'label_nsfw', label: 'Label NSFW', format: 'boolean' },
+ { key: 'default_comment_sort', label: 'Default Comment Sort' },
+ { key: 'min_comment_score', label: 'Min Comment Score', format: 'number' },
+ { key: 'min_link_score', label: 'Min Post Score', format: 'number' },
+ { key: 'num_comments', label: 'Comments per Page', format: 'number' },
+ { key: 'media', label: 'Media Display' },
+ { key: 'media_preview', label: 'Media Preview' },
+ { key: 'video_autoplay', label: 'Video Autoplay', format: 'boolean' },
+ { key: 'nightmode', label: 'Night Mode', format: 'boolean' },
+ { key: 'enable_followers', label: 'Followers Enabled', format: 'boolean' },
+ { key: 'show_presence', label: 'Show Online Status', format: 'boolean' },
+ { key: 'hide_from_robots', label: 'Hidden From Search Engines', format: 'boolean' },
+ { key: 'public_votes', label: 'Public Votes', format: 'boolean' },
+ { key: 'profile_opt_out', label: 'Profile Opt Out', format: 'boolean' },
+ { key: 'threaded_messages', label: 'Threaded Messages', format: 'boolean' },
+ { key: 'email_messages', label: 'Email on Messages', format: 'boolean' },
+ { key: 'email_private_message', label: 'Email on Private Message', format: 'boolean' },
+ { key: 'email_digests', label: 'Email Digests', format: 'boolean' },
+ ],
+};
+
+export const redditReportContentOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'success', label: 'Success', format: 'boolean' },
+ { key: 'id', label: 'Fullname' },
+ { key: 'reason', label: 'Reason' },
+ ],
+};
+
+export const redditGetSubredditRulesOutputSchema: OutputSchema = {
+ fields: [
+ {
+ key: 'rules',
+ label: 'Rules',
+ labelKey: 'short_name',
+ listItems: [
+ { key: 'short_name', label: 'Rule' },
+ { key: 'description', label: 'Description' },
+ { key: 'kind', label: 'Applies To' },
+ { key: 'priority', label: 'Priority', format: 'number' },
+ { key: 'violation_reason', label: 'Report Reason' },
+ { key: 'created_utc', label: 'Created At (Unix Seconds)', format: 'number' },
+ ],
+ },
+ { key: 'count', label: 'Count', format: 'number' },
+ { key: 'site_rules', label: 'Site-wide Rules' },
+ ],
+};
+
+export const redditSaveContentOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'success', label: 'Success', format: 'boolean' },
+ { key: 'id', label: 'Fullname' },
+ { key: 'saved', label: 'Saved', format: 'boolean' },
+ ],
+};
+
+export const redditListSavedCategoriesOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'categories', label: 'Categories' },
+ { key: 'count', label: 'Count', format: 'number' },
+ ],
+};
+
+export const redditSearchUsersOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'users', label: 'Users', labelKey: 'name', listItems: [{ key: 'kind', label: 'Kind' }, ...userFields] },
+ ...pagingFields,
+ ],
+};
+
+export const redditSetPostFlairOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'success', label: 'Success', format: 'boolean' },
+ { key: 'post', label: 'Post Fullname' },
+ { key: 'flair_template_id', label: 'Flair Template ID' },
+ { key: 'text', label: 'Flair Text' },
+ ],
+};
+
+export const redditListSubredditCommentsOutputSchema: OutputSchema = {
+ fields: [{ key: 'comments', label: 'Comments', labelKey: 'author', listItems: commentFields }, ...pagingFields],
+};
+
+export const redditGetSubmitTextOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'subreddit', label: 'Subreddit' },
+ { key: 'submit_text', label: 'Submission Guidelines' },
+ { key: 'submit_text_html', label: 'Submission Guidelines HTML', format: 'html' },
+ ],
+};
+
+export const redditSubscribeSubredditOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'success', label: 'Success', format: 'boolean' },
+ { key: 'subreddit', label: 'Subreddit' },
+ { key: 'subscribed', label: 'Subscribed', format: 'boolean' },
+ ],
+};
+
+export const redditGetUserTrophiesOutputSchema: OutputSchema = {
+ fields: [
+ {
+ key: 'trophies',
+ label: 'Trophies',
+ labelKey: 'name',
+ listItems: [
+ { key: 'id', label: 'Trophy ID' },
+ { key: 'name', label: 'Name' },
+ { key: 'description', label: 'Description' },
+ { key: 'award_id', label: 'Award ID' },
+ { key: 'granted_at', label: 'Granted At (Unix Seconds)', format: 'number' },
+ { key: 'url', label: 'URL', format: 'url' },
+ { key: 'icon_70', label: 'Icon', format: 'image' },
+ ],
+ },
+ { key: 'count', label: 'Count', format: 'number' },
+ ],
+};
+
+export const redditListUserFlairsOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'flairs', label: 'Flairs' },
+ { key: 'count', label: 'Count', format: 'number' },
+ ],
+};
+
+export const redditListUserContentOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'items', label: 'Items', labelKey: 'name', listItems: postOrCommentFields },
+ ...pagingFields,
+ ],
+};
+
+export const redditGetWikiPageOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'subreddit', label: 'Subreddit' },
+ { key: 'page', label: 'Page' },
+ { key: 'content_md', label: 'Content (Markdown)' },
+ { key: 'revision_id', label: 'Revision ID' },
+ { key: 'revision_date', label: 'Revised At (Unix Seconds)', format: 'number' },
+ { key: 'revision_by', label: 'Revised By' },
+ { key: 'may_revise', label: 'Can Edit', format: 'boolean' },
+ ],
+};
+
+export const redditListWikiPagesOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'pages', label: 'Page Names' },
+ { key: 'count', label: 'Count', format: 'number' },
+ ],
+};
+
+export const createRedditCommentOutputSchema: OutputSchema = rawThingsResponse({ dataFields: rawCommentFields });
+
+export const editRedditPostOutputSchema: OutputSchema = rawThingsResponse({ dataFields: rawPostFields });
+
+export const createRedditPostOutputSchema: OutputSchema = {
+ fields: [
+ {
+ key: 'json',
+ label: 'Response',
+ children: [
+ { key: 'errors', label: 'Errors' },
+ {
+ key: 'data',
+ label: 'Data',
+ children: [
+ { key: 'id', label: 'Post ID' },
+ { key: 'name', label: 'Fullname' },
+ { key: 'url', label: 'URL', format: 'url' },
+ ],
+ },
+ ],
+ },
+ ],
+};
+
+export const deleteRedditContentOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'success', label: 'Success', format: 'boolean' },
+ { key: 'response', label: 'Response' },
+ ],
+};
+
+export const fetchPostCommentsOutputSchema: OutputSchema = {
+ itemLabel: '{author}',
+ fields: [
+ {
+ key: 'comments',
+ label: 'Comments',
+ value: '',
+ listItems: [
+ { key: 'id', label: 'Comment ID' },
+ { key: 'author', label: 'Author' },
+ { key: 'body', label: 'Body' },
+ { key: 'score', label: 'Score', format: 'number' },
+ { key: 'created_utc', label: 'Created At (Unix Seconds)', format: 'number' },
+ { key: 'permalink', label: 'Permalink' },
+ { key: 'edited', label: 'Edited' },
+ { key: 'is_submitter', label: 'Is Post Author', format: 'boolean' },
+ { key: 'stickied', label: 'Stickied', format: 'boolean' },
+ { key: 'replies', label: 'Replies' },
+ ],
+ },
+ ],
+};
+
+export const getRedditPostDetailsOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'id', label: 'Post ID' },
+ { key: 'title', label: 'Title' },
+ { key: 'author', label: 'Author' },
+ { key: 'author_fullname', label: 'Author Fullname' },
+ { key: 'subreddit', label: 'Subreddit' },
+ { key: 'subreddit_id', label: 'Subreddit Fullname' },
+ { key: 'selftext', label: 'Body Text' },
+ { key: 'selftext_html', label: 'Body HTML', format: 'html' },
+ { key: 'score', label: 'Score', format: 'number' },
+ { key: 'upvote_ratio', label: 'Upvote Ratio', format: 'number' },
+ { key: 'created_utc', label: 'Created At (Unix Seconds)', format: 'number' },
+ { key: 'permalink', label: 'Permalink' },
+ { key: 'url', label: 'URL', format: 'url' },
+ { key: 'domain', label: 'Domain' },
+ { key: 'num_comments', label: 'Comment Count', format: 'number' },
+ { key: 'is_self', label: 'Is Text Post', format: 'boolean' },
+ { key: 'is_video', label: 'Is Video', format: 'boolean' },
+ { key: 'is_original_content', label: 'Original Content', format: 'boolean' },
+ { key: 'over_18', label: 'NSFW', format: 'boolean' },
+ { key: 'spoiler', label: 'Spoiler', format: 'boolean' },
+ { key: 'locked', label: 'Locked', format: 'boolean' },
+ { key: 'stickied', label: 'Stickied', format: 'boolean' },
+ ],
+};
+
+export const retrieveRedditPostOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'kind', label: 'Kind' },
+ {
+ key: 'data',
+ label: 'Listing',
+ children: [
+ { key: 'after', label: 'Next Page Cursor' },
+ { key: 'before', label: 'Previous Page Cursor' },
+ { key: 'dist', label: 'Count', format: 'number' },
+ {
+ key: 'children',
+ label: 'Posts',
+ listItems: [
+ { key: 'kind', label: 'Kind' },
+ { key: 'data', label: 'Post', children: rawPostFields },
+ ],
+ },
+ ],
+ },
+ ],
+};
+
+function rawThingsResponse({ dataFields }: { dataFields: OutputSchema['fields'] }): OutputSchema {
+ return {
+ fields: [
+ {
+ key: 'json',
+ label: 'Response',
+ children: [
+ { key: 'errors', label: 'Errors' },
+ {
+ key: 'data',
+ label: 'Data',
+ children: [
+ {
+ key: 'things',
+ label: 'Things',
+ listItems: [
+ { key: 'kind', label: 'Kind' },
+ { key: 'data', label: 'Data', children: dataFields },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ };
+}