Emit an event with the specified type and arguments
+Event arguments, including onType to specify the event type
+Listen for specific user events
+Type of event to monitor
+Function to call with event data
+Generated using TypeDoc
+Adds participant to Group
+Chat id ('0000000000-00000000@g.us' or '000000000000000000@g.us')
+Participants id '000000000000@c.us'
+Creates a new chat group
+Group name
+Participants id '000000000000@c.us'
+Decrypts message file
+Message object
+Decrypted file buffer (null otherwise)
+Listen to interface changes.
+Listen to deleted messages.
+Listen to edited messages.
+Listen to new messages.
+Listen to message acknowledgment (read receipt).
+Listen to introductory reactions.
+Listen to reaction messages.
+Parameters to change group description
+group number
+group description
+Parameters to change group image
+group number
+of image
+Generated using TypeDoc
+Decrypts message file
+Message object
+Decrypted file buffer (null otherwise)
+Listen to interface changes.
+Listen to deleted messages.
+Listen to edited messages.
+Listen to new messages.
+Listen to message acknowledgment (read receipt).
+Listen to introductory reactions.
+Listen to reaction messages.
+Generated using TypeDoc
+Listen to interface changes.
+Listen to deleted messages.
+Listen to edited messages.
+Listen to new messages.
+Listen to message acknowledgment (read receipt).
+Listen to introductory reactions.
+Listen to reaction messages.
+Generated using TypeDoc
+Adds participant to Group
+Chat id ('0000000000-00000000@g.us' or '000000000000000000@g.us')
+Participants id '000000000000@c.us'
+Check if the number exists
+phone number
+Creates a new chat group
+Group name
+Participants id '000000000000@c.us'
+Decrypts message file
+Message object
+Decrypted file buffer (null otherwise)
+returns a list of contacts
+contacts
+Get information from the connected number
+Current host device details
+Get version of the current whatsapp
+Listen to interface changes.
+Listen to deleted messages.
+Listen to edited messages.
+Listen to new messages.
+Listen to message acknowledgment (read receipt).
+Listen to introductory reactions.
+Listen to reaction messages.
+Get screenshot
+base64 image
+Parameters to change group description
+group number
+group description
+Parameters to change group image
+group number
+of image
+Generated using TypeDoc
+Listen to interface changes.
+Listen to deleted messages.
+Listen to edited messages.
+Listen to new messages.
+Listen to message acknowledgment (read receipt).
+Listen to introductory reactions.
+Listen to reaction messages.
+Generated using TypeDoc
+Adds participant to Group
+Chat id ('0000000000-00000000@g.us' or '000000000000000000@g.us')
+Participants id '000000000000@c.us'
+Check if the number exists
+phone number
+Creates a new chat group
+Group name
+Participants id '000000000000@c.us'
+Decrypts message file
+Message object
+Decrypted file buffer (null otherwise)
+returns a list of contacts
+contacts
+Get information from the connected number
+Current host device details
+Get version of the current whatsapp
+Listen to interface changes.
+Listen to deleted messages.
+Listen to edited messages.
+Listen to new messages.
+Listen to message acknowledgment (read receipt).
+Listen to introductory reactions.
+Listen to reaction messages.
+Get screenshot
+base64 image
+Send audio file
+Chat id
+Path file
+Send audio base64
+Chat id
+base64 data
+Sends file from path
+Chat id
+File path
+Sends image message
+Chat id
+File path or http link
+Sends image message base64
+Chat id
+File path, http link or base64Encoded
+Sends a text message to given chat
+chat id: xxxxx@us.c
+text message
+Parameters to change group description
+group number
+group description
+Parameters to change group image
+group number
+of image
+Generated using TypeDoc
+Adds participant to Group
+Chat id ('0000000000-00000000@g.us' or '000000000000000000@g.us')
+Participants id '000000000000@c.us'
+Check if the number exists
+phone number
+Creates a new chat group
+Group name
+Participants id '000000000000@c.us'
+Decrypts message file
+Message object
+Decrypted file buffer (null otherwise)
+returns a list of contacts
+contacts
+Get information from the connected number
+Current host device details
+Get version of the current whatsapp
+Listen to interface changes.
+Listen to deleted messages.
+Listen to edited messages.
+Listen to new messages.
+Listen to message acknowledgment (read receipt).
+Listen to introductory reactions.
+Listen to reaction messages.
+Get screenshot
+base64 image
+Send audio file
+Chat id
+Path file
+Send audio base64
+Chat id
+base64 data
+Sends file from path
+Chat id
+File path
+Sends image message
+Chat id
+File path or http link
+Sends image message base64
+Chat id
+File path, http link or base64Encoded
+Sends a text message to given chat
+chat id: xxxxx@us.c
+text message
+Parameters to change group description
+group number
+group description
+Parameters to change group image
+group number
+of image
+Generated using TypeDoc
+Decrypts message file
+Message object
+Decrypted file buffer (null otherwise)
+Listen to interface changes.
+Listen to deleted messages.
+Listen to edited messages.
+Listen to new messages.
+Listen to message acknowledgment (read receipt).
+Listen to introductory reactions.
+Listen to reaction messages.
+Generated using TypeDoc
+send an audio message
+send audio in base64
+send file message
+send image file
+send image in base64
+send text message
+Generated using TypeDoc
+Conflic page, when there are another whatsapp web openned.
+Connection.
+Deprecated page.
+Chat page.
+Offline page, when there are no internet.
+Blocked page, by proxy.
+QR code page.
+Blocked page.
+Loading page, waiting data from smartphone.
+Blocked page.
+Generated using TypeDoc
+user connection information
+receive which interface the user is on!
+Receive new messages deleted
+Receive new messages edited
+monitor new messages
+monitor the status of a message
+Receive new message intro reactions emoji (It is triggered upon entering the chat, loading all available emojis. It is also triggered when a new emoji is sent in any chat)
+Receive new messagens reactions emoji
+receive QRCODE updates
+Generated using TypeDoc
+Generated using TypeDoc
+Auto close called!
+The browser has closed
+Process chromium download
+Starting browser
+Opening whatsapp page
+Error open browser
+Error open whatzapp
+Website accessed successfully
+Generated using TypeDoc
+++This project was developed to help the community that uses whatsapp as a way to implement an API quickly and effectively, for companies and much more! Thank you for being part of this family.
+
You can use this project in two ways, the first is using Web Services using a set of well-defined operations, the POST, GET, PUT and DELETE methods, the second option is to use the bot in raw form, without using a Web Services.
+ + + + +Do you have any doubt? Need help? Join our whatsapp group and ask your questions with other people!
+ +Use the stable version:
+> npm i --save hydra-bot
+
+ or for Nightly releases:
+> npm i --save https://github.com/jonalan7/Hydra-bot/releases/download/nightly/hydra-nightly.tgz
+
+ Terminal Admin:
+> yarn admin
+
+ Install yarn Ubuntu:
+> curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
+> echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
+> sudo apt update && sudo apt install yarn
+> yarn
+
+
+ The service will be started on localhost on port 8080
+const hydraBot = require('hydra-bot');
+(async () => {
+ // start Web Service
+ const WS = await hydraBot.initWs();
+})();
+
+
+ If you want to work in free mode, using only the bot, dry the necessary information!
+const hydraBot = require('hydra-bot');
+const mime = require('mime-types');
+const fs = require('fs');
+
+(async () => {
+ let client;
+ // start bot service
+ const ev = await hydraBot.initServer();
+
+ // return to current whatsapp interface
+ ev.on('interfaceChange', (change) => {
+ console.log('interfaceChange: ', change);
+ });
+
+ // return qrcode parameters
+ ev.on('qrcode', (qrcode) => {
+ console.log('qrcode: ', qrcode);
+ });
+
+ // return connection information
+ ev.on('connection', async (conn) => {
+ // browser information!
+ if (conn.statusFind === 'browser') {
+ console.log('info Browser: ', conn.text);
+ }
+
+ // Was connected to whatsapp chat
+ if (conn.connect) {
+ client = conn.client; // class client from hydra-bot
+ const getMe = await client.getHost();
+ const hostNumber = getMe.id._serialized; // number host
+ console.log('Host Number: ', hostNumber);
+
+ // send a text message
+ await client
+ .sendMessage({
+ to: hostNumber, // you can pass the contact number or group number
+ body: "hi i'm hydra bot", // message text
+ options: {
+ type: 'sendText', // shipping type
+ },
+ })
+ .then((result) => {
+ console.log(result); // message result
+ })
+ .catch((error) => {
+ console.log(error); // message error
+ });
+ }
+ });
+
+ // return receive new messages
+ ev.on('newMessage', async (newMsg) => {
+ // when is received
+ if (!newMsg.result.fromMe) {
+ // message received!
+ console.log('NewMessageReceived: ', newMsg.result);
+ // dowload files
+ if (newMsg.result.isMedia) {
+ const buffer = await client.decryptFile(newMsg.result);
+ // At this point you can do whatever you want with the buffer
+ // Most likely you want to write it into a file
+ const fileName = `some-file-name.${mime.extension(
+ newMsg.result.mimetype
+ )}`;
+ fs.writeFile(fileName, buffer, (err) => {
+ if (err) {
+ console.log(err);
+ }
+ });
+ }
+ }
+ // when is it sent
+ if (!!newMsg.result.fromMe) {
+ // Message sent
+ console.log('NewMessageSent: ', newMsg.result);
+ }
+ });
+
+ // returns the status of each message
+ ev.on('newOnAck', async (event) => {
+ console.log('id Message: ', event.result.id._serialized); // message id
+ console.log('Status Message: ', event.result.ack); // -7 = MD_DOWNGRADE, -6 = INACTIVE, -5 = CONTENT_UNUPLOADABLE, -4 = CONTENT_TOO_BIG, -3 = CONTENT_GONE, -2 = EXPIRED, -1 = FAILED, 0 = CLOCK, 1 = SENT, 2 = RECEIVED, 3 = READ, 4 = PLAYED
+ console.log('From Message: ', event.result.from); // from message
+ console.log('To Message: ', event.result.to); // to message
+ });
+})();
+
+
+ Puppeteer takes care of the file downloading. The decryption is being done as + fast as possible (outruns native methods). Supports big files!
+const hydraBot = require('hydra-bot');
+const fs = require('fs');
+const mime = require('mime-types');
+
+(async () => {
+ let client;
+ // start bot service
+ const ev = await hydraBot.initServer();
+
+ // return connection information
+ ev.on('connection', async (conn) => {
+ // Was connected to whatsapp chat
+ if (conn.connect) {
+ client = conn.client;
+ }
+ });
+
+ ev.on('newMessage', async (newMsg) => {
+ // when is received
+ if (!newMsg.result.fromMe) {
+ // message received!
+ console.log('NewMessageReceived: ', newMsg.result);
+ // dowload files
+ if (newMsg.result.isMedia) {
+ const buffer = await client.decryptFile(newMsg.result);
+ // At this point you can do whatever you want with the buffer
+ // Most likely you want to write it into a file
+ const fileName = `some-file-name.${mime.extension(
+ newMsg.result.mimetype
+ )}`;
+ fs.writeFile(fileName, buffer, (err) => {
+ if (err) {
+ console.log(err);
+ }
+ });
+ }
+ }
+ });
+})();
+
+
+ const hydraBot = require('hydra-bot');
+
+hydraBot.initServer({
+ session: 'session', // Name of the token to be generated, a folder with all customer information will be created
+ pathNameToken: 'token', // The path and name of the folder where the client tokens will be saved
+ printQRInTerminal: true, // The QR CODE will be printed on the terminal if true
+ updatesLog: true, // Logs info updates automatically in terminal
+ timeAutoClose: 60000, // If you don't read the QR CODE by default 60 seconds, it will automatically close the client's browser to save memory, if you want to disable it, set 0 or false
+ mkdirFolderToken: '', // Token folder path, only inside the project
+ puppeteerOptions: {
+ headless: true, // Start the project with the browser open or not!
+ args: [], // Additional arguments to pass to the browser instance. adding any parameter you will replace the default args of the project
+ executablePath: 'useChrome', // The browser that will be used for the project, you can specify a path, if you don't pass any parameters it will open the installed browser.
+ },
+});
+
+
+ const hydraBot = require('hydra-bot');
+
+hydraBot.initWs({
+ hostServer: 'http://localhost',
+ port: '8080',
+ url: '', // point a URL to receive a callback!
+ authentication: true, // ask for authentication in routes
+ pathNameToken: 'token', // The path and name of the folder where the client tokens will be saved
+ printQRInTerminal: true, // The QR CODE will be printed on the terminal if true
+ updatesLog: true, // Logs info updates automatically in terminal
+ timeAutoClose: 60000, // If you don't read the QR CODE by default 60 seconds, it will automatically close the client's browser to save memory, if you want to disable it, set 0 or false
+ mkdirFolderToken: '', // Token folder path, only inside the project
+ puppeteerOptions: {
+ headless: true, // Start the project with the browser open or not!
+ args: [], // Additional arguments to pass to the browser instance. adding any parameter you will replace the default args of the project
+ executablePath: 'useChrome', // The browser that will be used for the project, you can specify a path, if you don't pass any parameters it will open the installed browser.
+ },
+});
+
+
+ To start the administration interface use:
+> yarn admin
+
+ List of commands in the terminal:
+Command | +Description | +
---|---|
/create |
+ Create user | +
/delete |
+ Delete user | +
/selectid |
+ Show user by id | +
/selectname |
+ Select user by name | +
/getall |
+ List all users | +
/deactivate |
+ Disable user | +
/activate |
+ Activate User | +
/changename |
+ Change username | +
/password |
+ Change user password | +
/cls |
+ Clear screen/terminal | +
/help |
+ List all commands for administration in terminal | +
/exit |
+ Exit manager | +
REST API
Headers
, to be able to access them, to create a administrator{
+ "Content-Type": "application/json",
+ "admin": "admin",
+ "admin_pass": "admin"
+}
+
+
+ Type | +Route to browser | +Description | +Body | +
---|---|---|---|
POST | +/create_user |
+ Create user | +{"name":"USE","password":"USER PASSWORD"} |
+
DEL | +/delete_user/ID_USE |
+ Delete user | +EMPTY |
+
GET | +/get_user_by_id/ID_USE |
+ Show user by ID | +EMPTY |
+
GET | +/get_all_users |
+ List all users | +EMPTY |
+
PUT | +/deactivate_user |
+ Disable user | +{"id":"USER ID"} |
+
PUT | +/activate_user |
+ Activate User | +{"id":"USER ID"} |
+
PUT | +/change_name |
+ Change username | +{"id":"USER ID","name":"NEW USERNAME"} |
+
PUT | +/change_password |
+ Change user password | +{"id":"USER ID","password":"NEW SECURE PASSWORD"} |
+
++ +Note: Parameters can be changed during development!
+
Headers
of user (default, username = 'user', password = 'user').The headers must be parameterized as :
+{
+ "Content-Type": "application/json",
+ "user": "user",
+ "user_pass": "user"
+}
+
+
+ if you want to receive a callback on a specific url, pass the url parameter in the connect route.
+ +Type | +Route to browser | +Description | +Body | +
---|---|---|---|
POST | +/connect |
+ Start connection with Whatsapp | +{ "url": "http://localhost:8080/webhooktest" } |
+
POST | +/sendtext |
+ Send a text to a number | +{ "to": "contact number", "body": "message"} |
+
POST | +/sendFile |
+ Send file to a number | +{ "to": "contact number", "file_path": "https://docs.marklogic.com/guide/node-dev.pdf", "file_name": "node.js" } |
+
POST | +/sendAudio |
+ Send audio | +{ "to": "contact number", "url_mp3": "https://cdn.freesound.org/previews/620/620094_4935038-lq.mp3", "file_name": "node.js" } |
+
POST | +/sendImage |
+ Send image message | +{ "to": "contact number", "url_img": "https://i.pinimg.com/564x/a9/b1/18/a9b118761788b1ab260aae2835c468cd.jpg" } |
+
POST | +/disconnect |
+ Disconnecting from the server | +EMPTY | +
POST | +/check_user |
+ Check if the entered user exists | +EMPTY | +
Type | +Route to browser | +Description | +Body | +
---|---|---|---|
GET | +/get_all_contacts |
+ Retrieve contacts | +EMPTY |
+
GET | +/check_connect |
+ check if the client is connected | +EMPTY |
+
GET | +/last_qrcode |
+ Check if the QR-Code is active | +EMPTY |
+
GET | +/screenshot |
+ Get screenshot | +EMPTY |
+
You must be logged in to use these functions!
+ +to
can be <phone Number>@c.us
or <phone Number>-<groupId>@g.us
or <phone Number><groupId>@g.us
you can send messages only using one function!
+// send text message
+await client
+ .sendMessage({
+ to: '0000000000@c.us', // you can pass the contact number or group number
+ body: 'A message sent by hydra-bot', // message text
+ options: {
+ type: 'sendText', // shipping type
+ },
+ })
+ .then((result) => {
+ console.log(result); // message result
+ })
+ .catch((error) => {
+ console.log(error); // message error
+ });
+
+// send files
+await client
+ .sendMessage({
+ to: '0000000000@c.us', // you can pass the contact number or group number
+ body: './file.pdf', // you can use a directory or use a url
+ options: {
+ type: 'sendFile', // shipping type
+ filename: 'filename', // put the file name here
+ },
+ })
+ .then((result) => {
+ console.log(result); // message result
+ })
+ .catch((error) => {
+ console.log(error); // message error
+ });
+
+// send file audio
+await client
+ .sendMessage({
+ to: '0000000000@c.us', // you can pass the contact number or group number
+ body: './file.mp3', // you can use a directory or use a url
+ options: {
+ type: 'sendAudio', // shipping type
+ },
+ })
+ .then((result) => {
+ console.log(result); // message result
+ })
+ .catch((error) => {
+ console.log(error); // message error
+ });
+
+// Send audio file base64
+await client
+ .sendMessage({
+ to: '0000000000@c.us', // you can pass the contact number or group number
+ body: base64MP3, // you can use a directory or use a url
+ options: {
+ type: 'sendAudioBase64', // shipping type
+ },
+ })
+ .then((result) => {
+ console.log(result); // message result
+ })
+ .catch((error) => {
+ console.log(error); // message error
+ });
+
+// Send image message
+await client
+ .sendMessage({
+ to: '0000000000@c.us', // you can pass the contact number or group number
+ body: './file.jpg', // you can use a directory or use a url
+ options: {
+ type: 'sendImage', // shipping type
+ caption: 'image text', // image text
+ },
+ })
+ .then((result) => {
+ console.log(result); // message result
+ })
+ .catch((error) => {
+ console.log(error); // message error
+ });
+
+// Send image Base64
+await client
+ .sendMessage({
+ to: '0000000000@c.us', // you can pass the contact number or group number
+ body: base64IMG, // you can use a directory or use a url
+ options: {
+ type: 'sendImageFromBase64', // shipping type
+ caption: 'image text', // image text
+ },
+ })
+ .then((result) => {
+ console.log(result); // message result
+ })
+ .catch((error) => {
+ console.log(error); // message error
+ });
+
+
+ // Sends a text message to given chat
+await client
+ .sendText('0000000000@c.us', 'A message sent by hydra-bot')
+ .then((result) => {
+ console.log(result); // message result
+ })
+ .catch((error) => {
+ console.log(error); // message error
+ });
+
+// Sends file from path
+await client
+ .sendFile('0000000000@c.us', './file.pdf', { filename: 'filename' })
+ .then((result) => {
+ console.log(result); // message result
+ })
+ .catch((error) => {
+ console.log(error); // message error
+ });
+
+// Send audio file
+await client
+ .sendAudio('0000000000@c.us', './file.mp3')
+ .then((result) => {
+ console.log(result); // message result
+ })
+ .catch((error) => {
+ console.log(error); // message error
+ });
+
+// Send audio base64
+await client
+ .sendAudioBase64('0000000000@c.us', base64MP3)
+ .then((result) => {
+ console.log(result); // message result
+ })
+ .catch((error) => {
+ console.log(error); // message error
+ });
+
+// Send image message
+await client
+ .sendImage('0000000000@c.us', './file.jpg', { caption: 'image text' })
+ .then((result) => {
+ console.log(result); // message result
+ })
+ .catch((error) => {
+ console.log(error); // message error
+ });
+
+// Send image base64
+await client
+ .sendImageFromBase64('0000000000@c.us', base64IMG, { caption: 'image text' })
+ .then((result) => {
+ console.log(result); // message result
+ })
+ .catch((error) => {
+ console.log(error); // message error
+ });
+
+
+ // Get device info
+await client.getHost();
+
+
+ // returns a list of contacts
+const contacts = await client.getAllContacts();
+
+// return whatsapp version
+const version = await client.getWAVersion();
+
+
+ Group number example <phone Number>-<groupId>@g.us
or <phone Number><groupId>@g.us
// Create group
+await client
+ .createGroup('Group name', ['111111111111@c.us', '222222222222@c.us'])
+ .then((result) => {
+ console.log(result); // message result
+ })
+ .catch((error) => {
+ console.log(error); // message error
+ });
+
+// Add participant to Group
+await client
+ .addParticipant('00000000-000000@g.us', [
+ '111111111111@c.us',
+ '222222222222@c.us',
+ ])
+ .then((result) => {
+ console.log(result); // message result
+ })
+ .catch((error) => {
+ console.log(error); // message error
+ });
+
+// Change group description
+await client
+ .setGroupDescription('00000000-000000@g.us', 'group description')
+ .then((result) => {
+ console.log(result); // message result
+ })
+ .catch((error) => {
+ console.log(error); // message error
+ });
+
+// Change group image
+await client
+ .setGroupImage('00000000000000@g.us', './file.jpg')
+ .then((result) => {
+ console.log(result); // message result
+ })
+ .catch((error) => {
+ console.log(error); // message error
+ });
+
+
+ List of events triggered in the project
+
+// Event triggered when there's a change in the WhatsApp interface
+// The change information can include elements like screen changes or navigation.
+ev.on("interfaceChange", (change: any) => {
+ // Processes the interface change, like navigation between screens
+ console.log("Interface change detected:", change);
+});
+
+// Event triggered when a QR code is generated, typically used for authentication
+// The QR code is sent to the client as a string or object containing data for login.
+ev.on("qrcode", (qrcode) => {
+ // Displays the generated QR code for WhatsApp Web authentication
+ console.log("QR Code for authentication:", qrcode);
+});
+
+// Event triggered when there is a connection change, such as connection loss or establishment
+// Connection data may include network status or connection errors.
+ev.on('connection', async (conn) => {
+ // Displays information about the connection status
+ console.log("Connection status:", conn);
+ if (conn.connect) {
+ // Was connected to whatsapp chat
+ console.error("Has connected");
+ }
+});
+
+// Event triggered when a new message is received
+// The message may include data such as sender, content, timestamp, etc.
+ev.on("newMessage", (newMsg) => {
+ // Displays the data of the new received message
+ console.log("New message received:", newMsg);
+});
+
+// Event triggered when a message is edited
+// The edited message may include the previous content and the new content.
+ev.on("newEditMessage", async (editMessage) => {
+ // Processes the edited message by checking changes in content
+ console.log("Message edited:", editMessage);
+});
+
+// Event triggered when a message is deleted
+// The deleted message may include the message ID and other related details.
+ev.on("newDeleteMessage", async (deleteMessage) => {
+ // Processes the deletion of the message and notifies the user
+ console.log("Message deleted:", deleteMessage);
+});
+
+// Event triggered when there is a new intro reaction (emoji) to a message
+// This can be used to analyze which reactions were added to new messages.
+ev.on("onIntroReactionMessage", async (introReaction) => {
+ // Processes the intro reaction (emoji) to the new message
+ console.log("New intro reaction received:", introReaction);
+});
+
+// Event triggered when an emoji reaction is added to an existing message
+// The reaction may include details like the emoji, sender, and associated message.
+ev.on("onReactionMessage", async (reaction) => {
+ // Processes the reaction added to an existing message
+ console.log("Reaction added to message:", reaction);
+});
+
+// Event triggered to return the status of each message (e.g., read, delivered, etc.)
+// This can include data such as delivery and read status, allowing message state tracking.
+ev.on("newOnAck", async (event) => {
+ // Processes the acknowledgment status of the message
+ console.log("Message ack status:", event);
+});
+
+
+
+ Building the hydra-bot is very simple
+ +To build the entire project just run
+> npm run build
+
+
+ Run a test inside the project
+> npm run build:dev
+
+
+ Maintainers are needed, I cannot keep with all the updates by myself. If you are + interested please open a Pull Request.
+ +Pull requests are welcome. For major changes, please open an issue first to + discuss what you would like to change.
+Generated using TypeDoc
+Generated using TypeDoc
+Generated using TypeDoc
+initial function optional parameters
+token folder path, only inside the project
+the path and name of the folder where the client tokens will be saved
+the QR CODE will be printed on the terminal
+puppeteer Options
+name of the token to be generated, a folder with all customer information will be created
+if you don't read the QR CODE by default 60 seconds, it will automatically close the client's browser to save memory, if you want to disable it, set 0 or false
+logs info updates automatically in terminal
+Generated using TypeDoc
+Generated using TypeDoc
+Generated using TypeDoc
+Generated using TypeDoc
+Generated using TypeDoc
+Generated using TypeDoc
+Generated using TypeDoc
+additional arguments to pass to the browser instance. adding any parameter you will replace the default args of the project
+chromium version the project should use
+when started, the project will automatically download Chromium if it can't find it
+the browser that will be used for the project, you can specify a path, if you don't pass any parameters it will open the installed browser.
+specify whether the browser is visible or invisible, invisible to true and visible to false
+Generated using TypeDoc
+Generated using TypeDoc
+Generated using TypeDoc
+Generated using TypeDoc
+Generated using TypeDoc
+Generated using TypeDoc
+The Hydra-Bot Project is an open-source application developed entirely in TypeScript and Node.js. To use it, it is essential to have Node.js installed in your environment, as it is responsible for running the application's code. Additionally, you will need npm (Node.js package manager) to download and manage the dependencies necessary for the project to work.
+You can download Node.js, which includes npm, directly from the official website: + Download Node.js and npm
+ +To ensure that Node.js and npm are correctly installed, you can run the following commands in your terminal to check their versions:
+To check the Node.js version:
+node -v
+
+ This command will display the installed Node.js version. + To check the npm version:
+npm -v
+
+ This command will display the installed npm version.
+ +npm is the default package manager for the Node.js JavaScript runtime environment. It is used to download and manage libraries, including the latest version of Hydra-Bot, for your machine.
+ +You can install the latest version of Hydra-Bot directly via npm using the following command:
+npm i --save hydra-bot
+
+
+ If you want access to the current development version (beta), which includes features not yet officially released, you can download it from GitHub with the following command:
+npm i --save https://github.com/jonalan7/Hydra-bot/releases/download/nightly/hydra-nightly.tgz
+
+
+ In this mode, you have complete freedom to create your custom automations. + You can leverage the full power of Node.js to program and configure the functionalities as you wish.
+ + +This mode is ideal for those less familiar with Node.js or those who prefer using predefined operations. + It provides a set of ready-to-use routes utilizing the HTTP methods POST, GET, PUT, and DELETE, allowing for simple and efficient interaction with the system.
+ +Generated using TypeDoc
+If you want to work in free mode, using only the bot, dry the necessary information!
+
+const hydraBot = require('hydra-bot');
+
+(async () => {
+ let client;
+ // start bot service
+ const ev = await hydraBot.initServer();
+
+ // return to current whatsapp interface
+ ev.on('interfaceChange', (change) => {
+ console.log("interfaceChange: ", change);
+ });
+
+ // return qrcode parameters
+ ev.on('qrcode', (qrcode) => {
+ console.log('qrcode: ', qrcode);
+ });
+
+ // return connection information
+ ev.on('connection', async (conn) => {
+
+ // browser information!
+ if (conn.statusFind === 'browser') {
+ console.log('info Browser: ', conn.text);
+ }
+
+ // Was connected to whatsapp chat
+ if (conn.connect) {
+ client = conn.client; // class client from hydra-bot
+ const getMe = await client.getHost();
+ const hostNumber = getMe.id._serialized; // number host
+ console.log('Host Number: ', hostNumber);
+ // send a text message
+ await client.sendMessage({
+ to: hostNumber, // you can pass the contact number or group number
+ body: "hi i'm hydra bot", // message text
+ options: {
+ type: 'sendText', // shipping type
+ }
+ }).then((result) => {
+ console.log(result); // message result
+ }).catch((error) => {
+ console.log(error); // message error
+ });
+
+ }
+ });
+
+ ev.on('newMessage', async (newMsg) => {
+ // when is received
+ if (!newMsg.result.fromMe) {
+ // message received!
+ console.log('NewMessageReceived: ', newMsg.result);
+ }
+ // when is it sent
+ if (!!newMsg.result.fromMe) {
+ // Message sent
+ console.log('NewMessageSent: ', newMsg.result);
+ }
+ });
+
+ // returns the status of each message
+ ev.on('newOnAck', async (event) => {
+ console.log('id Message: ', event.result.id._serialized); // message id
+ console.log('Status Message: ', event.result.ack); // -7 = MD_DOWNGRADE, -6 = INACTIVE, -5 = CONTENT_UNUPLOADABLE, -4 = CONTENT_TOO_BIG, -3 = CONTENT_GONE, -2 = EXPIRED, -1 = FAILED, 0 = CLOCK, 1 = SENT, 2 = RECEIVED, 3 = READ, 4 = PLAYED
+ console.log('From Message: ', event.result.from); // from message
+ console.log('To Message: ', event.result.to); // to message
+ });
+
+})();
+
+ Generated using TypeDoc
+hydra-bot
library allows you to tailor the service's behavior to fit your application requirements.The web service will run locally on localhost
using port 8080
. Below is an example of how to initialize the service:
const hydraBot = require('hydra-bot');
+
+(async () => {
+ // Initialize and start the Web Service
+ const WS = await hydraBot.initWs();
+})();
+
+
+ The Web Service includes commands for administration and control directly through the terminal. These commands allow administrators to manage and monitor the service effectively.
+For a complete guide to terminal administration, visit: + Terminal Administration Guide
+ +The service also supports webhook integration for client-side interaction. This feature allows external systems to send and receive real-time data, enabling seamless automation and communication.
+For more information on how to use the client webhook, check out the guide: + Client Webhook Usage Guide
+Generated using TypeDoc
+Use Postman to test the routes! + Postman example + Download Postman
+ +To start the administration interface, run the following command in the terminal:
+> yarn admin
+
+ Install yarn Ubuntu:
+> curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
+> echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
+> sudo apt update && sudo apt install yarn
+> yarn
+
+
+ Administrators are responsible for managing API users via Webhook. They can execute commands that allow creating, deleting, and managing user data.
+ +Here is the list of commands an administrator can use in the terminal to manage users:
+Command | +Description | +
---|---|
/create |
+ Create a new user | +
/delete |
+ Delete an existing user | +
/selectid |
+ Show a user by ID | +
/selectname |
+ Show a user by name | +
/getall |
+ List all users | +
/deactivate |
+ Disable user | +
/activate |
+ Activate User | +
/changename |
+ Change a user's name | +
/password |
+ Change a user's password | +
/cls |
+ Clear screen/terminal | +
/help |
+ List all available commands for administration | +
/exit |
+ Exit the administration manager | +
These routes allow you to manage and query users using a REST API. An administrator can access these routes by authenticating with a specific header that includes the admin credentials.
+To authenticate requests via Webhook, you need to include the following headers in the request:
+{
+ "Content-Type" : "application/json",
+ "admin" : "admin",
+ "admin_pass" : "admin"
+}
+
+
+ With an administrator (there is a default administrator, the username and password as admin), he can access via Web Service with the following routes:
+Type | +Route to browser | +Description | +Body | +
---|---|---|---|
POST | +/create_user |
+ Create user | +{"name":"USE","password":"USER PASSWORD"} |
+
DEL | +/delete_user/ID_USE |
+ Delete user | +EMPTY |
+
GET | +/get_user_by_id/ID_USE |
+ Show user by ID | +EMPTY |
+
GET | +/get_all_users |
+ List all users | +EMPTY |
+
PUT | +/deactivate_user |
+ Disable user | +{"id":"USER ID"} |
+
PUT | +/activate_user |
+ Activate User | +{"id":"USER ID"} |
+
PUT | +/change_name |
+ Change username | +{"id":"USER ID","name":"NEW USERNAME"} |
+
PUT | +/change_password |
+ Change user password | +{"id":"USER ID","password":"NEW SECURE PASSWORD"} |
+
POST /create_user
: This route creates a new user. Send a JSON body containing the name and password of the user you want to create.
DELETE /delete_user/USER_ID
: This route deletes a specific user by their USER_ID. No body is required in the request.
GET /get_user_by_id/USER_ID
: To retrieve a user by their ID, send a GET request. No body is required.
GET /get_all_users
: This route lists all users. No body is required in the request.
PUT /deactivate_user
: To deactivate a user, send a JSON body containing the USER_ID of the user you want to disable.
PUT /activate_user
: This route activates a disabled user. Send the USER_ID in the request body.
PUT /change_name
: To change a user's name, send the USER_ID and the new name in the request body.
PUT /change_password
: This route changes a user's password. Send the USER_ID and the new password in the request body.
Generated using TypeDoc
+Use Postman to test routes! + Postman example + Download Postman
+ +All whatsapp connection wheels have a pattern of Headers
of user.
+ The headers must be parameterized as :
{
+ "Content-Type" : "application/json",
+ "user" : "user",
+ "user_pass" : "user"
+}
+
+
+ if you want to receive a callback on a specific url, pass the url parameter in the connect route.
+ +Type | +Route to browser | +Description | +Body | +
---|---|---|---|
POST | +/connect |
+ Start connection with Whatsapp | +{ "url": "http://localhost:8080/webhooktest" } |
+
POST | +/sendtext |
+ Send a text to a number | +{ "to": "contact number", "body": "message"} |
+
POST | +/sendFile |
+ Send file to a number | +{ "to": "contact number", "file_path": "https://docs.marklogic.com/guide/node-dev.pdf", "file_name": "node.js" } |
+
POST | +/sendAudio |
+ Send audio | +{ "to": "contact number", "url_mp3": "https://cdn.freesound.org/previews/620/620094_4935038-lq.mp3" } |
+
POST | +/sendImage |
+ Send image message | +{ "to": "contact number", "url_img": "https://i.pinimg.com/564x/a9/b1/18/a9b118761788b1ab260aae2835c468cd.jpg" } |
+
POST | +/disconnect |
+ Disconnecting from the server | +EMPTY | +
POST | +/check_user |
+ Check if the entered user exists | +EMPTY | +
Type | +Route to browser | +Description | +Body | +
---|---|---|---|
GET | +/get_all_contacts |
+ Retrieve contacts | +EMPTY |
+
GET | +/check_connect |
+ check if the client is connected | +EMPTY |
+
GET | +/last_qrcode |
+ Check if the QR-Code is active | +EMPTY |
+
Generated using TypeDoc
+to
can be <phone Number>@c.us
, <phone Number>-<groupId>@g.us
, or <phone Number><groupId>@g.us
.To use these functions, it is necessary to initialize the bot.
Click here to learn more.
Event triggered when there's a change in the WhatsApp interface
+// The change information can include elements like screen changes or navigation.
+ev.on("interfaceChange", (change: any) => {
+ // Processes the interface change, like navigation between screens
+ console.log("Interface change detected:", change);
+});
+
+
+ Event triggered when a QR code is generated, typically used for authentication
+// The QR code is sent to the client as a string or object containing data for login.
+ev.on("qrcode", (qrcode) => {
+ // Displays the generated QR code for WhatsApp Web authentication
+ console.log("QR Code for authentication:", qrcode);
+});
+
+
+ Event triggered when there is a connection change, such as connection loss or establishment
+// Connection data may include network status or connection errors.
+ev.on('connection', async (conn) => {
+ // Displays information about the connection status
+ console.log("Connection status:", conn);
+ if (conn.connect) {
+ // Was connected to whatsapp chat
+ console.error("Has connected");
+ }
+});
+
+
+ Event triggered when a message is edited
+// The edited message may include the previous content and the new content.
+ev.on("newEditMessage", async (editMessage) => {
+ // Processes the edited message by checking changes in content
+ console.log("Message edited:", editMessage);
+});
+
+
+ Event triggered when a message is deleted
+// The deleted message may include the message ID and other related details.
+ev.on("newDeleteMessage", async (deleteMessage) => {
+ // Processes the deletion of the message and notifies the user
+ console.log("Message deleted:", deleteMessage);
+});
+
+
+ Event triggered when there is a new intro reaction (emoji) to a message
+// This can be used to analyze which reactions were added to new messages.
+ev.on("onIntroReactionMessage", async (introReaction) => {
+ // Processes the intro reaction (emoji) to the new message
+ console.log("New intro reaction received:", introReaction);
+});
+
+
+ Event triggered when an emoji reaction is added to an existing message
+// The reaction may include details like the emoji, sender, and associated message.
+ev.on("onReactionMessage", async (reaction) => {
+ // Processes the reaction added to an existing message
+ console.log("Reaction added to message:", reaction);
+});
+
+
+ Event triggered to return the status of each message (e.g., read, delivered, etc.)
+// This can include data such as delivery and read status, allowing message state tracking.
+ev.on("newOnAck", async (event) => {
+ // Processes the acknowledgment status of the message
+ console.log("Message ack status:", event);
+});
+
+ Generated using TypeDoc
+to
can be <phone Number>@c.us
, <phone Number>-<groupId>@g.us
, or <phone Number><groupId>@g.us
.To use these functions, it is necessary to initialize the bot.
Click here to learn more.
Retrieve information about the device connected to the bot.
+
+await client.getHost();
+
+
+
+ Retrieve the version of WhatsApp currently in use.
+
+const version = await client.getWAVersion();
+
+
+ Generated using TypeDoc
+data reception functions
+ +to
can be <phone Number>@c.us
, <phone Number>-<groupId>@g.us
, or <phone Number><groupId>@g.us
.To use these functions, it is necessary to initialize the bot.
Click here to learn more.
Returns a list of contacts
+const contacts = await client.getAllContacts();
+
+
+ Check if the number exists
+const result = await client.checkNumber("<phone Number>@c.us");
+
+ Generated using TypeDoc
+to
can be <phone Number>@c.us
, <phone Number>-<groupId>@g.us
, or <phone Number><groupId>@g.us
.To use these functions, it is necessary to initialize the bot.
Click here to learn more.
Send messages separately
+ +Sends a text message to given chat
+await client.sendText("0000000000@c.us", "A message sent by hydra-bot")
+.then((result) => {
+ console.log(result); // message result
+}).catch((error) => {
+ console.log(error); // message error
+});
+
+
+ Sends file from path
+await client.sendFile("0000000000@c.us", './file.pdf', { filename: 'filename' })
+.then((result) => {
+ console.log(result); // message result
+}).catch((error) => {
+ console.log(error); // message error
+});
+
+
+ Send audio file
+await client.sendAudio("0000000000@c.us", './file.mp3')
+.then((result) => {
+ console.log(result); // message result
+}).catch((error) => {
+ console.log(error); // message error
+});
+
+
+ Send audio base64
+await client.sendAudioBase64("0000000000@c.us", base64MP3)
+.then((result) => {
+ console.log(result); // message result
+}).catch((error) => {
+ console.log(error); // message error
+});
+
+
+ Send image message
+await client.sendImage("0000000000@c.us", './file.jpg', { caption: 'image text' })
+.then((result) => {
+ console.log(result); // message result
+}).catch((error) => {
+ console.log(error); // message error
+});
+
+
+ Send image base64
+await client.sendImageFromBase64("0000000000@c.us", base64IMG, { caption: 'image text' })
+.then((result) => {
+ console.log(result); // message result
+}).catch((error) => {
+ console.log(error); // message error
+});
+
+ Generated using TypeDoc
+to
can be <phone Number>@c.us
, <phone Number>-<groupId>@g.us
, or <phone Number><groupId>@g.us
.To use these functions, it is necessary to initialize the bot.
Click here to learn more.
you can send messages only using one function!
+ +// send text message
+await client.sendMessage({
+ to: "0000000000@c.us", // you can pass the contact number or group number
+ body: "A message sent by hydra-bot", // message text
+ options: {
+ type: 'sendText', // shipping type
+ }
+}).then((result) => {
+ console.log(result); // message result
+}).catch((error) => {
+ console.log(error); // message error
+});
+
+
+ // send text message
+await client.sendMessage({
+ to: "0000000000@c.us", // you can pass the contact number or group number
+ body: './file.pdf', // you can use a directory or use a url
+ options: {
+ type: 'sendFile', // shipping type
+ filename: 'filename' // put the file name here
+ }
+}).then((result) => {
+ console.log(result); // message result
+}).catch((error) => {
+ console.log(error); // message error
+});
+
+
+ // send file audio
+await client.sendMessage({
+ to: "0000000000@c.us", // you can pass the contact number or group number
+ body: './file.mp3', // you can use a directory or use a url
+ options: {
+ type: 'sendAudio', // shipping type
+ }
+}).then((result) => {
+ console.log(result); // message result
+}).catch((error) => {
+ console.log(error); // message error
+});
+
+
+ // Send audio file base64
+await client.sendMessage({
+ to: "0000000000@c.us", // you can pass the contact number or group number
+ body: base64MP3, // you can use a directory or use a url
+ options: {
+ type: 'sendAudioBase64', // shipping type
+ }
+}).then((result) => {
+ console.log(result); // message result
+}).catch((error) => {
+ console.log(error); // message error
+});
+
+
+ // Send image message
+await client.sendMessage({
+ to: "0000000000@c.us", // you can pass the contact number or group number
+ body: './file.jpg', // you can use a directory or use a url
+ options: {
+ type: 'sendImage', // shipping type
+ caption: 'image text' // image text
+ }
+}).then((result) => {
+ console.log(result); // message result
+}).catch((error) => {
+ console.log(error); // message error
+});
+
+
+ // Send image Base64
+await client.sendMessage({
+ to: "0000000000@c.us", // you can pass the contact number or group number
+ body: base64IMG, // you can use a directory or use a url
+ options: {
+ type: 'sendImageFromBase64', // shipping type
+ caption: 'image text' // image text
+ }
+}).then((result) => {
+ console.log(result); // message result
+}).catch((error) => {
+ console.log(error); // message error
+});
+
+ Generated using TypeDoc
+Puppeteer takes care of the file downloading. The decryption is being done as fast as possible (outruns native methods). Supports big files!
+const hydraBot = require('hydra-bot');
+const fs = require('fs');
+const mime = require('mime-types');
+
+(async () => {
+ let client;
+ // start bot service
+ const ev = await hydraBot.initServer();
+ // return connection information
+ ev.on('connection', async (conn) => {
+ // Was connected to whatsapp chat
+ if (conn.connect) {
+ client = conn.client;
+ }
+ });
+ ev.on('newMessage', async (newMsg) => {
+ // when is received
+ if (!newMsg.result.fromMe) {
+ // message received!
+ console.log('NewMessageReceived: ', newMsg.result);
+ // dowload files
+ if (newMsg.result.isMedia) {
+ const buffer = await client.decryptFile(newMsg.result);
+ // At this point you can do whatever you want with the buffer
+ // Most likely you want to write it into a file
+ const fileName = `some-file-name.${mime.extension(newMsg.result.mimetype)}`;
+ fs.writeFile(fileName, buffer, (err) => {
+ if (err) {
+ console.log(err);
+ }
+ });
+ }
+ }
+ });
+})();
+
+ Generated using TypeDoc
+to
can be <phone Number>@c.us
, <phone Number>-<groupId>@g.us
, or <phone Number><groupId>@g.us
.To use these functions, it is necessary to initialize the bot.
Click here to learn more.
Create group
+await client.createGroup('Group name', ['111111111111@c.us', '222222222222@c.us'])
+.then((result) => {
+ console.log(result); // message result
+}).catch((error) => {
+ console.log(error); // message error
+});
+
+
+ Add participant
+await client.addParticipant('00000000-000000@g.us', ['111111111111@c.us', '222222222222@c.us'])
+.then((result) => {
+ console.log(result); // message result
+}).catch((error) => {
+ console.log(error); // message error
+});
+
+
+ Change group description
+await client.setGroupDescription('00000000-000000@g.us', 'group description')
+.then((result) => {
+ console.log(result); // message result
+}).catch((error) => {
+ console.log(error); // message error
+});
+
+
+ Change group image
+await client.setGroupImage('00000000000000@g.us', './file.jpg')
+.then((result) => {
+ console.log(result); // message result
+}).catch((error) => {
+ console.log(error); // message error
+});
+
+ Generated using TypeDoc
+
Attribution and behavior change of a given event
+