Git Product home page Git Product logo

jonalan7 / hydra-bot Goto Github PK

View Code? Open in Web Editor NEW
50.0 6.0 18.0 2.39 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.21% TypeScript 51.12% Batchfile 0.14% PowerShell 0.37% EJS 0.15%
api nodejs bot chatbots whatsapp whatsapp-api whatsapp-bot bot-javascript zap-api zap-bot

hydra-bot's People

Contributors

chrisk8er avatar dependabot[bot] avatar jonalan7 avatar sousaakira avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

hydra-bot's Issues

Does this library keep session for long term?

Hi,
I am using in some library that also allow to send msg to users.
But there is a bug in the library i am using, after some times unexpected the session canΧ³t be loaded and i need to remove the folder and scan the qr code from start.

Is this bug happen in your library?

It also important to mention that i am using in pm2.

Second thing, Is this library considiring to be updated when whatsapp makes updates and sometime broken the library?

After updating 1.0.29 show axios error 429

After updating 1.0.29 showing this kind of error while showing qr code

Webhooktest Return object  {
  onType: 'interfaceChange',
  session: 'user',
  result: { displayInfo: 'CONNECTING', mode: 'QR', info: 'OPENING' },
  token: '5cc32e366c87c4cb49e4309b75f57d64'
}
Webhooktest Return object  {
  onType: 'interfaceChange',
  session: 'user',
  result: { displayInfo: 'CONNECTING', mode: 'QR', info: 'PAIRING' },
  token: '5cc32e366c87c4cb49e4309b75f57d64'
}
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "AxiosError: Request failed with status code 429".] {
  code: 'ERR_UNHANDLED_REJECTION'
}
disconnect
child process exited with code 1

image

Reproduce code

const hydraBot = require('hydra-bot');
var serveStatic = require( "serve-static" );
(async () => {
  // start Web Service
  const WS = 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: 'E:\\', // 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.
        }
      }
      );
      
      
})();

The message is send with sucess but a error is generated

my code

client.sendMessage({
  to: data.cs + "@c.us", 
  body: 'message', 
  options: {
      type: 'sendText', // shipping type
  }
})
.then(() => {
   //don't run

})
.catch((err) => {
    console.log("Erro => ",err)
})

return

Erro =>

{
  to: {
    fromMe: true,
    remote: {
      server: 'c.us',
      user: '*',
      _serialized: '*@c.us'
    },
    id: 'ZHZA7T8DXRIT1ZHV',
    self: 'out',
    _serialized: 'true_*@c.us_ZHZA7T8DXRIT1ZHV_out'
  },
  erro: false,
  text: null,
  status: 'OK',
  type: 'sendText',
  body: 'message'
}

Bug

interfaceChange: {
onType: 'interfaceChange',
session: 'session',
result: { displayInfo: 'CONNECTING', mode: 'QR', info: 'SYNCING' }
}
interfaceChange: {
onType: 'interfaceChange',
session: 'session',
result: { displayInfo: 'CONNECTING', mode: 'SYNCING', info: 'NORMAL' }
}
interfaceChange: {
onType: 'interfaceChange',
session: 'session',
result: { displayInfo: 'CONNECTING', mode: 'QR', info: 'OPENING' }
}
interfaceChange: {
onType: 'interfaceChange',
session: 'session',
result: { displayInfo: 'CONNECTING', mode: 'QR', info: 'PAIRING' }
}
interfaceChange: {
onType: 'interfaceChange',
session: 'session',
result: { displayInfo: 'CONNECTING', mode: 'QR', info: 'NORMAL' }
}
info Browser: Auto close called!

MaxListenersExceeededWarning

When I run the my app using

nodemon inde.js

this run without problems
image

but when I try run using

node index.js

the app say

[CON]: initBrowser
[CON]: initWhatsapp
[CON]: openedWhatsapp
(node:6764) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 interfaceChange listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 interfaceChange listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit
    at _addListener (node:events:587:17)
    at EventEmitter.addListener (node:events:605:10)
    at webPack.listener (C:\Users\Admin\Documents\Ag2\node_modules\hydra-bot\dist\webpack\api\layes\listener.layes.js:76:30)
    at webPack.initLitener (C:\Users\Admin\Documents\Ag2\node_modules\hydra-bot\dist\webpack\api\layes\listener.layes.js:71:14)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

And stop here.

"Error open browser" in ubuntu

`const hydraBot = require('hydra-bot');
const mime = require('mime-types');
const fs = require('fs');

(async () => {

console.log('process.platform',process.platform);
let client;
// start bot service
const ev = await hydraBot.initServer({
    session: "session-1",
    pathNameToken:"token-1",
    mkdirFolderToken:'',
    puppeteerOptions: {
        headless: process.platform === 'linux' ? true : false ,
        executablePath: process.platform === 'linux' ? "/usr/bin/google-chrome" : "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
        args: [], // Additional arguments to pass to the browser instance. adding any parameter you will replace the default args of the project
    }
});

// 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;
        // send a text message
        await client.sendMessage({
            to: "[email protected]", // you can pass the contact number or group number
            body: "hi i'm hydra bot", // message text
            options: {
                type: 'text', // 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.isSentByMe) {
        // message received!
        console.log('NewMessageReceived: ', newMsg.result);
        // dowload files
        if (newMsg.result.isMedia === true || newMsg.result.isMMS === true) {
            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) => {
                console.log(err);
            });
        }
    }
    // when is it sent
    if (!!newMsg.result.isSentByMe) {
        // Message sent
        console.log('NewMessageSent: ', newMsg.result);
    }
});

// returns the status of each message
ev.on('newOnAck', async (event) => {
    console.log('id Message: ', event.id._serialized); // message id
    console.log('Status Message: ', event.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.from); // from message
    console.log('To Message: ', event.to); // to message
});

})();`

You're up to date πŸŽ‰πŸŽ‰πŸŽ‰
info Browser: Starting browser...
info Browser: Error open browser...

I installed chrome in this ubuntu, other libraries works ok.

roy#: /usr/bin/google-chrome
[21214:21214:0716/060348.729112:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180

Send Location

Hi,
Is there any way to send location or maybe live location?

build fail in macbook pro m1

npm i --save hydra-bot

npm notice
npm notice New minor version of npm available! 8.11.0 -> 8.14.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.14.0
npm notice Run npm install -g [email protected] to update!
npm notice
npm ERR! code 1
npm ERR! path /Users/roysabah/www/msgto/server/node_modules/@open-wa/wa-automate/node_modules/sharp
npm ERR! command failed
npm ERR! command sh -c (node install/libvips && node install/dll-copy && prebuild-install --runtime=napi) || (node-gyp rebuild && node install/dll-copy)
npm ERR! CC(target) Release/obj.target/nothing/../node-addon-api/nothing.o
npm ERR! LIBTOOL-STATIC Release/nothing.a
npm ERR! TOUCH Release/obj.target/libvips-cpp.stamp
npm ERR! CXX(target) Release/obj.target/sharp/src/common.o
npm ERR! info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.9.1/libvips-8.9.1-darwin-arm64v8.tar.gz
npm ERR! ERR! sharp Prebuilt libvips 8.9.1 binaries are not yet available for darwin-arm64v8
npm ERR! info sharp Attempting to build from source via node-gyp but this may fail due to the above error
npm ERR! info sharp Please see https://sharp.pixelplumbing.com/install for required dependencies
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | darwin | arm64
npm ERR! gyp info find Python using Python version 3.8.9 found at "/Applications/Xcode.app/Contents/Developer/usr/bin/python3"
npm ERR! gyp info spawn /Applications/Xcode.app/Contents/Developer/usr/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args '/Users/roysabah/www/msgto/server/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args 'binding.gyp',
npm ERR! gyp info spawn args '-f',
npm ERR! gyp info spawn args 'make',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/Users/roysabah/www/msgto/server/node_modules/@open-wa/wa-automate/node_modules/sharp/build/config.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/Users/roysabah/www/msgto/server/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/Users/roysabah/Library/Caches/node-gyp/16.15.1/include/node/common.gypi',
npm ERR! gyp info spawn args '-Dlibrary=shared_library',
npm ERR! gyp info spawn args '-Dvisibility=default',
npm ERR! gyp info spawn args '-Dnode_root_dir=/Users/roysabah/Library/Caches/node-gyp/16.15.1',
npm ERR! gyp info spawn args '-Dnode_gyp_dir=/Users/roysabah/www/msgto/server/node_modules/node-gyp',
npm ERR! gyp info spawn args '-Dnode_lib_file=/Users/roysabah/Library/Caches/node-gyp/16.15.1/<(target_arch)/node.lib',
npm ERR! gyp info spawn args '-Dmodule_root_dir=/Users/roysabah/www/msgto/server/node_modules/@open-wa/wa-automate/node_modules/sharp',
npm ERR! gyp info spawn args '-Dnode_engine=v8',
npm ERR! gyp info spawn args '--depth=.',
npm ERR! gyp info spawn args '--no-parallel',
npm ERR! gyp info spawn args '--generator-output',
npm ERR! gyp info spawn args 'build',
npm ERR! gyp info spawn args '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: archive library: Release/nothing.a the table of contents is empty (no object file members in the library define global symbols)
npm ERR! ../src/common.cc:23:10: fatal error: 'vips/vips8' file not found
npm ERR! #include <vips/vips8>
npm ERR! ^~~~~~~~~~~~
npm ERR! 1 error generated.
npm ERR! make: *** [Release/obj.target/sharp/src/common.o] Error 1
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: make failed with exit code: 2
npm ERR! gyp ERR! stack at ChildProcess.onExit (/Users/roysabah/www/msgto/server/node_modules/node-gyp/lib/build.js:194:23)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:527:28)
npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
npm ERR! gyp ERR! System Darwin 21.3.0
npm ERR! gyp ERR! command "/usr/local/bin/node" "/Users/roysabah/www/msgto/server/node_modules/.bin/node-gyp" "rebuild"
npm ERR! gyp ERR! cwd /Users/roysabah/www/msgto/server/node_modules/@open-wa/wa-automate/node_modules/sharp
npm ERR! gyp ERR! node -v v16.15.1
npm ERR! gyp ERR! node-gyp -v v8.4.1
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/roysabah/.npm/_logs/2022-07-16T05_15_00_813Z-debug-0.log

Docker and Database

I'm having trouble saving the user I created when using docker. Docker will reset the data when I stop the container.
any solution to store the database outside docker?

Qr code take long time and sometimes it stack

Screen Shot 2022-07-16 at 8 41 58

`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({
    puppeteerOptions: {
        headless: process.platform === 'linux' ? true : false ,
        executablePath: process.platform === 'linux' ? "/usr/bin/google-chrome" : "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
        args: ['--no-sandbox'], // Additional arguments to pass to the browser instance. adding any parameter you will replace the default args of the project
    }
});

// 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;
        // send a text message
        await client.sendMessage({
            to: "[email protected]", // you can pass the contact number or group number
            body: "hi i'm hydra bot", // message text
            options: {
                type: 'text', // 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.isSentByMe) {
        // message received!
        console.log('NewMessageReceived: ', newMsg.result);
        // dowload files
        if (newMsg.result.isMedia === true || newMsg.result.isMMS === true) {
            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) => {
                console.log(err);
            });
        }
    }
    // when is it sent
    if (!!newMsg.result.isSentByMe) {
        // Message sent
        console.log('NewMessageSent: ', newMsg.result);
    }
});

// returns the status of each message
ev.on('newOnAck', async (event) => {
    console.log('id Message: ', event.id._serialized); // message id
    console.log('Status Message: ', event.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.from); // from message
    console.log('To Message: ', event.to); // to message
});

})();`
Screen Shot 2022-07-16 at 8 46 42

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.