├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.txt ├── README.md ├── SECURITY.md ├── config ├── settings.js └── settings2.js ├── includes ├── client.js └── client2.js ├── index.js ├── nodemon.json └── package.json /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | education, socio-economic status, nationality, personal appearance, race, 10 | religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at {{ email }}. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | [fork]: /fork 4 | [pr]: /compare 5 | [style]: https://standardjs.com/ 6 | [code-of-conduct]: CODE_OF_CONDUCT.md 7 | 8 | Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great. 9 | 10 | Please note that this project is released with a [Contributor Code of Conduct][code-of-conduct]. By participating in this project you agree to abide by its terms. 11 | 12 | ## Issues and PRs 13 | 14 | If you have suggestions for how this project could be improved, or want to report a bug, open an issue! We'd love all and any contributions. If you have questions, too, we'd love to hear them. 15 | 16 | We'd also love PRs. If you're thinking of a large PR, we advise opening up an issue first to talk about it, though! Look at the links below if you're not sure how to open a PR. 17 | 18 | ## Submitting a pull request 19 | 20 | 1. [Fork][fork] and clone the repository. 21 | 1. Configure and install the dependencies: `npm install`. 22 | 1. Make sure the tests pass on your machine: `npm test`, note: these tests also apply the linter, so there's no need to lint separately. 23 | 1. Create a new branch: `git checkout -b my-branch-name`. 24 | 1. Make your change, add tests, and make sure the tests still pass. 25 | 1. Push to your fork and [submit a pull request][pr]. 26 | 1. Pat your self on the back and wait for your pull request to be reviewed and merged. 27 | 28 | Here are a few things you can do that will increase the likelihood of your pull request being accepted: 29 | 30 | - Follow the [style guide][style] which is using standard. Any linting errors should be shown when running `npm test`. 31 | - Write and update tests. 32 | - Keep your changes as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests. 33 | - Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html). 34 | 35 | Work in Progress pull requests are also welcome to get feedback early on, or if there is something blocked you. 36 | 37 | ## Resources 38 | 39 | - [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) 40 | - [Using Pull Requests](https://help.github.com/articles/about-pull-requests/) 41 | - [GitHub Help](https://help.github.com) 42 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2023, Dani Ramdani 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WhatsApp BOT Multi Device Pairing Code - NodeJs 2 | Contoh skrip bot WhatsApp, menggunakan perpustakaan WhatsApp Web API 3 | 4 | ## Instalasi 5 | ### Instal Perangkat Lunak/Paket-Paket 6 | #### Untuk Linux 7 | ```bash 8 | sudo apt-get install nodejs 9 | sudo apt-get install git 10 | sudo apt-get install npm 11 | sudo apt-get install yarn 12 | ``` 13 | 14 | #### Untuk Windows 15 | ```bash 16 | choco install nodejs 17 | choco install git 18 | choco install yarn 19 | ``` 20 | 21 | #### Untuk MacOS 22 | ```bash 23 | brew install node 24 | brew install git 25 | brew install yarn 26 | ``` 27 | 28 | #### Untuk Android (Termux) 29 | ```bash 30 | pkg install nodejs 31 | pkg install git 32 | pkg install yarn 33 | ``` 34 | 35 | ### Download/Klon Proyek 36 | ```bash 37 | git clone https://github.com/danitechid/example-wa-bot-script.git 38 | ``` 39 | 40 | ### Pindah Direktori (CD) 41 | ```bash 42 | cd example-wa-bot-script 43 | ``` 44 | 45 | ### Instal Dependensi 46 | #### Menggunakan Npm 47 | ```bash 48 | npm install 49 | ``` 50 | #### Atau Menggunakan Yarn 51 | ```bash 52 | yarn install 53 | ``` 54 | 55 | ### Jalankan Server 56 | #### Menggunakan Npm 57 | ```bash 58 | npm run start 59 | ``` 60 | 61 | #### Atau Menggunakan Yarn 62 | ```bash 63 | yarn run start 64 | ``` 65 | 66 | #### Atau Menggunakan Node 67 | ```bash 68 | node run start 69 | ``` 70 | 71 | #### Atau Menggunakan Bun 72 | ```bash 73 | bun run start 74 | ``` 75 | 76 | ## Informasi 77 | * Pembuat / Pengembang: Dani Ramdani (Dani Techno.) - FullStack Engineer 78 | * Kontak Pembuat / Pengembang: 0895 1254 5999 (WhatsApp), contact@danitechno.com (Email) 79 | 80 | ## Terimakasih Kepada 81 | * Dani Techno. - FullStack Engineer (Pembuat / Pengembang) 82 | * @danitech/wa-web-api (Penyedia Library "WhatsApp Web API") 83 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Reporting Security Issues 2 | 3 | If you believe you have found a security vulnerability in React, we encourage you to let us know right away. We will investigate all legitimate reports and do our best to quickly fix the problem. 4 | 5 | Please refer to the following page for our responsible disclosure policy, reward guidelines, and those things that should not be reported: 6 | 7 | contact@danitechno.com 8 | -------------------------------------------------------------------------------- /config/settings.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Information 3 | * Creator / Developer: Dani Ramdani (Dani Techno.) - FullStack Engineer 4 | * Contact creator / Developer: 0895 1254 5999 (WhatsApp), contact@danitechno.com (Email) 5 | */ 6 | 7 | /* Thanks to 8 | * Dani Techno. - FullStack Engineer (Creator / Developer) 9 | * @danitech/wa-web-api (Library "WhatsApp Web API" provider) 10 | */ 11 | 12 | module.exports = { 13 | pairing_mode: true, 14 | session_folder_name: 'session', 15 | browser: ["Chrome (Windows)", "latest"], 16 | mode: 'both', // Private, Group, Both/All 17 | public_mode: true, 18 | offline_status: false, 19 | auto_update_profile_status: false, 20 | auto_read_messages: true, 21 | auto_typing: true, 22 | auto_recording: false, 23 | prefix: '.', 24 | bot: { 25 | name: 'Bot Name', 26 | profile_status: 'Bot Status' 27 | }, 28 | owner: { 29 | name: ["Owner Name"], 30 | number: ["628xxx"] 31 | } 32 | date: { 33 | country: 'id-ID', 34 | time_zone: 'Asia/Jakarta' 35 | } 36 | }; -------------------------------------------------------------------------------- /config/settings2.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Information 3 | * Creator / Developer: Dani Ramdani (Dani Techno.) - FullStack Engineer 4 | * Contact creator / Developer: 0895 1254 5999 (WhatsApp), contact@danitechno.com (Email) 5 | */ 6 | 7 | /* Thanks to 8 | * Dani Techno. - FullStack Engineer (Creator / Developer) 9 | * @danitech/wa-web-api (Library "WhatsApp Web API" provider) 10 | */ 11 | 12 | module.exports = { 13 | pairing_mode: true, 14 | session_folder_name: 'session', 15 | browser: ["Chrome (Windows)", "latest"], 16 | public_mode: true, 17 | prefix: '.', 18 | bot: { 19 | name: 'Bot Name', 20 | profile_status: 'Bot Status' 21 | }, 22 | owner: { 23 | name: ["Owner Name"], 24 | number: ["628xxx"] 25 | } 26 | }; -------------------------------------------------------------------------------- /includes/client.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Information 3 | * Creator / Developer: Dani Ramdani (Dani Techno.) - FullStack Engineer 4 | * Contact creator / Developer: 0895 1254 5999 (WhatsApp), contact@danitechno.com (Email) 5 | */ 6 | 7 | /* Thanks to 8 | * Dani Techno. - FullStack Engineer (Creator / Developer) 9 | * @danitech/wa-web-api (Library "WhatsApp Web API" provider) 10 | */ 11 | 12 | const chalk = require('chalk'); 13 | const config = require('../config/settings.js'); 14 | 15 | module.exports = async ({ 16 | client, 17 | messages 18 | }) => { 19 | try { 20 | const message = messages.message; 21 | const messageType = messages.type; 22 | const messageMType = messages.mtype; 23 | const messageContent = JSON.stringify(message); 24 | const messageKey = messages.key; 25 | const messageChat = messages.chat; 26 | const messageSender = messages.sender; 27 | const messagePushName = messages.pushName; 28 | const messageReply = messages.reply; 29 | const body = messageMType === 'conversation' ? message.conversation : messageMType === 'extendedTextMessage' ? message.extendedTextMessage.text : messageMType === 'imageMessage' ? message.imageMessage.caption : messageMType === 'videoMessage' ? message.videoMessage.caption : ''; 30 | const budy = typeof messages.text === 'string' ? messages.text : ''; 31 | const command = body.startsWith(config.prefix) ? body.replace(config.prefix, '').trim().split(/ +/).shift().toLowerCase() : ''; 32 | const cleanCommand = command.replace(config.prefix, ''); 33 | const args = body.trim().split(/ +/).slice(1); 34 | const query = q = args.join(' '); 35 | const query1 = q1 = query.split('|')[0]; 36 | const query2 = q2 = query.split('|')[1]; 37 | const quoted = messages.quoted ? messages.quoted : messages; 38 | const mime = (quoted.msg || quoted).mimetype || ''; 39 | const isMedia = /image|video|sticker|audio/.test(mime); 40 | const isImage = (messageType == 'imageMessage'); 41 | const isVideo = (messageType == 'videoMessage'); 42 | const isAudio = (messageType == 'audioMessage'); 43 | const isText = (messageType == 'textMessage'); 44 | const isSticker = (messageType == 'stickerMessage'); 45 | const isQuotedText = messageType === 'extendexTextMessage' && messageContent.includes('textMessage'); 46 | const isQuotedImage = messageType === 'extendedTextMessage' && messageContent.includes('imageMessage'); 47 | const isQuotedLocation = messageType === 'extendedTextMessage' && messageContent.includes('locationMessage'); 48 | const isQuotedVideo = messageType === 'extendedTextMessage' && messageContent.includes('videoMessage'); 49 | const isQuotedSticker = messageType === 'extendedTextMessage' && messageContent.includes('stickerMessage'); 50 | const isQuotedAudio = messageType === 'extendedTextMessage' && messageContent.includes('audioMessage'); 51 | const isQuotedContact = messageType === 'extendedTextMessage' && messageContent.includes('contactMessage'); 52 | const isQuotedDocument = messageType === 'extendedTextMessage' && messageContent.includes('documentMessage'); 53 | const jid = messageChat ? messageChat : messageKey.remoteJid; 54 | const senderNumber = messageSender.replace(/\D/g, ''); 55 | const senderName = messagePushName || 'Undefined'; 56 | const ownerNumbers = config.owner.number; 57 | const isOwner = ownerNumbers.includes(senderNumber); 58 | const profileStatus = config.bot.profile_status; 59 | const isPublicMode = config.public_mode; 60 | const isOfflineStatus = config.offline_status; 61 | const isAutoUpdateProfileStatus = config.auto_update_profile_status; 62 | const isMessage = message; 63 | const isAutoReadMessages = config.auto_read_messages; 64 | const isAutoTyping = config.auto_typing; 65 | const isAutoRecording = config.auto_recording; 66 | const isGroup = messages.isGroup; 67 | 68 | var reply = sendText = messageReply; 69 | 70 | const date = new Date(); 71 | const formattedDate = new Date(date.toLocaleString('en-US', { timeZone: config.date.time_zone })); 72 | const currentDate = formattedDate; 73 | 74 | if (!isPublicMode) { 75 | if (!messageKey.fromMe) { 76 | return; 77 | }; 78 | }; 79 | 80 | if (config.mode === 'private') { 81 | if (isMessage) { 82 | if (isGroup) { 83 | return; 84 | }; 85 | }; 86 | } else if (config.mode === 'group') { 87 | if (isMessage) { 88 | if (!isGroup) { 89 | return; 90 | }; 91 | }; 92 | } else if (config.mode === 'all' || config.mode === 'both') { 93 | /**/ 94 | }; 95 | 96 | // Offline status 97 | if (isOfflineStatus) { 98 | client.sendPresenceUpdate('unavailable', jid) 99 | }; 100 | 101 | // Auto update profile status 102 | if (isAutoUpdateProfileStatus) { 103 | client.updateProfileStatus(profileStatus) 104 | }; 105 | 106 | if (isMessage) { 107 | if (body.startsWith(config.prefix)) { 108 | 109 | // Auto read messages 110 | if (isAutoReadMessages) { 111 | client.readMessages([messageKey]); 112 | }; 113 | 114 | // Auto typing 115 | if (isAutoTyping) { 116 | client.sendPresenceUpdate('composing', jid) 117 | }; 118 | 119 | // Auto recording 120 | if (isAutoRecording) { 121 | client.sendPresenceUpdate('recording', jid) 122 | }; 123 | }; 124 | 125 | console.log( 126 | chalk.bgMagenta(' [New Message] '), 127 | chalk.cyanBright('Time: ') + chalk.greenBright(currentDate) + '\n', 128 | chalk.cyanBright('Message: ') + chalk.greenBright(budy || messageMType) + '\n' + 129 | chalk.cyanBright('From:'), chalk.greenBright(senderName), chalk.yellow('- ' + senderNumber) + '\n' + 130 | chalk.cyanBright('Chat Type:'), chalk.greenBright(!isGroup ? 'Private Chat' : 'Group Chat - ' + chalk.yellow(messageChat)) 131 | ); 132 | }; 133 | 134 | if (!body.startsWith(config.prefix) || body === config.prefix) { 135 | return; 136 | }; 137 | 138 | switch (cleanCommand) { 139 | case 'test': { 140 | reply('Ok success!'); 141 | break; 142 | }; 143 | 144 | default: { 145 | const infoMessage = `Command: ${config.prefix}${cleanCommand}, tidak tersedia!`; 146 | reply(infoMessage); 147 | }; 148 | }; 149 | } catch (error) { 150 | reply('Terjadi kesalahan pada server.'); 151 | console.error(error); 152 | }; 153 | }; -------------------------------------------------------------------------------- /includes/client2.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Information 3 | * Creator / Developer: Dani Ramdani (Dani Techno.) - FullStack Engineer 4 | * Contact creator / Developer: 0895 1254 5999 (WhatsApp), contact@danitechno.com (Email) 5 | */ 6 | 7 | /* Thanks to 8 | * Dani Techno. - FullStack Engineer (Creator / Developer) 9 | * @danitech/wa-web-api (Library "WhatsApp Web API" provider) 10 | */ 11 | 12 | const chalk = require('chalk'); 13 | const config = require('../config/settings.js'); 14 | 15 | module.exports = async ({ 16 | client, 17 | messages 18 | }) => { 19 | try { 20 | const body = messages.mtype === 'conversation' ? messages.message.conversation : messages.mtype === 'extendedTextMessage' ? messages.message.extendedTextMessage.text : ''; 21 | const budy = typeof messages.text === 'string' ? messages.text : ''; 22 | const command = body.startsWith(config.prefix) ? body.replace(config.prefix, '').trim().split(/ +/).shift().toLowerCase() : ''; 23 | const cleanCommand = command.replace(config.prefix, ''); 24 | const args = body.trim().split(/ +/).slice(1); 25 | const query = q = args.join(' '); 26 | const query1 = q1 = query.split('|')[0] 27 | const query2 = q2 = query.split('|')[1] 28 | 29 | const ownerNumbers = config.owner.number; 30 | const senderNumber = messages.sender.replace(/\D/g, ''); 31 | const senderName = messages.pushName || 'Undefined'; 32 | const isOwner = ownerNumbers.includes(messages.sender); 33 | 34 | if (!config.public_mode) { 35 | if (!messages.key.fromMe) { 36 | return; 37 | }; 38 | }; 39 | 40 | if (messages.message) { 41 | client.readMessages([messages.key]); 42 | 43 | console.log( 44 | chalk.bgMagenta(' [New Message] '), 45 | chalk.cyanBright('Time: ') + chalk.greenBright(new Date()) + '\n', 46 | chalk.cyanBright('Message: ') + chalk.greenBright(budy || messages.mtype) + '\n' + 47 | chalk.cyanBright('From:'), chalk.greenBright(senderName), chalk.yellow('- ' + senderNumber) + '\n' + 48 | chalk.cyanBright('Chat Type:'), chalk.greenBright(!messages.isGroup ? 'Private Chat' : 'Group Chat - ' + chalk.yellow(messages.chat)) 49 | ); 50 | }; 51 | 52 | if (!body.startsWith(config.prefix) || body === config.prefix) { 53 | return; 54 | }; 55 | 56 | switch (cleanCommand) { 57 | case 'test': { 58 | messages.reply('Ok, Success!'); 59 | break; 60 | }; 61 | 62 | default: { 63 | messages.reply(`Command: ${config.prefix}${cleanCommand}, tidak tersedia!`); 64 | }; 65 | }; 66 | } catch (error) { 67 | messages.reply('Terjadi kesalahan pada server.'); 68 | console.error(error); 69 | }; 70 | }; -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Information 3 | * Creator / Developer: Dani Ramdani (Dani Techno.) - FullStack Engineer 4 | * Contact creator / Developer: 0895 1254 5999 (WhatsApp), contact@danitechno.com (Email) 5 | */ 6 | 7 | /* Thanks to 8 | * Dani Techno. - FullStack Engineer (Creator / Developer) 9 | * @danitech/wa-web-api (Library "WhatsApp Web API" provider) 10 | */ 11 | 12 | const server = require('@danitech/wa-web-api'); 13 | const fs = require('fs'); 14 | const chalk = require('chalk'); 15 | const config = require('./config/settings.js'); 16 | const client = require('./includes/client.js'); 17 | 18 | const startServer = (config, client) => { 19 | return server.start(config, client); 20 | }; 21 | 22 | startServer(config, client); -------------------------------------------------------------------------------- /nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "ignore": ["index.js"], 3 | "ext": "js" 4 | } 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "whatsapp-bot", 3 | "version": "0.0.0", 4 | "private": true, 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index.js", 8 | "dev": "nodemon index.js" 9 | }, 10 | "dependencies": { 11 | "@danitech/wa-web-api": "latest", 12 | "fs": "latest", 13 | "chalk": "^4.1.2" 14 | }, 15 | "devDependencies": { 16 | "nodemon": "~3.0.1" 17 | } 18 | } --------------------------------------------------------------------------------