Skip to content

2530 - add reddit component #2714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions docs/content/docs/reference/components/reddit.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
title: "Reddit"
description: "Reddit is a social news aggregation, discussion, and content-sharing platform where users post and vote on content organized into communities called subreddits."
---

Reddit is a social news aggregation, discussion, and content-sharing platform where users post and vote on content organized into communities called subreddits.


Categories: Social Media


Type: reddit/v1

<hr />



## Connections

Version: 1


### OAuth2 Authorization Code

#### Properties

| Name | Label | Type | Description | Required |
|:---------------:|:--------------:|:------------:|:-------------------:|:--------:|
| clientId | Client Id | STRING | | true |
| clientSecret | Client Secret | STRING | | true |





<hr />



## Actions


### Create Comment
Name: createComment

`Creates a new comment on a Reddit post or comment.`

#### Properties

| Name | Label | Type | Description | Required |
|:---------------:|:--------------:|:------------:|:-------------------:|:--------:|
| thing_id | Parent ID | STRING | `Fullname of parent (post ID or comment ID to reply to).` | true |
| text | Comment Text | STRING | `Comment text.` | true |

#### Example JSON Structure
```json
{
"label" : "Create Comment",
"name" : "createComment",
"parameters" : {
"thing_id" : "",
"text" : ""
},
"type" : "reddit/v1/createComment"
}
```

#### Output

The output for this action is dynamic and may vary depending on the input parameters. To determine the exact structure of the output, you need to execute the action.




### Create Post
Name: createPost

`Creates new reddit post.`

#### Properties

| Name | Label | Type | Description | Required |
|:---------------:|:--------------:|:------------:|:-------------------:|:--------:|
| sr | Subreddit Name | STRING | `Subreddit name.` | true |
| title | Title | STRING | `Post title.` | true |
| kind | Kind | STRING <details> <summary> Options </summary> link, self </details> | `Type of post.` | true |
| url | URL | STRING | `Link URL.` | true |
| text | Text | STRING | `Post text.` | true |

#### Example JSON Structure
```json
{
"label" : "Create Post",
"name" : "createPost",
"parameters" : {
"sr" : "",
"title" : "",
"kind" : "",
"url" : "",
"text" : ""
},
"type" : "reddit/v1/createPost"
}
```

#### Output

The output for this action is dynamic and may vary depending on the input parameters. To determine the exact structure of the output, you need to execute the action.






1 change: 1 addition & 0 deletions server/apps/server-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ dependencies {
implementation(project(":server:libs:modules:components:rabbitmq"))
implementation(project(":server:libs:modules:components:random-helper"))
implementation(project(":server:libs:modules:components:reckon"))
implementation(project(":server:libs:modules:components:reddit"))
implementation(project(":server:libs:modules:components:resend"))
implementation(project(":server:libs:modules:components:request"))
implementation(project(":server:libs:modules:components:rocketchat"))
Expand Down
1 change: 1 addition & 0 deletions server/ee/apps/worker-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ dependencies {
implementation(project(":server:libs:modules:components:rabbitmq"))
implementation(project(":server:libs:modules:components:random-helper"))
implementation(project(":server:libs:modules:components:reckon"))
implementation(project(":server:libs:modules:components:reddit"))
implementation(project(":server:libs:modules:components:resend"))
implementation(project(":server:libs:modules:components:request"))
implementation(project(":server:libs:modules:components:rocketchat"))
Expand Down
5 changes: 5 additions & 0 deletions server/libs/modules/components/reddit/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version="1.0"

dependencies {
implementation(project(":server:libs:core:commons:commons-util"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2025 ByteChef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bytechef.component.reddit;

import static com.bytechef.component.definition.ComponentDsl.component;
import static com.bytechef.component.definition.ComponentDsl.tool;

import com.bytechef.component.ComponentHandler;
import com.bytechef.component.definition.ComponentCategory;
import com.bytechef.component.definition.ComponentDefinition;
import com.bytechef.component.reddit.action.RedditCreateCommentAction;
import com.bytechef.component.reddit.action.RedditCreatePostAction;
import com.bytechef.component.reddit.connection.RedditConnection;
import com.google.auto.service.AutoService;

/**
* @author Marija Horvat
*/
@AutoService(ComponentHandler.class)
public class RedditComponentHandler implements ComponentHandler {

private static final ComponentDefinition COMPONENT_DEFINITION = component("reddit")
.title("Reddit")
.description(
"Reddit is a social news aggregation, discussion, and content-sharing platform where users post and vote on content organized into communities called subreddits.")
.icon("path:assets/reddit.svg")
.customAction(true)
.categories(ComponentCategory.SOCIAL_MEDIA)
.connection(RedditConnection.CONNECTION_DEFINITION)
.actions(
RedditCreateCommentAction.ACTION_DEFINITION,
RedditCreatePostAction.ACTION_DEFINITION)
.clusterElements(
tool(RedditCreateCommentAction.ACTION_DEFINITION),
tool(RedditCreatePostAction.ACTION_DEFINITION));

@Override
public ComponentDefinition getDefinition() {
return COMPONENT_DEFINITION;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2025 ByteChef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bytechef.component.reddit.action;

import static com.bytechef.component.definition.ComponentDsl.action;
import static com.bytechef.component.definition.ComponentDsl.string;
import static com.bytechef.component.definition.Context.Http.responseType;
import static com.bytechef.component.reddit.constant.RedditConstants.TEXT;
import static com.bytechef.component.reddit.constant.RedditConstants.THING_ID;

import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
import com.bytechef.component.definition.Context;
import com.bytechef.component.definition.Context.Http.Body;
import com.bytechef.component.definition.Context.Http.ResponseType;
import com.bytechef.component.definition.Parameters;
import com.bytechef.component.definition.TypeReference;

/**
* @author Marija Horvat
*/
public class RedditCreateCommentAction {

public static final ModifiableActionDefinition ACTION_DEFINITION = action("createComment")
.title("Create Comment")
.description("Creates a new comment on a Reddit post or comment.")
.properties(
string(THING_ID)
.label("Parent ID")
.description("Fullname of parent (post ID or comment ID to reply to).")
.required(true),
string(TEXT)
.label("Comment Text")
.description("Comment text.")
.required(true))
.output()
.perform(RedditCreateCommentAction::perform);

private RedditCreateCommentAction() {
}

public static Object perform(Parameters inputParameters, Parameters connectionParameters, Context context) {

return context.http(http -> http.post("/comment"))
.body(Body.of(
THING_ID, inputParameters.getRequiredString(THING_ID),
TEXT, inputParameters.getRequiredString(TEXT)))
.configuration(responseType(ResponseType.JSON))
.execute()
.getBody(new TypeReference<>() {});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2025 ByteChef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bytechef.component.reddit.action;

import static com.bytechef.component.definition.ComponentDsl.action;
import static com.bytechef.component.definition.ComponentDsl.option;
import static com.bytechef.component.definition.ComponentDsl.string;
import static com.bytechef.component.definition.Context.Http.responseType;
import static com.bytechef.component.reddit.constant.RedditConstants.KIND;
import static com.bytechef.component.reddit.constant.RedditConstants.SUBREDDIT_NAME;
import static com.bytechef.component.reddit.constant.RedditConstants.TEXT;
import static com.bytechef.component.reddit.constant.RedditConstants.TITLE;
import static com.bytechef.component.reddit.constant.RedditConstants.URL;

import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
import com.bytechef.component.definition.Context;
import com.bytechef.component.definition.Context.Http.Body;
import com.bytechef.component.definition.Context.Http.ResponseType;
import com.bytechef.component.definition.Parameters;
import com.bytechef.component.definition.TypeReference;

/**
* @author Marija Horvat
*/
public class RedditCreatePostAction {

public static final ModifiableActionDefinition ACTION_DEFINITION = action("createPost")
.title("Create Post")
.description("Creates new reddit post.")
.properties(
string(SUBREDDIT_NAME)
.label("Subreddit Name")
.description("Subreddit name.")
.required(true),
string(TITLE)
.label("Title")
.description("Post title.")
.required(true),
string(KIND)
.label("Kind")
.description("Type of post.")
.options(option("Link", "link"), option("Self", "self"))
.required(true),
string(URL)
.label("URL")
.description("Link URL.")
.required(true)
.displayCondition("%s == '%s'".formatted(KIND, "link")),
string(TEXT)
.label("Text")
.description("Post text.")
.required(true)
.displayCondition("%s == '%s'".formatted(KIND, "self")))
.output()
.perform(RedditCreatePostAction::perform);

private RedditCreatePostAction() {
}

public static Object perform(Parameters inputParameters, Parameters connectionParameters, Context context) {

return context.http(http -> http.post("/submit"))
.body(Body.of(
SUBREDDIT_NAME, inputParameters.getRequiredString(SUBREDDIT_NAME),
TITLE, inputParameters.getRequiredString(TITLE),
KIND, inputParameters.getRequiredString(KIND),
URL, inputParameters.getString(URL),
TEXT, inputParameters.getString(TEXT)))
.configuration(responseType(ResponseType.JSON))
.execute()
.getBody(new TypeReference<>() {});
}
}
Loading