Skip to content

Commit 969758e

Browse files
Joan Reyeromariobalca
andauthored
Reddit integration (#351)
Co-authored-by: Mário Balça <mario.balca@gmail.com>
1 parent aa3dffb commit 969758e

48 files changed

Lines changed: 1676 additions & 47 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

backend/.env.dist.local

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,14 @@ CROWD_GITHUB_CLIENT_SECRET=
119119
CROWD_GITHUB_PRIVATE_KEY=
120120
CROWD_GITHUB_WEBHOOK_SECRET=
121121

122+
# Pizzly settings
123+
CROWD_PIZZLY_URL=http://pizzly:3003
124+
CROWD_PIZZLY_SECRET_KEY=424242
125+
CROWD_PIZZLY_INTEGRATIONS=reddit
126+
122127
# Cohere settings
123128
CROWD_COHERE_API_KEY=
124129

125130
# Vector settings
126-
CROWD_VECTOR_API_KEY=
127-
CROWD_VECTOR_INDEX=
131+
CROWD_QDRANT_HOST=qdrant
132+
CROWD_QDRANT_PORT=6333

backend/config/custom-environment-variables.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,9 @@
126126
"clientSecret": "CROWD_GITHUB_CLIENT_SECRET",
127127
"privateKey": "CROWD_GITHUB_PRIVATE_KEY",
128128
"webhookSecret": "CROWD_GITHUB_WEBHOOK_SECRET"
129+
},
130+
"pizzly": {
131+
"url": "CROWD_PIZZLY_URL",
132+
"secretKey": "CROWD_PIZZLY_SECRET_KEY"
129133
}
130134
}

backend/package-lock.json

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"@aws-sdk/client-comprehend": "^3.159.0",
3434
"@cubejs-client/core": "^0.30.4",
3535
"@google-cloud/storage": "5.3.0",
36+
"@nangohq/pizzly-node": "^0.3.6",
3637
"@octokit/auth-app": "^3.6.1",
3738
"@octokit/graphql": "^4.8.0",
3839
"@octokit/request": "^5.6.3",
@@ -63,6 +64,7 @@
6364
"express": "4.17.1",
6465
"express-rate-limit": "6.5.1",
6566
"formidable-serverless": "1.1.1",
67+
"he": "^1.2.0",
6668
"helmet": "4.1.1",
6769
"html-to-text": "^8.2.1",
6870
"jsonwebtoken": "8.5.1",
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Permissions from '../../../security/permissions'
2+
import IntegrationService from '../../../services/integrationService'
3+
import PermissionChecker from '../../../services/user/permissionChecker'
4+
5+
export default async (req, res) => {
6+
new PermissionChecker(req).validateHas(Permissions.values.tenantEdit)
7+
const payload = await new IntegrationService(req).redditOnboard(req.body.subreddits)
8+
await req.responseHandler.success(req, res, payload)
9+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import axios from 'axios'
2+
import Error400 from '../../../errors/Error400'
3+
import Permissions from '../../../security/permissions'
4+
import PermissionChecker from '../../../services/user/permissionChecker'
5+
import track from '../../../segment/track'
6+
7+
export default async (req, res) => {
8+
new PermissionChecker(req).validateHasAny([
9+
Permissions.values.integrationCreate,
10+
Permissions.values.integrationEdit,
11+
])
12+
13+
if (req.query.subreddit) {
14+
try {
15+
const result = await axios.get(
16+
`https://www.reddit.com/r/${req.query.subreddit}/new.json?limit=1`,
17+
)
18+
if (
19+
result.status === 200 &&
20+
result.data.data.children &&
21+
result.data.data.children.length > 0
22+
) {
23+
console.log('here')
24+
track(
25+
'Reddit: subreddit input',
26+
{
27+
subreddit: req.query.subreddit,
28+
valid: true,
29+
},
30+
{ ...req },
31+
)
32+
return req.responseHandler.success(req, res, result.data.data.children)
33+
}
34+
} catch (e) {
35+
track(
36+
'Reddit: subreddit input',
37+
{
38+
subreddit: req.query.subreddit,
39+
valid: false,
40+
},
41+
{ ...req },
42+
)
43+
return req.responseHandler.error(req, res, new Error400(req.language))
44+
}
45+
}
46+
track(
47+
'Reddit: subreddit input',
48+
{
49+
subreddit: req.query.subreddit,
50+
valid: false,
51+
},
52+
{ ...req },
53+
)
54+
return req.responseHandler.error(req, res, new Error400(req.language))
55+
}

backend/src/api/integration/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@ export default (app) => {
2525
`/discord-authenticate/:tenantId/:guild_id`,
2626
safeWrap(require('./helpers/discordAuthenticate').default),
2727
)
28+
app.put(`/reddit-onboard/:tenantId`, safeWrap(require('./helpers/redditOnboard').default))
2829
app.get(
2930
'/tenant/:tenantId/devto-validate',
3031
safeWrap(require('./helpers/devtoValidators').default),
3132
)
33+
app.get(
34+
'/tenant/:tenantId/reddit-validate',
35+
safeWrap(require('./helpers/redditValidator').default),
36+
)
3237
app.post(
3338
'/tenant/:tenantId/devto-connect',
3439
safeWrap(require('./helpers/devtoCreateOrUpdate').default),

backend/src/api/member/memberQuery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default async (req, res) => {
2323

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

26-
if (req.query.filter && Object.keys(req.query.filter).length > 0) {
26+
if (req.body.filter && Object.keys(req.body.filter).length > 0) {
2727
track('Member Advanced Fitler', { ...payload }, { ...req })
2828
}
2929

backend/src/config/configTypes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,8 @@ export interface CubeJSConfiguration {
168168
jwtSecret: string
169169
jwtExpiry: string
170170
}
171+
172+
export interface PizzlyConfiguration {
173+
url: string
174+
secretKey: string
175+
}

backend/src/config/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
DevtoConfiguration,
2323
RedisConfiguration,
2424
PosthogConfiguration,
25+
PizzlyConfiguration,
2526
} from './configTypes'
2627

2728
// TODO-kube
@@ -216,3 +217,10 @@ export const CUBEJS_CONFIG: CubeJSConfiguration = KUBE_MODE
216217
jwtSecret: process.env.CUBE_JS_JWT_SECRET,
217218
jwtExpiry: process.env.CUBE_JS_JWT_EXPIRY,
218219
}
220+
221+
export const PIZZLY_CONFIG: PizzlyConfiguration = KUBE_MODE
222+
? config.get<PizzlyConfiguration>('pizzly')
223+
: {
224+
url: process.env.PIZZLY_URL,
225+
secretKey: process.env.PIZZLY_SECRET_KEY,
226+
}

0 commit comments

Comments
 (0)