first commit

This commit is contained in:
kicap1992
2025-12-19 17:19:03 +08:00
commit a77eb69753
4 changed files with 2035 additions and 0 deletions

8
.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.env
dist/
build/
.wwebjs*

80
index.js Normal file
View File

@ -0,0 +1,80 @@
const express = require('express');
const { Client, LocalAuth } = require('whatsapp-web.js');
const qrcode = require('qrcode-terminal');
const app = express();
app.use(express.json());
// WhatsApp client
const client = new Client({
authStrategy: new LocalAuth(),
puppeteer: {
headless: true,
args: ['--no-sandbox', '--disable-setuid-sandbox']
}
});
// Show QR in terminal
client.on('qr', (qr) => {
console.log('Scan this QR code:');
qrcode.generate(qr, { small: true });
});
// When WhatsApp is ready
client.on('ready', () => {
console.log('WhatsApp client ready');
});
// 4⃣ ✅ MESSAGE LISTENER (PUT IT HERE)
client.on('message', async (message) => {
console.log('--- New Message ---');
console.log('From:', message.from); // chat ID
console.log('Body:', message.body);
console.log('Is Group:', message.from.endsWith('@g.us'));
// Example: auto-reply
if (message.body.toLowerCase() === 'ping') {
await message.reply('pong');
}
});
// Initialize WhatsApp
client.initialize();
/**
* POST /send
* {
* "number": "62822932xxxx",
* "message": "hello"
* }
*/
app.get('/send', async (req, res) => {
//const { number, message } = req.body;
let number= "6281336138742";
let message ="hello ini dia";
const chatId = number + '@c.us';
try {
await client.sendMessage(chatId, message);
return res.json({
success: true,
to: number,
message
});
} catch (err) {
console.error(err);
return res.status(500).json({
success: false,
error: 'Failed to send message'
});
}
});
// Start Express server
const PORT = 3019;
app.listen(PORT, () => {
console.log(`Express server running on http://localhost:${PORT}`);
});

1930
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

17
package.json Normal file
View File

@ -0,0 +1,17 @@
{
"name": "tes-bot",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^5.2.1",
"qrcode-terminal": "^0.12.0",
"whatsapp-web.js": "^1.34.2"
}
}