Skip to content
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

Addition to Cleanup, Fix Bugs and New Features #56

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
ec6fff3
style add prettier
berkingurcan May 20, 2024
289b7a4
feat add vars for REDIS cloud usage
berkingurcan May 20, 2024
983ca75
feat add createClient to summarizer.js
berkingurcan May 20, 2024
b48ccc4
feat add nodemon
berkingurcan May 20, 2024
91b769b
Update README.md
berkingurcan May 20, 2024
c16595c
refactor(config): separate environment configuration into config module
berkingurcan May 20, 2024
dbe3190
refactor: gets summarizeFrequency from config module
berkingurcan May 20, 2024
20b76a1
style use version from config file
berkingurcan May 20, 2024
2073b86
style change import positions
berkingurcan May 20, 2024
77c38cc
refactor create constants and use it
berkingurcan May 20, 2024
8a1cce9
refactor: modularize summarizer, prompts config
berkingurcan May 20, 2024
d1bf7a9
style: prettier
berkingurcan May 20, 2024
1e3f308
feat add gets .env.local files
berkingurcan May 20, 2024
4c46bd8
refactor: add lib folder for functions
berkingurcan May 20, 2024
878bcb3
refactor: modularize summarize to lib
berkingurcan May 20, 2024
66e857d
refactore move functions to lib
berkingurcan May 20, 2024
ab01bf3
feat create test folder
berkingurcan May 21, 2024
6c1c5e3
style
berkingurcan May 21, 2024
21176ad
refactor move createSurvey to lib
berkingurcan May 22, 2024
322d753
refactor move makeSurveyPost to lib
berkingurcan May 22, 2024
e36c467
style prettier
berkingurcan May 22, 2024
c6b8d66
refactor: move startAutoPosting to lib
berkingurcan May 22, 2024
c1662e9
style: delete unnecessary runTest func
berkingurcan May 22, 2024
186ae19
refactor create commandBuilder
berkingurcan May 22, 2024
8e61396
refactor add handlers to utils
berkingurcan May 22, 2024
a451916
fix error create bot.js
berkingurcan May 22, 2024
5db2c48
fix add imports
berkingurcan May 22, 2024
c199de4
fix respond and submit
berkingurcan May 22, 2024
3e563e1
fix handleview
berkingurcan May 23, 2024
7c4af76
fix handle autopost
berkingurcan May 23, 2024
0a08351
refactor: rename utils to handler
berkingurcan May 23, 2024
cd399be
style remove unnecessary imports
berkingurcan May 23, 2024
d8a2f3d
style remove unnecessary comments
berkingurcan May 24, 2024
9b27108
refactor handlers to commands
berkingurcan May 24, 2024
1b6975c
Refactor migrate typescript and handle imports
berkingurcan May 24, 2024
a374acd
fix index.ts in lib
berkingurcan May 24, 2024
5ddf5c2
style remove unnecessary var
berkingurcan May 24, 2024
7dedb34
style add types to commandBuilder
berkingurcan May 24, 2024
c3ef966
style add types to handle create and handle autopost
berkingurcan May 24, 2024
8a1347d
style add types
berkingurcan May 24, 2024
d1f45d5
fix any type in handleautoposting and add tls to socket
berkingurcan May 24, 2024
1131c93
style remove unnecessary import
berkingurcan May 24, 2024
18f3a27
fix apikey mistake in update survey and convert prompt.ts into js
berkingurcan May 24, 2024
b9b8d5f
docs redis instructions
berkingurcan May 24, 2024
438dfc7
docs update readme
berkingurcan May 24, 2024
0116353
fix makeSurveyPost is not defined
berkingurcan May 25, 2024
e8e0aec
fix: Auto Posting error
berkingurcan May 26, 2024
6bbb634
feat add multiple questions
berkingurcan May 27, 2024
da46fbe
feat add Fields for questions
berkingurcan May 27, 2024
cdf72e4
fix handle create command for single survey
berkingurcan May 27, 2024
fb9f88e
Fix bug MAX 25 Survey while autocompleting.
berkingurcan May 27, 2024
982a384
style remove unnecessary logs
berkingurcan May 27, 2024
6a8345e
style prettier
berkingurcan May 27, 2024
0c29bc5
fix style of single survey and add limits
berkingurcan May 27, 2024
79b2b9f
style place holder info
berkingurcan May 27, 2024
a77c469
fix change dockerfile and compose
berkingurcan May 27, 2024
2fb0666
style remove tests from docker
berkingurcan May 27, 2024
f5e9ddf
Update docker-compose.yaml
berkingurcan May 27, 2024
e1429a7
Update docker composes and dockerfiles
berkingurcan May 27, 2024
f465233
Update docker-compose.yaml
berkingurcan May 27, 2024
2a26f02
Fix bug MAX 25 Survey while autocompleting.
berkingurcan May 27, 2024
df643dd
fix typo unmachedResponseCount to summary.unmatchedResponses.length
berkingurcan May 28, 2024
5a60d2b
feat add thread post automatically
berkingurcan May 29, 2024
06b1e1e
feat add created survey posts to thread cnl
berkingurcan May 29, 2024
84292d7
FIX SET PLACEHOLDER > 1000
berkingurcan May 29, 2024
1a3b02e
feat add delete command
berkingurcan Jun 3, 2024
4e66032
fix bugs for delete button
berkingurcan Jun 3, 2024
966c421
feat add delete rewrite condition added
berkingurcan Jun 3, 2024
237cd6f
fix: delete redis key fields
berkingurcan Jun 3, 2024
01aadb1
fix better warning
berkingurcan Jun 3, 2024
2f6ffe5
fix delete 45 char limit
berkingurcan Jun 3, 2024
b32063d
feat add edit command
berkingurcan Jun 3, 2024
e9b5c3c
fix db updates
berkingurcan Jun 3, 2024
d544451
Merge branch 'add-edit-command' into add-command-delete-surveys
berkingurcan Jun 3, 2024
3b2bff0
prettiered resolved conflict
berkingurcan Jun 3, 2024
4add9cc
Update constants.ts
berkingurcan Jun 3, 2024
12e3d4d
fix modal payload must contain between 1 and 5 components.
berkingurcan Jun 5, 2024
2e73951
feat add is-active status
berkingurcan Jun 5, 2024
90c9d6b
feat add filterin while auto complete
berkingurcan Jun 5, 2024
233fbc2
feat add command for set status
berkingurcan Jun 5, 2024
bd2ff4e
style remove unnecessary imports
berkingurcan Jun 5, 2024
bc0d076
fix optimize autocomplete filter
berkingurcan Jun 6, 2024
d208512
fix 45 char limit for title
berkingurcan Jun 6, 2024
ec84ff8
feat add end time add and edit feature
berkingurcan Jun 7, 2024
77756e2
fix edit end time format
berkingurcan Jun 7, 2024
7bc1d91
fix typo redis set
berkingurcan Jun 7, 2024
eeb8442
feat add loop for check expire status of survey
berkingurcan Jun 7, 2024
89f5175
fix add optimization with multi to redis
berkingurcan Jun 7, 2024
73ed77d
style prettier
berkingurcan Jun 7, 2024
bf54061
feat add verify questions length create & edit
berkingurcan Jun 10, 2024
0637ab1
fix bug respond previously generated respond
berkingurcan Jun 10, 2024
20acf8a
fix "-" char problem in title
berkingurcan Jun 10, 2024
5d60dca
style prettier
berkingurcan Jun 10, 2024
89d4b76
feat add logger loglevel and logs
berkingurcan Jun 10, 2024
3793d4e
feat change logs to loglevel
berkingurcan Jun 10, 2024
fa48e39
Merge branch 'thread-post' into implement-active-passive-and-timefram…
berkingurcan Jun 10, 2024
3b0c4a7
style channel Id change
berkingurcan Jun 10, 2024
8ce9e4e
style log debug
berkingurcan Jun 10, 2024
c452e20
Update logger.js
berkingurcan Jun 11, 2024
3a5de99
feat add set GSS LOG LEVEL
berkingurcan Jun 11, 2024
2223ecc
Update logger.js
berkingurcan Jun 11, 2024
924aacd
fix env var log level
berkingurcan Jun 11, 2024
06019bb
Update config.js
berkingurcan Jun 11, 2024
86c5801
remove semicolon
berkingurcan Jun 11, 2024
66154c3
Merge branch 'main' into implement-active-passive-and-timeframe-featu…
berkingurcan Jun 11, 2024
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
3 changes: 1 addition & 2 deletions .github/workflows/build-publish-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
env:
ECR_REPOSITORY_URL: 673156464838.dkr.ecr.us-west-2.amazonaws.com
ECR_REPOSITORY_NAME: gpt-survey-summarizer
APPLICATION_NAME: gpt-survey-summarizer
APPLICATION_NAME: gpt-survey-summarizer
DOCKER_TAG_PREFIX: ${{ github.event.inputs.docker_tag_prefix }}
PLATFORM: staging
NAMESPACE: governance
Expand All @@ -24,7 +24,6 @@ jobs:
name: Build Publish and Deploy Docker Image
runs-on: minafoundation-default-runners
steps:

- name: ⚙️ Set environment variables
run: |
echo "AWS_REGION=$AWS_REGION" >> $GITHUB_ENV
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ node_modules/
# Environment variable files
.env
.env.*
.env.local
.env.local*

# Logs
logs
Expand Down
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG NODE_VERSION=21.7.1
ARG NODE_VERSION=22.0.0

FROM node:${NODE_VERSION}-alpine

Expand All @@ -9,15 +9,16 @@ WORKDIR /app
# Copy package root
COPY ./package.json ./.
COPY ./package-lock.json ./.
COPY ./tsconfig.json ./.
COPY ./settings.json ./.

# Npm clean-install
RUN npm ci

# Copy source code
COPY ./src/* ./src/
COPY ./src ./src/

ENTRYPOINT ["npm", "run"]

# Possible modes: [ bot (default), summarizer ]
CMD ["bot"]

CMD ["bot"]
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@ Join the discord server for discussing and developing this tool [here](https://d

## Usage

1. Create a .env file with the following variables:

```shell
DISCORD_TOKEN=
OPENAI_API_KEY=
REDIS_URL=
CLIENT_ID=
GUILD_ID=
SUMMARIZE_FREQUENCY_SECONDS=3600
```
1. Create a .env.local file with the following variables:

```shell
DISCORD_TOKEN=XXXXXXXXX
OPENAI_API_KEY=XXXXXXXXX
REDIS_HOST=XXXXXX without port
REDIS_PORT=XXXXX
REDIS_PASSWORD=XXXXXXX
CLIENT_ID=XXXXXXXXX
GUILD_ID=XXXXXXXXXX
SUMMARIZE_FREQUENCY_SECONDS=3600
```

1. Run `npm install`
2. Start redis with `redis-server`
3. Start the main bot script with `npm run bot`
4. Start the gpt summarization script with `npm run summarizer`
1. Fill the REDIS_HOST, REDIS_PORT and REDIS_PASSWORD for connecting your Redis DB
- Go to [Redis](https://redis.io/) and create an account.
- Create a db and click `connect` copy and paste your password, socket and port into .env.local file
- You can see the redis configuration in `config.js`
1. Start the main bot script with `npm run bot`
1. Or Start the main bot script with `npm run dev` to use nodemon in development phase.
1. Start the gpt summarization script with `npm run summarizer`

## Docker image

Expand Down
64 changes: 39 additions & 25 deletions SETUP.md
Original file line number Diff line number Diff line change
@@ -1,88 +1,102 @@
# Step 1: Environment Setup

## A. Discord Developer Portal

- Create a Discord Account: If you haven’t already, sign up for a Discord account at [Discord](https://discord.com/).
- Create a New Application:
- Visit the Discord Developer Portal.
- Click on the "New Application" button.
- Name your application and create it.
- Visit the Discord Developer Portal.
- Click on the "New Application" button.
- Name your application and create it.
- Create a Bot User:
- In your application settings, navigate to the "Bot" tab and click "Add Bot".
- Customize your bot as needed (username, icon).
- In your application settings, navigate to the "Bot" tab and click "Add Bot".
- Customize your bot as needed (username, icon).
- Copy Your Bot Token:
- Still under the "Bot" tab, find your Token and click "Copy". Keep this safe; you'll need it later.
- Still under the "Bot" tab, find your Token and click "Copy". Keep this safe; you'll need it later.

## B. OpenAI Account

- Sign Up with OpenAI: Create an account at OpenAI if you don't have one.
- Access Your API Key:
- Navigate to the API section and copy your API key for later use.
- Navigate to the API section and copy your API key for later use.

## C. Redis Setup
- Install Redis:
- Ensure Redis is installed on your local system or use a cloud provider like Redis Labs.
- Follow the installation guide for your operating system or cloud provider's instructions.

- Go to [Redis](https://redis.io/) and create an account.
- Create a db and click `connect` copy and paste your password, socket and port into .env.local file

# Step 2: Project Initialization

## A. Node.js and NPM

- Install Node.js: Download and install Node.js (including NPM) from Node.js official website.

## B. Initialize Your Project

- Create a Project Directory: Choose a location for your project and create a directory for it.
- Open a Terminal/Command Prompt: Navigate to your project directory.
- Initialize NPM:
- Run `npm init` and follow the prompts to create a package.json file.
- Run `npm init` and follow the prompts to create a package.json file.
- Install Dependencies:
- Run `npm install discord.js @discordjs/rest @discordjs/builders redis openai dotenv`.
- Run `npm install discord.js @discordjs/rest @discordjs/builders redis openai dotenv`.

# Step 3: Environment Variables:

- Create a .env file in your project root.
- Add your Discord Bot Token, OpenAI API Key, and Redis connection details (if applicable). Example:
DISCORD_TOKEN=<Your Discord Bot Token>
OPENAI_API_KEY=<Your OpenAI API Key>
CLIENT_ID=<Your Discord Application Client ID> (It's available in the [Discord Developer Portal](https://discord.com/developers/applications/)
GUILD_ID=<Your Discord Server (Guild) ID> (To get the Guild ID, you must ensure that "Developer Mode" is enabled in your Discord client settings)
REDIS_URL=redis://localhost:6379
DISCORD_TOKEN=<Your Discord Bot Token>
OPENAI_API_KEY=<Your OpenAI API Key>
CLIENT_ID=<Your Discord Application Client ID> (It's available in the [Discord Developer Portal](https://discord.com/developers/applications/)
GUILD_ID=<Your Discord Server (Guild) ID> (To get the Guild ID, you must ensure that "Developer Mode" is enabled in your Discord client settings)
REDIS_URL=redis://localhost:6379

## Finding the Client ID

- Navigate to the [Discord Developer Portal](https://discord.com/developers/applications/)
- Select Your Application: Click on the application you created for your bot.
- Locate the Client ID:
- Under the "Application" section (usually the first page you land on after selecting your application), you will find your Client ID. It's a long string of numbers.
- Click the "Copy" button next to the Client ID to copy it to your clipboard.
- Under the "Application" section (usually the first page you land on after selecting your application), you will find your Client ID. It's a long string of numbers.
- Click the "Copy" button next to the Client ID to copy it to your clipboard.

## Finding the Guild ID (Server ID)

To get the Guild ID, you must ensure that "Developer Mode" is enabled in your Discord client settings.

### Enabling Developer Mode

- Open Discord Settings: Click on the gear icon next to your username at the bottom left corner of the Discord interface.
- Access Advanced Settings: In the left sidebar, scroll down and select "Advanced" under the "App Settings" section.
- Enable Developer Mode: Toggle the "Developer Mode" switch to the on position.

### Copying the Guild ID

- Right-Click Your Server Icon:
- After enabling Developer Mode, go back to the server list on the left side of the Discord interface.
- Right-click the server (guild) where you intend to use the bot.
- After enabling Developer Mode, go back to the server list on the left side of the Discord interface.
- Right-click the server (guild) where you intend to use the bot.
- Select 'Copy ID': At the bottom of the context menu, click "Copy ID" to copy the Guild ID to your clipboard.

# Step 4: Registering Slash Commands

- Use the Discord.js guide to register your slash commands either globally or to a specific guild for testing. The command registration can be part of your bot startup process or a separate script.

# Step 5: Running Your Bot

- Start Your Bot:
- In your terminal/command prompt, navigate to your project directory.
- Run `node bot.js` to start your bot.
- In your terminal/command prompt, navigate to your project directory.
- Run `node bot.js` to start your bot.
- Invite Your Bot to Your Server:
- In the Discord Developer Portal, under your application's "OAuth2" settings, generate an invite link with the necessary bot permissions.
- Use the generated link to invite your bot to your server.
- In the Discord Developer Portal, under your application's "OAuth2" settings, generate an invite link with the necessary bot permissions.
- Use the generated link to invite your bot to your server.

# Step 6: Set Up Redis

- Ensure Redis is running and accessible. If you installed Redis locally, it should be available at `redis://localhost:6379`. For remote instances, configure according to your provider's instructions.

# Step 7: Testing Your Setup

- Test your bot on your Discord server by using the registered slash commands to create, list, and respond to surveys.
- Monitor the Redis database to ensure data is being saved and retrieved correctly.

# Step 8: Final Checks

- Ensure all environment variables are correctly set.
- Confirm that your bot has the necessary permissions on your Discord server to read messages, send messages, and manage interactions.
10 changes: 7 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ services:
build: .
command: bot
environment:
CLIENT_ID: ""
DISCORD_TOKEN: ""
REDIS_HOST: redis
REDIS_PORT: 6379
REDIS_PASSWORD: ""
CLIENT_ID: ""
GUILD_ID: ""
REDIS_URL: "redis://redis:6379"
SUMMARIZE_FREQUENCY_SECONDS: ""
summarizer:
image: gpt-survey-summarizer
build: .
command: summarizer
environment:
OPENAI_API_KEY: ""
REDIS_URL: "redis://redis:6379"
REDIS_HOST: redis
REDIS_PORT: 6379
REDIS_PASSWORD: ""
SUMMARIZE_FREQUENCY_SECONDS: ""
redis:
image: redis
41 changes: 26 additions & 15 deletions initial_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,36 @@ The following were initial notes used for drafting the implementation. It is sli
# notes

Product Requirements:
- Users can make new surveys, which each have a list of questions
- Users can answer surveys by providing answers to the list of questions
- Users can see what surveys they can answer
- Users can see the survey summary
- Users can see which comments have not been added to the survey summary yet

- Users can make new surveys, which each have a list of questions
- Users can answer surveys by providing answers to the list of questions
- Users can see what surveys they can answer
- Users can see the survey summary
- Users can see which comments have not been added to the survey summary yet

Discord bot commands
- `/gptsurvey new [surveyName]`
- `/gptsurvey summary [surveyname]`
- `/gptsurvey respond [surveyname]`
- `/gptsurvey list`

- `/gptsurvey new [surveyName]`
- `/gptsurvey summary [surveyname]`
- `/gptsurvey respond [surveyname]`
- `/gptsurvey list`

Backend Architecture
- a nodejs module that runs the discord bot code
- a redis server that holds survey data
- a nodejs module that monitors the redis server and updates the gpt computed survey data
- The gpt computed survey data would be a similar process as talk to the city, just with comments instead of claims

- a nodejs module that runs the discord bot code
- a redis server that holds survey data
- a nodejs module that monitors the redis server and updates the gpt computed survey data
- The gpt computed survey data would be a similar process as talk to the city, just with comments instead of claims

Data format of a survey form

```
- title: text
- questions: List[text]
```

Data format of a survey summary

```
- title: text,
- topics: [
Expand All @@ -41,7 +45,7 @@ Data format of a survey summary
{
subtopicName: text,
subtopicDescription: text,
comments: [
comments: [
{
submitter: text,
answers: List[text]
Expand All @@ -62,22 +66,29 @@ Data format of a survey summary
What the discord bot response to `/gptsurvey summary [surveyname]` could look like:

### [surveyname]

#### [topic1Name]

[Description]
[# of comments in the topic]
[% of comments in the topic out of the total]

##### [subtopic1Name]

[description]
[Thread with all comments in the subtopic]
[# of comments in the subtopic]
[% of comments in the subtopic out of the # of comments in the topic]

##### [subtopic2Name]

...

#### [topic2Name]

...

#### Comments not yet categorized

These comments will be categorized when the survey summary is recomputed in [x] minutes
[Thread with all the comments not yet included in the survey summary]

Loading