cmcts-c-agent-embedding 1.0.37-cagent → 1.0.38-cagent

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cmcts-c-agent-embedding",
3
- "version": "1.0.37-cagent",
3
+ "version": "1.0.38-cagent",
4
4
  "description": "Javascript library to display flowise chatbot on your website",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -42,6 +42,7 @@
42
42
  "node-fetch": "^3.3.2",
43
43
  "pdfjs-dist": "3.11.174",
44
44
  "prettier": "^3.4.2",
45
+ "socket.io-client": "^4.8.1",
45
46
  "solid-element": "1.7.0",
46
47
  "solid-js": "1.7.1",
47
48
  "zod": "^3.22.4"
@@ -83,4 +84,4 @@
83
84
  "uuid": "^9.0.1"
84
85
  },
85
86
  "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
86
- }
87
+ }
package/public/index.html CHANGED
@@ -34,8 +34,8 @@
34
34
  // chatflowid: 'b573e66d-0e28-4798-8e4f-fbbaff8e236f', // or 'support', 'salesbot', etc.
35
35
  // chatflowid: '7ee803b4-e3f8-4f33-bf85-ef9ab9d6f693', // or 'support', 'salesbot', etc.
36
36
  // chatflowid: '1dd678f5-85ed-440c-8800-33cea11c18b4', // or 'support', 'salesbot', etc.
37
- chatflowid: "66571066-226a-49e8-80f8-f62b5300a3dc",
38
- apiHost: "https://stock.cmcts.ai/c-agent",
37
+ chatflowid: "42a68bd5-3d8c-4b7b-b39b-03e7241d2fc6",
38
+ apiHost: "https://stock-backend.cagent.cmcts.ai",
39
39
  });
40
40
  </script>
41
41
  </body>
package/server.js CHANGED
@@ -9,6 +9,7 @@ import dotenv from 'dotenv';
9
9
  import axios from 'axios';
10
10
  import multer from 'multer';
11
11
  import FormData from 'form-data';
12
+ import nodemailer from 'nodemailer';
12
13
  import { generateEmbedScript } from './src/utils/embedScript.js';
13
14
 
14
15
  dotenv.config();
@@ -381,6 +382,81 @@ app.post('/api/v1/attachments/:identifier/:chatId', upload.array('files'), async
381
382
  }
382
383
  });
383
384
 
385
+ // Email sending endpoint
386
+ app.post('/api/v1/send-email', async (req, res) => {
387
+ try {
388
+ const { fileUrls, chatflowid, chatId } = req.body;
389
+
390
+ if (!fileUrls || !Array.isArray(fileUrls) || fileUrls.length === 0) {
391
+ return res.status(400).json({ error: 'CSV URLs are required' });
392
+ }
393
+
394
+ // Configure nodemailer transporter for Gmail
395
+ const transporter = nodemailer.createTransport({
396
+ service: 'gmail',
397
+ auth: {
398
+ user: 'leo.danny.ld.vn@gmail.com',
399
+ pass: 'rhfshdoamejhmils',
400
+ },
401
+ });
402
+
403
+ // Prepare attachments
404
+ const attachments = [];
405
+
406
+ for (const url of fileUrls) {
407
+ try {
408
+ // Download CSV file
409
+ const response = await axios.get(url, { responseType: 'arraybuffer' });
410
+ const filename = url.split('path=')[1]?.split('/').pop() || 'file.csv';
411
+
412
+ attachments.push({
413
+ filename: filename,
414
+ content: Buffer.from(response.data),
415
+ contentType: 'text/csv',
416
+ });
417
+ } catch (error) {
418
+ console.error(`Failed to download CSV from ${url}:`, error.message);
419
+ }
420
+ }
421
+
422
+ // Prepare email content with only CSV links
423
+ const csvLinksHtml = fileUrls.map((url) => `<li><a href="${url}">${url.split('path=')[1]?.split('/').pop() || url}</a></li>`).join('');
424
+
425
+ const mailOptions = {
426
+ from: 'leo.danny.ld.vn@gmail.com',
427
+ to: 'ldhuy2@cmc.com.vn',
428
+ subject: `Xác nhận từ Chatbot - ${chatflowid}`,
429
+ html: `
430
+ <h2>Xác nhận từ Chatbot</h2>
431
+ <p><strong>Chat ID:</strong> ${chatId}</p>
432
+ <p><strong>File CSV:</strong></p>
433
+ <ul>
434
+ ${csvLinksHtml}
435
+ </ul>
436
+ <p><strong>File đính kèm:</strong> ${attachments.length} file(s)</p>
437
+ `,
438
+ attachments: attachments,
439
+ };
440
+
441
+ // Send email
442
+ const info = await transporter.sendMail(mailOptions);
443
+
444
+ console.log('Email sent successfully:', info.messageId);
445
+ res.json({
446
+ success: true,
447
+ messageId: info.messageId,
448
+ attachmentsCount: attachments.length,
449
+ fileUrls: fileUrls,
450
+ });
451
+ } catch (error) {
452
+ console.error('Email sending error:', error);
453
+ res.status(500).json({
454
+ error: 'Failed to send email',
455
+ details: error.message,
456
+ });
457
+ }
458
+ });
459
+
384
460
  app.use((_req, res) => {
385
461
  res.status(404).json({ error: 'Not Found' });
386
462
  });