-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba44349
commit 7a9985d
Showing
2 changed files
with
19 additions
and
10 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
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'); | ||
*/ | ||
} | ||
} |
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