Skip to content

Commit 5c70e82

Browse files
authored
1117 Fix terminating chats on tab close (#1186)
* PoC beacon * Simplify * Clena up * Clean up
1 parent f630a69 commit 5c70e82

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

notification-server/src/server.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,21 @@ app.post("/dequeue", async (req, res) => {
6565
}
6666
});
6767

68-
app.post("/add-chat-to-termination-queue", (req, res) => {
69-
try{
68+
app.post("/add-chat-to-termination-queue", express.json(), express.text(), (req, res) => {
69+
try {
70+
const body = typeof req.body === "string" ? JSON.parse(req.body) : req.body;
71+
7072
addToTerminationQueue(
71-
req.body.chatId,
73+
body.chatId,
7274
() => fetch(`${process.env.RUUTER_URL}/chats/end`, {
7375
method: 'POST',
7476
headers: {
7577
'content-type': 'application/json',
76-
'cookie': req.body.cookie || req.headers.cookie,
78+
'cookie': body.cookie || req.headers.cookie,
7779
},
7880
body: JSON.stringify({
7981
message: {
80-
chatId: req.body.chatId,
82+
chatId: body.chatId,
8183
authorRole: 'end-user',
8284
event: 'CLIENT_LEFT_FOR_UNKNOWN_REASONS',
8385
authorTimestamp: new Date().toISOString(),
@@ -87,7 +89,7 @@ app.post("/add-chat-to-termination-queue", (req, res) => {
8789
);
8890

8991
res.status(200).json({ response: 'Chat will be terminated soon' });
90-
} catch {
92+
} catch (error) {
9193
res.status(500).json({ response: 'error' });
9294
}
9395
});

0 commit comments

Comments
 (0)