Nexchan commited on
Commit
4b9f537
·
verified ·
1 Parent(s): ffe67f5

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +10 -4
index.js CHANGED
@@ -203,6 +203,7 @@ async function cleanInactiveUsersV2() {
203
 
204
  cleanInactiveUsersV2();
205
 
 
206
  app.get('/v2/send', async (req, res) => {
207
  try {
208
  const { id, message } = req.query;
@@ -226,11 +227,15 @@ app.get('/v2/send', async (req, res) => {
226
 
227
  const botResponse = await sendMessageV2(chatData.data, message);
228
 
229
- // Menambahkan pesan user
230
- chatData.data.history.push({ role: 'user', parts: [{ text: message }] });
 
 
231
 
232
- // Menambahkan respons bot
233
- chatData.data.history.push({ role: 'model', parts: [{ text: botResponse }] });
 
 
234
 
235
  chatData.lastChat = DateTime.local();
236
  db_chatHistory[id] = chatData;
@@ -242,6 +247,7 @@ app.get('/v2/send', async (req, res) => {
242
  });
243
 
244
 
 
245
  app.get('/v2/listuser', (req, res) => {
246
  const userList = Object.keys(db_chatHistory);
247
  res.status(200).json({ userList });
 
203
 
204
  cleanInactiveUsersV2();
205
 
206
+
207
  app.get('/v2/send', async (req, res) => {
208
  try {
209
  const { id, message } = req.query;
 
227
 
228
  const botResponse = await sendMessageV2(chatData.data, message);
229
 
230
+ // Periksa apakah pesan user sudah ada sebelumnya
231
+ if (!chatData.data.history.some(item => item.role === 'user' && item.parts[0].text === message)) {
232
+ chatData.data.history.push({ role: 'user', parts: [{ text: message }] });
233
+ }
234
 
235
+ // Periksa apakah respons bot sudah ada sebelumnya
236
+ if (!chatData.data.history.some(item => item.role === 'model' && item.parts[0].text === botResponse)) {
237
+ chatData.data.history.push({ role: 'model', parts: [{ text: botResponse }] });
238
+ }
239
 
240
  chatData.lastChat = DateTime.local();
241
  db_chatHistory[id] = chatData;
 
247
  });
248
 
249
 
250
+
251
  app.get('/v2/listuser', (req, res) => {
252
  const userList = Object.keys(db_chatHistory);
253
  res.status(200).json({ userList });