From 7a9985d68d8bb6950ebddf282686c8e0ba656fa6 Mon Sep 17 00:00:00 2001 From: caiodasilva2005 Date: Sun, 15 Dec 2024 19:35:07 -0500 Subject: [PATCH] #3044-slack event received --- .../src/controllers/slack.controllers.ts | 27 ++++++++++++------- src/backend/src/services/slack.services.ts | 2 +- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/backend/src/controllers/slack.controllers.ts b/src/backend/src/controllers/slack.controllers.ts index e3c042291b..51388961a6 100644 --- a/src/backend/src/controllers/slack.controllers.ts +++ b/src/backend/src/controllers/slack.controllers.ts @@ -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'); + */ } } diff --git a/src/backend/src/services/slack.services.ts b/src/backend/src/services/slack.services.ts index 641c746314..20cbd3039f 100644 --- a/src/backend/src/services/slack.services.ts +++ b/src/backend/src/services/slack.services.ts @@ -1,5 +1,5 @@ export default class slackServices { - static async processEvent(req: any ) { + static async processEvent(req: any) { //TODO: process request console.log(req); }