Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const app = express();
- const http = require('http').Server(app);
- const https = require('https');
- const io = require('socket.io')(http);
- var cors = require('cors');
- const path = require('path');
- var db = require("./utils/config");
- // app.use(cors());
- const corsOptions = {
- origin: '*',
- credentials: true, //access-control-allow-credentials:true
- optionSuccessStatus: 200
- }
- app.use(cors(corsOptions));
- app.use(express.static(path.join(__dirname, 'assets')));
- const venom = require('venom-bot');
- venom
- .create(
- //session
- 'sh', //Pass the name of the client you want to start the bot
- //catchQR
- (base64Qrimg, asciiQR, attempts, urlCode) => {
- console.log('Number of attempts to read the qrcode: ', attempts);
- console.log('Terminal qrcode: ', asciiQR);
- console.log('base64 image string qrcode: ', base64Qrimg);
- console.log('urlCode (data-ref): ', urlCode);
- },
- // statusFind
- (statusSession, session) => {
- console.log('Status Session: ', statusSession); //return isLogged || notLogged || browserClose || qrReadSuccess || qrReadFail || autocloseCalled || desconnectedMobile || deleteToken || chatsAvailable || deviceNotConnected || serverWssNotConnected || noOpenBrowser
- //Create session wss return "serverClose" case server for close
- console.log('Session name: ', session);
- },
- // options
- {
- multidevice: false, // for version not multidevice use false.(default: true)
- folderNameToken: 'tokens', //folder name when saving tokens
- mkdirFolderToken: '', //folder directory tokens, just inside the venom folder, example: { mkdirFolderToken: '/node_modules', } //will save the tokens folder in the node_modules directory
- headless: true, // Headless chrome
- devtools: false, // Open devtools by default
- useChrome: true, // If false will use Chromium instance
- debug: false, // Opens a debug session
- logQR: true, // Logs QR automatically in terminal
- browserWS: '', // If u want to use browserWSEndpoint
- browserArgs: [''], //Original parameters ---Parameters to be added into the chrome browser instance
- puppeteerOptions: {}, // Will be passed to puppeteer.launch
- disableSpins: true, // Will disable Spinnies animation, useful for containers (docker) for a better log
- disableWelcome: true, // Will disable the welcoming message which appears in the beginning
- updatesLog: true, // Logs info updates automatically in terminal
- autoClose: 60000, // Automatically closes the venom-bot only when scanning the QR code (default 60 seconds, if you want to turn it off, assign 0 or false)
- createPathFileToken: false, // creates a folder when inserting an object in the client's browser, to work it is necessary to pass the parameters in the function create browserSessionToken
- chromiumVersion: '818858', // Version of the browser that will be used. Revision strings can be obtained from omahaproxy.appspot.com.
- addProxy: [''], // Add proxy server exemple : [e1.p.webshare.io:01, e1.p.webshare.io:01]
- userProxy: '', // Proxy login username
- userPass: '' // Proxy password
- },
- // BrowserSessionToken
- // To receive the client's token use the function await clinet.getSessionTokenBrowser()
- {
- WABrowserId: '"UnXjH....."',
- WASecretBundle: '{"key":"+i/nRgWJ....","encKey":"kGdMR5t....","macKey":"+i/nRgW...."}',
- WAToken1: '"0i8...."',
- WAToken2: '"1@lPpzwC...."'
- },
- // BrowserInstance
- (browser, waPage) => {
- console.log('Browser PID:', browser.process().pid);
- waPage.screenshot({ path: 'screenshot.png' });
- }
- )
- .then((client) => {
- start(client);
- })
- .catch((erro) => {
- console.log(erro);
- });
- const port = process.env.PORT || 3000;
- http.listen(port, () => {
- console.log(`Socket.IO server running at http://localhost:${port}/`);
- });
- db.connect(function(err) {
- if (err) throw err;
- console.log("Connected DB");
- });
- async function start(client) {
- const baterai = await client.getBatteryLevel();
- const getHostDevice = await client.getHostDevice();
- const contacts = await client.getAllContacts();
- io.on('connection', (socket) => {
- io.sockets.emit('device', {
- baterai: baterai,
- device_name: getHostDevice.phone.device_manufacturer
- });
- if (socket.connected) {
- io.sockets.emit('connected', {
- connected: socket.connected
- });
- } else if (socket.disconnect) {
- io.sockets.emit('disconnect', {
- disconnect: socket.disconnect
- });
- }
- socket.on('retrive_kontak', data => {
- if (data.kontak == "retrive_kontak") {
- var values = [];
- contacts.forEach(function callbackFn(data, index) {
- values[index] = [
- contacts[index].id.user,
- contacts[index].name,
- contacts[index].type,
- contacts[index].isBusiness,
- contacts[index].isMe,
- contacts[index].isUser,
- contacts[index].isMyContact
- ];
- });
- let sql = "INSERT INTO kontak (nomor, nama, type, isBusiness, isMe, isUser, isMyContact) VALUES?";
- db.query(sql, [values], function(err, result) {
- //if (err) throw err;
- // console.log("Number of records inserted: " + result.affectedRows);
- });
- io.sockets.emit('retrive_kontak', {
- kontak: true
- });
- }
- });
- client.onMessage((message) => {
- var d = new Date();
- const time = d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
- const date = d.getFullYear() + ":" + d.getMonth() + ":" + d.getDay();
- let sql = 'INSERT INTO webhook (`nama`, `to`, `from`, `chat`, `date`, `time`) VALUES ';
- sql += `('${message.sender.verifiedName}','${message.to}', '${message.from}', '${message.body}', '${date}', '${time}');`;
- db.query(sql, function(err, result) {
- if (err) throw err;
- console.log("Number of records inserted: " + result.affectedRows);
- });
- io.emit('webhook', {
- message: message.body,
- from: message.from,
- to: message.to,
- name: message.sender.verifiedName
- });
- });
- socket.on('chat message', msg => {
- io.emit('chat message', msg);
- console.log(msg);
- client.sendText('6282285664114' + '@c.us', 'Welcome Venom 🕷')
- .then((result) => {
- //console.log('Result: ', result); //return object success
- console.log('sukses send wa');
- })
- .catch((erro) => {
- console.error('Error when sending: ', erro); //return object error
- });
- });
- // client
- // .sendImage(
- // '6282285664114@c.us',
- // __dirname + '/assets/image/sebuahhobi.png',
- // 'image-name',
- // 'Caption text'
- // )
- // .then((result) => {
- // console.log('Result: ', result); //return object success
- // })
- // .catch((erro) => {
- // console.error('Error when sending: ', erro); //return object error
- // });
- console.log('connected');
- });
- }
- // app.get('/', (req, res) => {
- // //res.sendFile(__dirname + '/index.html');
- // });
Add Comment
Please, Sign In to add comment