-
-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support new multidevice authentication
Merge pull request #63 from tuhinpal/newauthdev
- Loading branch information
Showing
15 changed files
with
232 additions
and
172 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
SESSION = '' | ||
SESSION_KEY="tuhin" | ||
PMPERMIT_ENABLED = 'true' | ||
MONGODB_URL = '' | ||
DEFAULT_TR_LANG = 'en' | ||
|
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
Binary file not shown.
This file was deleted.
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,38 +1,45 @@ | ||
const { Client, LegacySessionAuth } = require("whatsapp-web.js"); | ||
const { Client, LocalAuth } = require("whatsapp-web.js"); | ||
const qrcode = require("qrcode-terminal"); | ||
const logger = require("../logger"); | ||
const { write, clean } = require("./manage"); | ||
const readline = require("readline"); | ||
|
||
clean(); | ||
|
||
const client = new Client({ | ||
puppeteer: { headless: true, args: ["--no-sandbox"] }, | ||
authStrategy: new LegacySessionAuth(), | ||
}); | ||
client.initialize(); | ||
|
||
client.on("qr", (qr) => { | ||
console.log(`Scan this QR Code and copy the JSON\n`); | ||
qrcode.generate(qr, { small: true }); | ||
authStrategy: new LocalAuth({ clientId: "whatsbot" }), | ||
}); | ||
|
||
var token = ""; | ||
let password = null; | ||
|
||
client.on("authenticated", (session) => { | ||
token = session; | ||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
}); | ||
|
||
client.on("ready", async () => { | ||
// console.log(JSON.stringify(token)); | ||
rl.question( | ||
"Enter password to encrypt session (You need to put this in ENV): ", | ||
(answer) => { | ||
password = answer; | ||
console.log("Password set to:", password); | ||
console.log("Generating QR Code..."); | ||
rl.close(); | ||
client.initialize(); | ||
} | ||
); | ||
|
||
await logger( | ||
client, | ||
`Here is your session token. Please keep is as a secret. You can delete the file if you don't need it.\n\n*Generated at:* ${new Date()}` | ||
); | ||
await logger(client, JSON.stringify(token)); | ||
|
||
console.log( | ||
"\n\nPlease open your Whatsapp and see your chat. Your session token will be saved there." | ||
); | ||
client.on("qr", (qr) => { | ||
console.log(`Scan this QR Code and copy the JSON\n`); | ||
qrcode.generate(qr, { small: true }); | ||
}); | ||
|
||
setTimeout(() => { | ||
client.on("ready", () => { | ||
client.destroy(); | ||
console.log("Please wait..."); | ||
// wait because filesystem is busy | ||
setTimeout(async () => { | ||
console.log("Session has been created"); | ||
await write(password); | ||
process.exit(); | ||
}, 5000); | ||
}, 3000); | ||
}); |
This file was deleted.
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const { Client, LocalAuth } = require("whatsapp-web.js"); | ||
const qrcode = require("qrcode-terminal"); | ||
const { write, clean } = require("./manage"); | ||
const readline = require("readline"); | ||
const app = require("express")(); | ||
|
||
clean(); | ||
|
||
const client = new Client({ | ||
puppeteer: { headless: true, args: ["--no-sandbox"] }, | ||
authStrategy: new LocalAuth({ clientId: "whatsbot" }), | ||
}); | ||
|
||
let password = null; | ||
|
||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
}); | ||
|
||
rl.question( | ||
"Enter password to encrypt session (You need to put this in ENV): ", | ||
(answer) => { | ||
password = answer; | ||
console.log("Password set to:", password); | ||
console.log("Generating QR Code..."); | ||
rl.close(); | ||
client.initialize(); | ||
} | ||
); | ||
|
||
client.on("qr", (qr) => { | ||
console.log(`Scan this QR Code and copy the JSON\n`); | ||
qrcode.generate(qr, { small: true }); | ||
}); | ||
|
||
client.on("ready", () => { | ||
client.destroy(); | ||
console.log("Please wait..."); | ||
// wait because filesystem is busy | ||
setTimeout(async () => { | ||
console.log("Session has been created"); | ||
await write(password); | ||
app.listen(8080, () => { | ||
console.log( | ||
"Go to http://{app_url}/session.secure to download the session" | ||
); | ||
}); | ||
}, 3000); | ||
}); | ||
|
||
app.get("/session.secure", (req, res) => { | ||
res.download("./session.secure"); | ||
}); |
Oops, something went wrong.