-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
36 lines (28 loc) · 1.08 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const discordService = require('./services/discordService');
const messageController = require('./controllers/messageController');
const notionController = require('./controllers/notionController');
const express = require('express');
const app = express();
const port = 3000;
discordService.initializeBot();
messageController.handleMessage();
messageController.eventEmitter.on('chatGPTMessage', (chatGPTMessage) => {
console.log('Received chatGPTMessage in app.js:', chatGPTMessage);
const parseMessage = JSON.parse(chatGPTMessage)
const task = parseMessage.message; // Extract the 'message' property as the task
const tag = parseMessage.tag;
(async () => {
try {
await notionController.addPage(task, tag);
const successMessage = `Added task "${task}" with tag "${tag}" to Notion.`;
console.log(successMessage);
} catch (error) {
const errorMessage = "An error occurred while adding the task to Notion.";
console.log(errorMessage);
}
})();
});
// Start the server
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});