Skip to content

Commit

Permalink
#3044-slack event received
Browse files Browse the repository at this point in the history
  • Loading branch information
caiodasilva2005 committed Dec 16, 2024
1 parent ba44349 commit 7a9985d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
27 changes: 18 additions & 9 deletions src/backend/src/controllers/slack.controllers.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,51 @@
import { Request, Response } from 'express';
import crypto from 'crypto';
//import crypto from 'crypto';
import slackServices from '../services/slack.services';

export default class slackController {
static async handleEvent(req: Request, res: Response) {
console.log('got a slack req');
if (req.body.type === 'url_verification') {
return res.status(200).send({ challenge: req.body.challenge });
res.status(200).send({ challenge: req.body.challenge });
}

const slackSignature = req.headers['x-slack-signature'] as string;
console.log('EVENT');

//const slackSignature = req.headers['x-slack-signature'] as string;
const slackTimeStamp = req.headers['X-Slack-Request-Timestamp'] as string;

if (Math.abs(Date.now() - Number(slackTimeStamp) * 1000) > 60 * 5 * 1000) {
return res.status(400).send('Slack request verification failed due to expired timestamp');
res.status(400).send('Slack request verification failed due to expired timestamp');
}

/*
const reqBody = req.body;
const signatureBase = 'v0:' + slackTimeStamp + ':' + reqBody;

const finalSignature =
'v0=' +
crypto
.createHmac('sha256', process.env.SLACK_BOT_TOKEN ? process.env.SLACK_BOT_TOKEN : '')
.update(signatureBase)
.digest('hex');
*/

console.log('PROCESSING');
slackServices.processEvent(req.body);
res.status(200).send('Event recieved');
/*
if (
crypto.timingSafeEqual(
Uint8Array.from(Buffer.from(finalSignature, 'utf8')),
Uint8Array.from(Buffer.from(slackSignature, 'utf8'))
)
) {
console.log('WORKING');
slackServices.processEvent(req.body);
return res.status(200).send('Event recieved');
res.status(200).send('Event recieved');
}

return res.status(400).send('Slack request verification failed due to incorrect signature');
console.log('INVALID SIGNITURE');
res.status(400).send('Slack request verification failed due to incorrect signature');
*/
}
}
2 changes: 1 addition & 1 deletion src/backend/src/services/slack.services.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default class slackServices {
static async processEvent(req: any ) {
static async processEvent(req: any) {
//TODO: process request
console.log(req);
}
Expand Down

0 comments on commit 7a9985d

Please sign in to comment.