Description
Problem
Ever since migration to Discord from Mattermost, when students make submissions, our Discord server doesn’t get notifications.
Goal
Our goal is to bring back the feature to keep mentors / students more engaged and be aware of student activity. This way, students could get faster code review feedback.
- When users submits a challenge for a lesson X, we should update our discord channel for lesson X + 1 to students who have completed the lesson know that there has been a new submission.
- When a submission has been approved, we check to see if the user has completed all the challenges for the given lesson. If so, we progress them to the next lesson and send a congratulatory message to the lesson X channel. And then welcome the user into the lesson X+1 channel.
- We may also want to display a user's discord information on their c0d3 profile page.
In the future, we may just use Discord login instead of c0d3.com login. Also, possibly notify student when a comment is made on a submission.
To accomplish these features, we need to solve the following high level problems:
- How to correlate users’ Discord account to their c0d3.com account? (OAUTH after login)
- How to notify the lesson’s corresponding channel when users make a submission?
Architecture
Research
Since all of the unknowns are within the Discord API, our research focuses mainly around answering questions about the Discord API.
Correlating User’s Discord Account to c0d3.com account
- Best way to do this is using discord OAUTH2 API. This gives us the refresh token, auth token, which we can then use to fetch user’s discord info.
- test demo and result
- next-auth has an adapter for prisma and built in sign in functions and session handling, but we would need to add 2 or 3 more models to our schema and they provide no way of retrieving another user's discord info in real time, which is what we want
How to notify the lesson’s corresponding channel when users make a submission
- Create a bot and invite it to our guild/server. Sample link
- Official bot nodejs module
How to get channel ID
- Go to User Settings > Advanced > Activate Developer Mode
- Now when you right click on channel, there's an option to copy channel ID
Terminologies
- Our Guild ID for c0d3: 828783458469675019
- Within our Guild, we have multiple channels like (JS0-JS6).
Questions
- After users authorizes our app, we get
auth_token
(this expires). Doesrefresh_token
ever expire? No, the refresh token only expires when the user unauthorizes the application through their settingsauth_token
comes withexpires_in
with is in seconds. When we tested this, the value was604800
, which is 7 days
- What scopes may we want to ask the user for?
email
- In the future, we may want to use discord email in place of email verification during signup.- Further research needed: How do we know if the user has verified their email with discord? Are users able to oauth apps when their emails has not yet been verified?)
gdm.join
- allows our app to join users to a group dm. This could add an interesting feature for the future where we add users to relevant channels only after lesson completion.- Further research: Could we put 2 users in a group chat together? If we could, perhaps we could create a message between reviewer and student after submission review to facilitate communication between them?
guilds.join
- When users are not currently in c0d3 guild, after OAUTH we should automatically join them into our guild.identify
- For getting username and profile picture
- what bot permissions do we need and why