generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added a route to send Profile Blocked Messages (#198) * Added a route to sent Profile Blocked Messages * Modification to the message bot is sending * Authentication Added * Fixed Lint issues * Code Cleaning * Update variables.ts * Code Cleaning * Added a re-usable function for Auth (#199) * Added Auth for Identity Service (#200) * Added a route to sent Profile Blocked Messages * Modification to the message bot is sending * Authentication Added * Fixed Lint issues * Code Cleaning * Update variables.ts * Code Cleaning * Added a re-usable function for auth token * Added Auth for Identity Service * Set IDENTITY_SERVICE_PUBLIC_KEY environment while deploying (#201)
- Loading branch information
1 parent
515256d
commit f4c056c
Showing
18 changed files
with
276 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
export const SUPER_USER_ONE = "154585730465660929"; | ||
export const SUPER_USER_TWO = "1040700289348542566"; | ||
|
||
export const DISCORD_PROFILE_SERVICE_HELP_GROUP = "1209244798557360138"; | ||
export const DISCORD_PROFILE_SERVICE_STAGING_HELP_GROUP = "1209248671170953236"; | ||
export const DISCORD_PROFILE_SERVICE_DEVELOPMENT_HELP_GROUP = | ||
"1209237447083303014"; //Change this for your local environment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { env } from "../typeDefinitions/default.types"; | ||
import { sendProfileServiceBlockedMessage } from "../utils/sendProfileServiceBlockedMessage"; | ||
import JSONResponse from "../utils/JsonResponse"; | ||
import * as response from "../constants/responses"; | ||
import { verifyIdentityServiceAuthToken } from "../utils/verifyAuthToken"; | ||
|
||
export const sendProfileBlockedMessage = async (request: any, env: env) => { | ||
const authHeader = request.headers.get("Authorization"); | ||
if (!authHeader) { | ||
return new JSONResponse(response.BAD_SIGNATURE); | ||
} | ||
try { | ||
await verifyIdentityServiceAuthToken(authHeader, env); | ||
const messageRequest: { userId: string; reason: string } = | ||
await request.json(); | ||
const { userId, reason } = messageRequest; | ||
await sendProfileServiceBlockedMessage(userId, reason, env); | ||
return new JSONResponse("Message sent in tracking channel on discord"); | ||
} catch (e) { | ||
return new JSONResponse(response.BAD_SIGNATURE); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { env } from "../typeDefinitions/default.types"; | ||
import config from "../../config/config"; | ||
|
||
export const generateStringToBeSent = ( | ||
userId: string, | ||
reason: string, | ||
env: env | ||
) => { | ||
const helpGroupRoleId = config(env).PROFILE_SERVICE_HELP_GROUP_ID; | ||
return `Hello${userId ? ` <@${userId}>` : ""},\n${ | ||
userId ? "Your" : "Someone's" | ||
} Profile Service is **BLOCKED** because of the below-mentioned reason.${ | ||
userId | ||
? ` Please visit the [MY SITE](https://my.realdevsquad.com/identity) to fix this.\nIf you have any issue related to profile service, you can tag <@&${helpGroupRoleId}> and ask for help.` | ||
: "" | ||
}\n\n**Reason:** \`${reason ? reason : "No reason provided"}\``; | ||
}; | ||
|
||
export async function sendProfileServiceBlockedMessage( | ||
userId: string, | ||
reason: string, | ||
env: env | ||
): Promise<void> { | ||
const stringToBeSent = generateStringToBeSent(userId, reason, env); | ||
|
||
const bodyObj = { | ||
content: stringToBeSent, | ||
}; | ||
|
||
const url = config(env).TRACKING_CHANNEL_URL; | ||
|
||
await fetch(url, { | ||
method: "POST", | ||
body: JSON.stringify(bodyObj), | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bot ${env.DISCORD_TOKEN}`, | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.