@@ -4,19 +4,6 @@ import config from "../../config/config";
4
4
import { discordTextResponse } from "./discordResponse" ;
5
5
import { DISCORD_BASE_URL , AWS_IAM_SIGNIN_URL } from "../constants/urls" ;
6
6
7
- function sendDiscordMessage ( content : string , channelId : number , env : env ) {
8
- return fetch ( `${ DISCORD_BASE_URL } /channels/${ channelId } /messages` , {
9
- method : "POST" ,
10
- headers : {
11
- "Content-Type" : "application/json" ,
12
- Authorization : `Bot ${ env . DISCORD_TOKEN } ` ,
13
- } ,
14
- body : JSON . stringify ( {
15
- content : `${ content } ` ,
16
- } ) ,
17
- } ) ;
18
- }
19
-
20
7
export async function processAWSAccessRequest (
21
8
discordUserId : string ,
22
9
awsGroupId : string ,
@@ -47,18 +34,36 @@ export async function processAWSAccessRequest(
47
34
body : JSON . stringify ( requestData ) ,
48
35
} ) ;
49
36
37
+ let content = "" ;
50
38
if ( ! response . ok ) {
51
39
const responseText = await response . text ( ) ;
52
40
const errorData = JSON . parse ( responseText ) ;
53
- const content = `<@${ discordUserId } > Error occurred while granting AWS access: ${ errorData . error } ` ;
54
- return sendDiscordMessage ( content , channelId , env ) ;
41
+ content = `<@${ discordUserId } > Error occurred while granting AWS access: ${ errorData . error } ` ;
55
42
} else {
56
- const content = `AWS access granted successfully <@${ discordUserId } >! Please head over to AWS - ${ AWS_IAM_SIGNIN_URL } .` ;
57
- return sendDiscordMessage ( content , channelId , env ) ;
43
+ content = `AWS access granted successfully <@${ discordUserId } >! Please head over to AWS - ${ AWS_IAM_SIGNIN_URL } .` ;
58
44
}
45
+ return await fetch ( `${ DISCORD_BASE_URL } /channels/${ channelId } /messages` , {
46
+ method : "POST" ,
47
+ headers : {
48
+ "Content-Type" : "application/json" ,
49
+ Authorization : `Bot ${ env . DISCORD_TOKEN } ` ,
50
+ } ,
51
+ body : JSON . stringify ( {
52
+ content : content ,
53
+ } ) ,
54
+ } ) ;
59
55
} catch ( err ) {
60
56
const content = `<@${ discordUserId } > Error occurred while granting AWS access.` ;
61
- return sendDiscordMessage ( content , channelId , env ) ;
57
+ return await fetch ( `${ DISCORD_BASE_URL } /channels/${ channelId } /messages` , {
58
+ method : "POST" ,
59
+ headers : {
60
+ "Content-Type" : "application/json" ,
61
+ Authorization : `Bot ${ env . DISCORD_TOKEN } ` ,
62
+ } ,
63
+ body : JSON . stringify ( {
64
+ content : content ,
65
+ } ) ,
66
+ } ) ;
62
67
}
63
68
}
64
69
0 commit comments