// This is a mess I have no idea why slack makes getting infomation this hard.
const{
eventName:{
event_name:{value: selected_name},
},
eventType:{
"create.event.type":{
selected_option:{value: selected_event_id},
},
},
selectedUsers:{
invite_users:{selected_users},
},
eventDate:{
event_date:{selected_date},
},
eventTime:{
event_start_time:{selected_time},
},
}=values;
// Im sure this query can be made more efficient... The JSON filtering wouldnt work when doing it directly on user.
constfoundUser=awaitdb.credential
.findFirst({
rejectOnNotFound: true,
...WhereCredsEqualsId(user.id),
})
.user({
select:{
username: true,
email: true,
timeZone: true,
locale: true,
eventTypes:{
where:{
id: parseInt(selected_event_id),
},
select:{
id: true,
length: true,
locations: true,
},
},
credentials:{
...WhereCredsEqualsId(user.id),
},
},
});
constslackCredentials=foundUser?.credentials[0].key;// Only one slack credential for user
// @ts-ignore access_token must exist on slackCredentials otherwise we have wouldnt have reached this endpoint
constaccess_token=slackCredentials?.access_token;
// https://api.slack.com/authentication/best-practices#verifying since we verify the request is coming from slack we can store the access_token in the DB.
constclient=newWebClient(access_token);
// This could get a bit weird as there is a 3 second limit until the post times ou
// Compute all users that have been selected and get their email.
channel: user.id,// We just dm the user here as there is no point posting this message publicly - In future it might be worth pinging all the members of the invite also?
returnres.status(200).send("");// Slack requires a 200 to be sent to clear the modal. This makes it massive pain to update the user that the event has been created.