Skip to content

Commit

Permalink
#3044-receiving events
Browse files Browse the repository at this point in the history
  • Loading branch information
caiodasilva2005 committed Dec 16, 2024
1 parent 989ffd7 commit 5516efd
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 56 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@types/react-dom": "17.0.1"
},
"dependencies": {
"@slack/events-api": "^3.0.1",
"mitt": "^3.0.1",
"react-hook-form-persist": "^3.0.0",
"typescript": "^4.1.5"
Expand Down
5 changes: 5 additions & 0 deletions src/backend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import workPackageTemplatesRouter from './src/routes/work-package-templates.rout
import carsRouter from './src/routes/cars.routes';
import organizationRouter from './src/routes/organizations.routes';
import recruitmentRouter from './src/routes/recruitment.routes';
import { slackEvents } from './src/routes/slack.routes';

const app = express();

Expand All @@ -40,6 +41,10 @@ const options: cors.CorsOptions = {
allowedHeaders
};

// so we can listen to slack messages
// NOTE: must be done before using json
app.use('/slack', slackEvents.requestListener());

// so that we can use cookies and json
app.use(cookieParser());
app.use(express.json());
Expand Down
43 changes: 0 additions & 43 deletions src/backend/src/controllers/slack.controllers.ts

This file was deleted.

11 changes: 4 additions & 7 deletions src/backend/src/routes/slack.routes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { slackEvents } from '../..';
import { createEventAdapter } from '@slack/events-api';

export const slackEvents = createEventAdapter(process.env.SLACK_SIGNING_SECRET || '');

slackEvents.on('message', async (event) => {
try {
console.log(`Message received: ${event.text}`);
// Respond or process the message as needed
} catch (error) {
console.error('Error handling message event:', error);
}
console.log('EVENT:', event);
});
130 changes: 124 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3260,6 +3260,30 @@ __metadata:
languageName: node
linkType: hard

"@slack/events-api@npm:^3.0.1":
version: 3.0.1
resolution: "@slack/events-api@npm:3.0.1"
dependencies:
"@types/debug": ^4.1.4
"@types/express": ^4.17.0
"@types/lodash.isstring": ^4.0.6
"@types/node": ">=12.13.0 < 13"
"@types/yargs": ^15.0.4
debug: ^2.6.1
express: ^4.0.0
lodash.isstring: ^4.0.1
raw-body: ^2.3.3
tsscmp: ^1.0.6
yargs: ^15.3.1
dependenciesMeta:
express:
optional: true
bin:
slack-verify: dist/verify.js
checksum: ce62dc2ee9dd93b88820e18f88f543228740243dc390caf49b3a7e1ad351b298e3961898bd78f5eb43e9f6acac067458257cd34c9661089f684bb5cf4af468c3
languageName: node
linkType: hard

"@slack/logger@npm:^3.0.0":
version: 3.0.0
resolution: "@slack/logger@npm:3.0.0"
Expand Down Expand Up @@ -3706,7 +3730,7 @@ __metadata:
languageName: node
linkType: hard

"@types/debug@npm:^4.1.7":
"@types/debug@npm:^4.1.4, @types/debug@npm:^4.1.7":
version: 4.1.12
resolution: "@types/debug@npm:4.1.12"
dependencies:
Expand Down Expand Up @@ -3756,6 +3780,18 @@ __metadata:
languageName: node
linkType: hard

"@types/express-serve-static-core@npm:^4.17.33":
version: 4.19.6
resolution: "@types/express-serve-static-core@npm:4.19.6"
dependencies:
"@types/node": "*"
"@types/qs": "*"
"@types/range-parser": "*"
"@types/send": "*"
checksum: b0576eddc2d25ccdf10e68ba09598b87a4d7b2ad04a81dc847cb39fe56beb0b6a5cc017b1e00aa0060cb3b38e700384ce96d291a116a0f1e54895564a104aae9
languageName: node
linkType: hard

"@types/express-serve-static-core@npm:^5.0.0":
version: 5.0.2
resolution: "@types/express-serve-static-core@npm:5.0.2"
Expand Down Expand Up @@ -3789,6 +3825,18 @@ __metadata:
languageName: node
linkType: hard

"@types/express@npm:^4.17.0":
version: 4.17.21
resolution: "@types/express@npm:4.17.21"
dependencies:
"@types/body-parser": "*"
"@types/express-serve-static-core": ^4.17.33
"@types/qs": "*"
"@types/serve-static": "*"
checksum: fb238298630370a7392c7abdc80f495ae6c716723e114705d7e3fb67e3850b3859bbfd29391463a3fb8c0b32051847935933d99e719c0478710f8098ee7091c5
languageName: node
linkType: hard

"@types/file-saver@npm:^2.0.5":
version: 2.0.7
resolution: "@types/file-saver@npm:2.0.7"
Expand Down Expand Up @@ -3939,7 +3987,16 @@ __metadata:
languageName: node
linkType: hard

"@types/lodash@npm:^4.14.175":
"@types/lodash.isstring@npm:^4.0.6":
version: 4.0.9
resolution: "@types/lodash.isstring@npm:4.0.9"
dependencies:
"@types/lodash": "*"
checksum: ef381be69b459caa42d7c5dc4ff5b3653e6b3c9b2393f6e92848efeafe7690438e058b26f036b11b4e535fc7645ff12d1203847b9a82e9ae0593bdd3b25a971b
languageName: node
linkType: hard

"@types/lodash@npm:*, @types/lodash@npm:^4.14.175":
version: 4.17.13
resolution: "@types/lodash@npm:4.17.13"
checksum: d0bf8fbd950be71946e0076b30fd40d492293baea75f05931b6b5b906fd62583708c6229abdb95b30205ad24ce1ed2f48bc9d419364f682320edd03405cc0c7e
Expand Down Expand Up @@ -4008,6 +4065,13 @@ __metadata:
languageName: node
linkType: hard

"@types/node@npm:>=12.13.0 < 13":
version: 12.20.55
resolution: "@types/node@npm:12.20.55"
checksum: e4f86785f4092706e0d3b0edff8dca5a13b45627e4b36700acd8dfe6ad53db71928c8dee914d4276c7fd3b6ccd829aa919811c9eb708a2c8e4c6eb3701178c37
languageName: node
linkType: hard

"@types/nodemailer@npm:^6.4.0":
version: 6.4.17
resolution: "@types/nodemailer@npm:6.4.17"
Expand Down Expand Up @@ -4292,7 +4356,7 @@ __metadata:
languageName: node
linkType: hard

"@types/yargs@npm:^15.0.0":
"@types/yargs@npm:^15.0.0, @types/yargs@npm:^15.0.4":
version: 15.0.19
resolution: "@types/yargs@npm:15.0.19"
dependencies:
Expand Down Expand Up @@ -8054,7 +8118,7 @@ __metadata:
languageName: node
linkType: hard

"debug@npm:2.6.9, debug@npm:^2.2.0, debug@npm:^2.3.3, debug@npm:^2.6.0":
"debug@npm:2.6.9, debug@npm:^2.2.0, debug@npm:^2.3.3, debug@npm:^2.6.0, debug@npm:^2.6.1":
version: 2.6.9
resolution: "debug@npm:2.6.9"
dependencies:
Expand Down Expand Up @@ -10062,6 +10126,45 @@ __metadata:
languageName: node
linkType: hard

"express@npm:^4.0.0":
version: 4.21.2
resolution: "express@npm:4.21.2"
dependencies:
accepts: ~1.3.8
array-flatten: 1.1.1
body-parser: 1.20.3
content-disposition: 0.5.4
content-type: ~1.0.4
cookie: 0.7.1
cookie-signature: 1.0.6
debug: 2.6.9
depd: 2.0.0
encodeurl: ~2.0.0
escape-html: ~1.0.3
etag: ~1.8.1
finalhandler: 1.3.1
fresh: 0.5.2
http-errors: 2.0.0
merge-descriptors: 1.0.3
methods: ~1.1.2
on-finished: 2.4.1
parseurl: ~1.3.3
path-to-regexp: 0.1.12
proxy-addr: ~2.0.7
qs: 6.13.0
range-parser: ~1.2.1
safe-buffer: 5.2.1
send: 0.19.0
serve-static: 1.16.2
setprototypeof: 1.2.0
statuses: 2.0.1
type-is: ~1.6.18
utils-merge: 1.0.1
vary: ~1.1.2
checksum: 3aef1d355622732e20b8f3a7c112d4391d44e2131f4f449e1f273a309752a41abfad714e881f177645517cbe29b3ccdc10b35e7e25c13506114244a5b72f549d
languageName: node
linkType: hard

"express@npm:^4.17.1":
version: 4.21.1
resolution: "express@npm:4.21.1"
Expand Down Expand Up @@ -10464,6 +10567,7 @@ __metadata:
"@babel/plugin-transform-object-assign": ^7.18.6
"@babel/preset-react": ^7.18.6
"@babel/preset-typescript": ^7.18.6
"@slack/events-api": ^3.0.1
"@types/jest": ^28.1.6
"@types/node": 18.17.1
"@typescript-eslint/eslint-plugin": 4.18.0
Expand Down Expand Up @@ -15863,6 +15967,13 @@ __metadata:
languageName: node
linkType: hard

"path-to-regexp@npm:0.1.12":
version: 0.1.12
resolution: "path-to-regexp@npm:0.1.12"
checksum: ab237858bee7b25ecd885189f175ab5b5161e7b712b360d44f5c4516b8d271da3e4bf7bf0a7b9153ecb04c7d90ce8ff5158614e1208819cf62bac2b08452722e
languageName: node
linkType: hard

"path-to-regexp@npm:^1.7.0":
version: 1.9.0
resolution: "path-to-regexp@npm:1.9.0"
Expand Down Expand Up @@ -17379,7 +17490,7 @@ __metadata:
languageName: node
linkType: hard

"raw-body@npm:2.5.2":
"raw-body@npm:2.5.2, raw-body@npm:^2.3.3":
version: 2.5.2
resolution: "raw-body@npm:2.5.2"
dependencies:
Expand Down Expand Up @@ -20522,6 +20633,13 @@ __metadata:
languageName: node
linkType: hard

"tsscmp@npm:^1.0.6":
version: 1.0.6
resolution: "tsscmp@npm:1.0.6"
checksum: 1512384def36bccc9125cabbd4c3b0e68608d7ee08127ceaa0b84a71797263f1a01c7f82fa69be8a3bd3c1396e2965d2f7b52d581d3a5eeaf3967fbc52e3b3bf
languageName: node
linkType: hard

"tsutils@npm:^3.17.1, tsutils@npm:^3.21.0":
version: 3.21.0
resolution: "tsutils@npm:3.21.0"
Expand Down Expand Up @@ -22349,7 +22467,7 @@ __metadata:
languageName: node
linkType: hard

"yargs@npm:^15.4.1":
"yargs@npm:^15.3.1, yargs@npm:^15.4.1":
version: 15.4.1
resolution: "yargs@npm:15.4.1"
dependencies:
Expand Down

0 comments on commit 5516efd

Please sign in to comment.