-
Notifications
You must be signed in to change notification settings - Fork 8
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
Showing
15 changed files
with
131 additions
and
270 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,51 +1,16 @@ | ||
import { Request, Response } from 'express'; | ||
//import crypto from 'crypto'; | ||
import { getWorkspaceId } from '../integrations/slack'; | ||
import OrganizationsService from '../services/organizations.services'; | ||
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') { | ||
res.status(200).send({ challenge: req.body.challenge }); | ||
} | ||
|
||
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) { | ||
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); | ||
res.status(200).send('Event recieved'); | ||
} | ||
console.log('INVALID SIGNITURE'); | ||
res.status(400).send('Slack request verification failed due to incorrect signature'); | ||
*/ | ||
export default class SlackController { | ||
static async processMessageEvent(event: any) { | ||
try { | ||
const organizations = await OrganizationsService.getAllOrganizations(); | ||
const nerSlackWorkspaceId = await getWorkspaceId(); | ||
const orgId = organizations.find((org) => org.slackWorkspaceId === nerSlackWorkspaceId)?.organizationId; | ||
if (orgId) { | ||
slackServices.processMessageSent(event, orgId); | ||
} | ||
} catch (error: unknown) {} | ||
} | ||
} |
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
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
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
Oops, something went wrong.