Giter Club home page Giter Club logo

dbsdenis / hydra-bot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jonalan7/hydra-bot

0.0 0.0 0.0 2.05 MB

The most reliable WhatsApp tool for chatbots with advanced features. Hydra bot is an open source project developed by the JavaScript community with the aim of exporting functions from WhatsApp Web to the node js, . The most complete javascript library for Whatsapp, 100% Open Source.

License: MIT License

JavaScript 48.94% PowerShell 0.75% TypeScript 49.71% Batchfile 0.30% EJS 0.31%

hydra-bot's Introduction

npm version Downloads Average time to resolve an issue Percentage of issues still open

Welcome to Hydra Bot

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.

Supporters

To maintain quality, we are receiving support! We thank you in advance for the opportunity to develop and maintain this project!

Company URL Logo
redrive https://redrive.com.br/
zaplus https://zaplus.chat/
tabchat https://tabchat.com.br/

WhatSapp Group

Do you have any doubt? Need help? Join our whatsapp group and ask your questions with other people!

Installation

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

Getting started Web Service

The service will be started on localhost on port 8080

const hydraBot = require('hydra-bot');
(async () => {
    // start Web Service
    const WS = await hydraBot.initWs();
})();

Getting started bot (the bot in raw form, without using a Web Services).

If you want to work in free mode, using only the bot, dry the necessary information!

const hydraBot = require('hydra-bot');

(async () => {
    // start bot service
    const webpack = await hydraBot.initServer();

    // return to current whatsapp interface
    webpack.on('interfaceChange', (change) => {
        console.log("interfaceChange: ", change);
    });

    // return qrcode parameters
    webpack.on('qrcode', (qrcode) => {
        console.log('qrcode: ', qrcode);
    });

    // return connection information
    webpack.on('connection', async (conn) => {
        console.log("Info connection: ", conn);
        if (conn) {
            // send a text message
            await webpack.sendMessage({
                to: "[email protected]",
                body: "A message sent by hydra-bot",
                options: {
                    type: 'text',
                }
            }).then((result) => {
                console.log(result)
            });
        }
    });

    // return receive new messages
    webpack.on('newMessage', (newMsg) => {
        // when is received
        if (!newMsg.isSentByMe) {
            // message received!
            console.log('NewMessageReceived: ', newMsg);
        }
        // when is it sent
        if (!!newMsg.isSentByMe) {
            // message sent
            console.log('NewMessageSent: ', newMsg);
        }
    });
})();

Optional create parameters (the bot in raw form, without using a Web Services)

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: "false", // 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 parameter it will open chromium.
  }
}
);

Optional create parameters Web Services

const hydraBot = require('hydra-bot');

hydraBot.initWs(
{
  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: "false", // 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 parameter it will open chromium.
  }
}
);

Commands for administration via terminal

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

Routes for handling and querying users.

List of commands using REST API

All user wheels have a pattern of Headers, to be able to access them, to create a administrador (default, username = 'admin', password = 'admin'):
{
    "Content-Type" : "application/json",
    "admin" : "admin",
    "admin_pass" : "admin"
}

List of routes for user management:

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"}

Web Service Routes (more features still under development)

Note: Parameters can be changed during development!

List of routes for managing whatsapp:

All whatsapp connection wheels have a pattern of Headers of user (default, username = 'user', password = 'user').

The headers must be parameterized as :

{
    "Content-Type" : "application/json",
    "user" : "user",
    "user_pass" : "user"
}

Using Webhook

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"}

Basic Functions (more features still under development)

You must be logged in to use these functions!

Here, chatId could be <phoneNumber>@c.us or <phoneNumber>-<groupId>@g.us
// send text message
await webpack.sendMessage({
    to: "[email protected]",
    body: "A message sent by hydra-bot",
    options: {
        type: 'text',
    }
}).then((result) => {
    console.log(result)
});

Debugging

Building the hydra-bot is very simple

Development

To build the entire project just run

> npm run build

Test

run a test inside the project

> npm start

hydra-bot's People

Contributors

jonalan7 avatar dependabot[bot] avatar sousaakira avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.