-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/jonalan7/Hydra-bot
- Loading branch information
Showing
11 changed files
with
556 additions
and
560 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,17 @@ | ||
const hydraBot = require('../dist'); | ||
const mime = require('mime-types'); | ||
const fs = require('fs'); | ||
(async () => { | ||
|
||
// hydraBot.initWs({ | ||
// puppeteerOptions: { | ||
// headless: false, | ||
// } | ||
// }); | ||
|
||
|
||
let client; | ||
// start bot service | ||
const ev = await hydraBot.initServer({ | ||
session: 'geovane', | ||
puppeteerOptions: { | ||
headless: false, | ||
} | ||
// start Web Service | ||
const WS = await hydraBot.initWs({ | ||
port: '8001', | ||
authentication: true, // ask for authentication in routes | ||
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 | ||
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 parameters it will open the installed browser. | ||
}, | ||
}); | ||
|
||
// 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); | ||
} | ||
|
||
// if (conn.statusFind === 'page') { | ||
// conn.page | ||
// } | ||
|
||
// Was connected to whatsapp chat | ||
if (conn.connect) { | ||
// send a text message | ||
client = conn.client; | ||
// await client.sendMessage({ | ||
// to: "0000000000@c.us", | ||
// body: "Oi eu sou um bot", | ||
// options: { | ||
// type: 'text', | ||
// } | ||
// }).then((result) => { | ||
// console.log(result); | ||
// }).catch((error) => { | ||
// console.log(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)}`; | ||
await fs.writeFile(fileName, buffer, (err) => { | ||
console.log(err); | ||
}); | ||
} | ||
} | ||
// when is it sent | ||
if (!!newMsg.result.isSentByMe) { | ||
// Message sent | ||
//console.log('NewMessageSent: ', newMsg.result); | ||
} | ||
}); | ||
|
||
})(); | ||
})(); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters