Skip to content

Commit

Permalink
Reddit integration (#351)
Browse files Browse the repository at this point in the history
Co-authored-by: Mário Balça <[email protected]>
  • Loading branch information
Joan Reyero and mariobalca authored Dec 19, 2022
1 parent aa3dffb commit 969758e
Show file tree
Hide file tree
Showing 48 changed files with 1,676 additions and 47 deletions.
9 changes: 7 additions & 2 deletions backend/.env.dist.local
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,14 @@ CROWD_GITHUB_CLIENT_SECRET=
CROWD_GITHUB_PRIVATE_KEY=
CROWD_GITHUB_WEBHOOK_SECRET=

# Pizzly settings
CROWD_PIZZLY_URL=http://pizzly:3003
CROWD_PIZZLY_SECRET_KEY=424242
CROWD_PIZZLY_INTEGRATIONS=reddit

# Cohere settings
CROWD_COHERE_API_KEY=

# Vector settings
CROWD_VECTOR_API_KEY=
CROWD_VECTOR_INDEX=
CROWD_QDRANT_HOST=qdrant
CROWD_QDRANT_PORT=6333
4 changes: 4 additions & 0 deletions backend/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,9 @@
"clientSecret": "CROWD_GITHUB_CLIENT_SECRET",
"privateKey": "CROWD_GITHUB_PRIVATE_KEY",
"webhookSecret": "CROWD_GITHUB_WEBHOOK_SECRET"
},
"pizzly": {
"url": "CROWD_PIZZLY_URL",
"secretKey": "CROWD_PIZZLY_SECRET_KEY"
}
}
66 changes: 66 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@aws-sdk/client-comprehend": "^3.159.0",
"@cubejs-client/core": "^0.30.4",
"@google-cloud/storage": "5.3.0",
"@nangohq/pizzly-node": "^0.3.6",
"@octokit/auth-app": "^3.6.1",
"@octokit/graphql": "^4.8.0",
"@octokit/request": "^5.6.3",
Expand Down Expand Up @@ -63,6 +64,7 @@
"express": "4.17.1",
"express-rate-limit": "6.5.1",
"formidable-serverless": "1.1.1",
"he": "^1.2.0",
"helmet": "4.1.1",
"html-to-text": "^8.2.1",
"jsonwebtoken": "8.5.1",
Expand Down
9 changes: 9 additions & 0 deletions backend/src/api/integration/helpers/redditOnboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Permissions from '../../../security/permissions'
import IntegrationService from '../../../services/integrationService'
import PermissionChecker from '../../../services/user/permissionChecker'

export default async (req, res) => {
new PermissionChecker(req).validateHas(Permissions.values.tenantEdit)
const payload = await new IntegrationService(req).redditOnboard(req.body.subreddits)
await req.responseHandler.success(req, res, payload)
}
55 changes: 55 additions & 0 deletions backend/src/api/integration/helpers/redditValidator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import axios from 'axios'
import Error400 from '../../../errors/Error400'
import Permissions from '../../../security/permissions'
import PermissionChecker from '../../../services/user/permissionChecker'
import track from '../../../segment/track'

export default async (req, res) => {
new PermissionChecker(req).validateHasAny([
Permissions.values.integrationCreate,
Permissions.values.integrationEdit,
])

if (req.query.subreddit) {
try {
const result = await axios.get(
`https://www.reddit.com/r/${req.query.subreddit}/new.json?limit=1`,
)
if (
result.status === 200 &&
result.data.data.children &&
result.data.data.children.length > 0
) {
console.log('here')
track(
'Reddit: subreddit input',
{
subreddit: req.query.subreddit,
valid: true,
},
{ ...req },
)
return req.responseHandler.success(req, res, result.data.data.children)
}
} catch (e) {
track(
'Reddit: subreddit input',
{
subreddit: req.query.subreddit,
valid: false,
},
{ ...req },
)
return req.responseHandler.error(req, res, new Error400(req.language))
}
}
track(
'Reddit: subreddit input',
{
subreddit: req.query.subreddit,
valid: false,
},
{ ...req },
)
return req.responseHandler.error(req, res, new Error400(req.language))
}
5 changes: 5 additions & 0 deletions backend/src/api/integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ export default (app) => {
`/discord-authenticate/:tenantId/:guild_id`,
safeWrap(require('./helpers/discordAuthenticate').default),
)
app.put(`/reddit-onboard/:tenantId`, safeWrap(require('./helpers/redditOnboard').default))
app.get(
'/tenant/:tenantId/devto-validate',
safeWrap(require('./helpers/devtoValidators').default),
)
app.get(
'/tenant/:tenantId/reddit-validate',
safeWrap(require('./helpers/redditValidator').default),
)
app.post(
'/tenant/:tenantId/devto-connect',
safeWrap(require('./helpers/devtoCreateOrUpdate').default),
Expand Down
2 changes: 1 addition & 1 deletion backend/src/api/member/memberQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default async (req, res) => {

const payload = await new MemberService(req).query(req.body)

if (req.query.filter && Object.keys(req.query.filter).length > 0) {
if (req.body.filter && Object.keys(req.body.filter).length > 0) {
track('Member Advanced Fitler', { ...payload }, { ...req })
}

Expand Down
5 changes: 5 additions & 0 deletions backend/src/config/configTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,8 @@ export interface CubeJSConfiguration {
jwtSecret: string
jwtExpiry: string
}

export interface PizzlyConfiguration {
url: string
secretKey: string
}
8 changes: 8 additions & 0 deletions backend/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
DevtoConfiguration,
RedisConfiguration,
PosthogConfiguration,
PizzlyConfiguration,
} from './configTypes'

// TODO-kube
Expand Down Expand Up @@ -216,3 +217,10 @@ export const CUBEJS_CONFIG: CubeJSConfiguration = KUBE_MODE
jwtSecret: process.env.CUBE_JS_JWT_SECRET,
jwtExpiry: process.env.CUBE_JS_JWT_EXPIRY,
}

export const PIZZLY_CONFIG: PizzlyConfiguration = KUBE_MODE
? config.get<PizzlyConfiguration>('pizzly')
: {
url: process.env.PIZZLY_URL,
secretKey: process.env.PIZZLY_SECRET_KEY,
}
20 changes: 20 additions & 0 deletions backend/src/database/attributes/member/reddit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Attribute } from '../attribute'
import { AttributeType } from '../types'
import { MemberAttributes, MemberAttributeName } from './enums'

export const RedditMemberAttributes: Attribute[] = [
{
name: MemberAttributes[MemberAttributeName.SOURCE_ID].name,
label: MemberAttributes[MemberAttributeName.SOURCE_ID].label,
type: AttributeType.STRING,
canDelete: false,
show: false,
},
{
name: MemberAttributes[MemberAttributeName.URL].name,
label: MemberAttributes[MemberAttributeName.URL].label,
type: AttributeType.URL,
canDelete: false,
show: true,
},
]
13 changes: 13 additions & 0 deletions backend/src/serverless/integrations/grid/redditGrid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { gridEntry } from './grid'

export class RedditGrid {
static post: gridEntry = {
score: 10,
isKeyAction: true,
}

static comment: gridEntry = {
score: 6,
isKeyAction: true,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { DiscordIntegrationService } from './integrations/discordIntegrationServ
import { IIntegrationStream, IStepContext } from '../../../types/integration/stepResult'
import { TwitterIntegrationService } from './integrations/twitterIntegrationService'
import { HackerNewsIntegrationService } from './integrations/hackerNewsIntegrationService'
import { RedditIntegrationService } from './integrations/redditIntegrationService'
import { TwitterReachIntegrationService } from './integrations/twitterReachIntegrationService'
import { SlackIntegrationService } from './integrations/slackIntegrationService'
import { GithubIntegrationService } from './integrations/githubIntegrationService'
Expand All @@ -45,6 +46,7 @@ export class IntegrationProcessor extends LoggingBase {
new DevtoIntegrationService(),
new DiscordIntegrationService(),
new HackerNewsIntegrationService(),
new RedditIntegrationService(),
new TwitterIntegrationService(),
new TwitterReachIntegrationService(),
new SlackIntegrationService(),
Expand Down
Loading

0 comments on commit 969758e

Please sign in to comment.