choco-bot
Version:
Whatsapp-bot
37 lines (28 loc) • 1 kB
JavaScript
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
app.use(express.static('public'));
const port = 3000;
// Simulated database (replace this with a real database in a production environment)
const chatList = [
{ id: 'user1', name: 'User 1' },
{ id: 'user2', name: 'User 2' },
// Add more users as needed
];
app.use(cors());
app.use(bodyParser.json());
app.get('/chatlist', (req, res) => {
res.json(chatList);
});
app.post('/sendMessage', (req, res) => {
console.log(req.body)
const { userId, message } = req.body;
// Log the message to the console (replace this with actual database storage)
console.log(`Message from ${userId}: ${message}`);
// Send a response back (you can customize the response as needed)
res.json({ status: 'Message sent successfully' });
});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});