-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
71 lines (60 loc) · 2.1 KB
/
server.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const express = require('express');
const bodyParser = require('body-parser');
const pdf = require('html-pdf');
const axios = require('axios');
const nodemailer = require('nodemailer');
const app = express();
const port = 3000;
app.use(bodyParser.json());
app.use(express.static('public'));
// Replace with the actual endpoint and API key
const MOM_TEST_BOT_ENDPOINT = 'https://api.chatgpt.com/g/g-H7fQi3wHH-mom-test-bot';
const API_KEY = 'YOUR_API_KEY_HERE';
// Nodemailer transport configuration
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'YOUR_EMAIL@gmail.com',
pass: 'YOUR_EMAIL_PASSWORD'
}
});
app.post('/send-pdf', async (req, res) => {
const { idea, email } = req.body;
try {
const response = await axios.post(MOM_TEST_BOT_ENDPOINT, {
prompt: idea
}, {
headers: {
'Authorization': `Bearer ${API_KEY}`
}
});
const momResponse = response.data.reply;
const html = `<html><body><h1>Startup Idea Feedback</h1><p>${momResponse}</p></body></html>`;
pdf.create(html).toStream((err, stream) => {
if (err) return res.status(500).send(err);
const mailOptions = {
from: 'YOUR_EMAIL@gmail.com',
to: email,
subject: 'Your Startup Idea Feedback',
text: 'Attached is the PDF with the feedback for your startup idea.',
attachments: [
{
filename: 'MomTestResponse.pdf',
content: stream
}
]
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return res.status(500).send(error.toString());
}
res.status(200).send('PDF sent successfully');
});
});
} catch (error) {
res.status(500).send('Error generating response');
}
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});