Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
ad3d7de
chore: add passport-reddit
pbkompasz Mar 10, 2025
8dbcc43
feat: reddit oauth
pbkompasz Mar 10, 2025
d9ddb8e
feat: api starter
pbkompasz Mar 11, 2025
e6cd535
feat: api fetch subreddits, profile
pbkompasz Mar 12, 2025
2d73608
feat: getUser
pbkompasz Mar 20, 2025
72036a4
feat: chat handler
pbkompasz Mar 26, 2025
04bd0d8
feat: getComments
pbkompasz Mar 27, 2025
c06d9dd
feat: chat handler
pbkompasz Mar 27, 2025
ecd92af
feat: user cache
pbkompasz Mar 27, 2025
bd25e82
chore: types
pbkompasz Mar 27, 2025
7885efe
chore: tests
pbkompasz May 2, 2025
b3d7521
chore: devvit package
pbkompasz May 3, 2025
29d6fa7
chore: yarn
pbkompasz May 3, 2025
452e975
chore:
pbkompasz May 3, 2025
fbee8d1
chore: merge
pbkompasz May 3, 2025
8d2f9c8
Merge branch 'main' into feat-reddit-connector
pbkompasz May 3, 2025
0462305
chore: yarn
pbkompasz May 3, 2025
38e620f
chore: remove devvit
pbkompasz May 5, 2025
cbc3a15
chore: move types
pbkompasz May 6, 2025
aaf4720
chore: move types
pbkompasz May 6, 2025
228f267
chore: add subreddit
pbkompasz May 6, 2025
e35a9ba
chore: add message types
pbkompasz May 6, 2025
9ae7485
feat: add methods
pbkompasz May 6, 2025
93bdc74
chore: update readme
pbkompasz May 6, 2025
072dc67
feat: api tests
pbkompasz May 6, 2025
54abb37
chore: move dir
pbkompasz May 6, 2025
e12543e
chore: add scopes
pbkompasz May 7, 2025
9f76002
chore: rename handler
pbkompasz May 7, 2025
fa648b0
chore: refactor types
pbkompasz May 7, 2025
02d4153
feat: add pagination
pbkompasz May 7, 2025
b7d79f7
fix: pagination
pbkompasz May 7, 2025
9fb1bad
chore: rename and fix types
pbkompasz May 7, 2025
8073ffb
chore: it works!!!
pbkompasz May 7, 2025
56cb704
chore: rename readme
pbkompasz May 7, 2025
093b0cb
chore: use proper type
pbkompasz May 7, 2025
ff810ed
chore: use proper type
pbkompasz May 7, 2025
7f6b45a
chore: add handlers
pbkompasz May 7, 2025
79e12fa
chore: message handler tests
pbkompasz May 7, 2025
2a18640
feat: request config types
pbkompasz May 8, 2025
8702df7
feat: forum and comment schema
pbkompasz May 8, 2025
b1fbcb3
chore: add name field
pbkompasz May 8, 2025
dcbc474
feat: add comments
pbkompasz May 8, 2025
e18f9b8
chore: add schema
pbkompasz May 8, 2025
97ccee6
chore: remove field
pbkompasz May 8, 2025
2375118
feat: posts
pbkompasz May 8, 2025
cf14a10
feat: api tests pass
pbkompasz May 8, 2025
74bfaf0
chore: add types
pbkompasz May 9, 2025
8907dd9
chore: udpate types
pbkompasz May 9, 2025
3d6c5c7
feat: add backdate
pbkompasz May 9, 2025
df9da19
chore: rename
pbkompasz May 9, 2025
9920b60
chore: add icon
pbkompasz May 9, 2025
9904e52
feat: tests pass
pbkompasz May 9, 2025
0285c0f
feat: add fetch limmit + log4js
pbkompasz May 9, 2025
305bd0d
chore: add sampel config file
pbkompasz May 9, 2025
f02f975
fix: add params
pbkompasz May 9, 2025
7e5aba1
feat: posts works
pbkompasz May 9, 2025
4cb2d85
feat: comment handlers work
pbkompasz May 9, 2025
c024721
chore: final cleanup
pbkompasz May 9, 2025
01db773
chore: posts tests pass
pbkompasz May 9, 2025
e01c500
feat: subreddit handler
pbkompasz May 9, 2025
72672a0
chore: cleanups
pbkompasz May 9, 2025
0d3e922
chore: tests
pbkompasz May 9, 2025
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
Binary file added assets/reddit/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"core-cli": "node node_modules/@verida/cli-tools/dist/exec.js",
"dev": "yarn build && yarn symlink-static && nodemon src/server.js",
"symlink-static": "rm -rf dist/web && ln -s ../src/web dist/web",
"build": "rm -rf dist && tsc && rm -rf dist/assets && cp -R assets dist/ && cp -R src/web dist/web",
"build": "rm -rf dist && tsc --noCheck && rm -rf dist/assets && cp -R assets dist/ && cp -R src/web dist/web",
"prestart": "yarn build",
"start": "node dist/server.js",
"tests": "ts-mocha './tests/**/*.ts'",
Expand Down Expand Up @@ -92,6 +92,7 @@
"passport": "^0.5.2",
"passport-facebook": "^3.0.0",
"passport-google-oauth20": "^2.0.0",
"passport-reddit": "^1.1.0",
"pdf-parse": "^1.1.1",
"sanitize-html": "^2.13.1",
"string-strip-html": "8.5.0",
Expand Down
57 changes: 57 additions & 0 deletions src/providers/reddit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Reddit Connector

The Reddit connector fetches a user's personal reddit data from the past 3 months.

## Handlers

## Known issues

1. Private chat messages are not supported in the official API, see [here](https://www.reddit.com/r/redditdev/comments/17s83sf/chat_api/)

## Refresh Tokens

<!-- TODO -->

## Unit Tests

This repository contains a suite of unit tests designed to test the core Reddit API and to validate the integration of a Reddit account with the provider's synchronization handlers. The tests ensure that the Reddit data is correctly fetched and processed. The unit tests cover the following aspects:

- Fetching and testing Reddit account.
- Fetching and testing Reddit account's subreddits, including where the account has the role of contributor, moderator or subscriber.
- Fetching and testing Reddit account's messages including notifications and private messages.
- Fetching and testing Reddit account's comments
- Fetching and testing Reddit account's interactions e.g. listing(posts, comments, etc.) that the user has upvoted, donwvoted, hidden or saved

### Prerequisites

Before running the unit tests, ensure that you have the following set up:

1. **Reddit Account**: A YouTube account with some activity is required. This activity includes uploaded videos, subscriptions, and liked videos.

2. **Reddit Account Data**: Make sure to have an account with some activity e.g. messages sent/received, comments, etc.
You can:
a. create a testing config file with the expected account information e.g. account name, number of messages, etc.
b. Run the tests with the following expected results

- **Messages**: An account with more than 50 messages.
- **Comments**: More than 50 comments by your account.
- **Posts**: Have at least a post.

3. **Authorized Application**: Make sure to create an authorized `web app` application and fill in the required information in the `serverconfig.local.json`

### Running the Tests

```bash
# To run the API tests
yarn run test tests/providers/reddit/api.test.ts
# To run the handler tests
yarn run test tests/providers/reddit/handlers/*.test.ts
```

## Resources

- [API Overview](https://www.reddit.com/dev/api/)
- [Reddit Passport](https://github.com/Slotos/passport-reddit)
- [OAuth2](https://github.com/reddit-archive/reddit/wiki/OAuth2)
- [API Scopes](https://www.reddit.com/api/v1/scopes)
- []()
33 changes: 33 additions & 0 deletions src/providers/reddit/accountCache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { RedditApi } from "./api";
import { Account } from "./types";

export interface TelegramUserProfile {
fullName: string;
firstName: string;
lastName: string;
username?: string;
}

/**
* Helper utility to fetch a user object
*/
export class AccountCache {
private accountCache: Record<string, Account> = {};
private api: RedditApi;

constructor(api: RedditApi) {
this.api = api;
}

public async getAccount(userId: string) {
if (this.accountCache[userId]) {
return this.accountCache[userId];
}

const user = await this.api.getUser(userId);

this.accountCache[userId] = user;

return this.accountCache[userId];
}
}
Loading