https://github.com/globaltechinfo/web-pair-qr
Session Id Generator For Whatsapp Bots Using Mega
https://github.com/globaltechinfo/web-pair-qr
baileys baileys-bot baileys-md bot express-pairing express-session pair pair-code pairing qr-code qrcode qrcode-generator qrcode-scanner session whatsapp whatsapp-api whatsapp-automation whatsapp-bot whatsapp-web whatsappbot
Last synced: about 2 months ago
JSON representation
Session Id Generator For Whatsapp Bots Using Mega
- Host: GitHub
- URL: https://github.com/globaltechinfo/web-pair-qr
- Owner: GlobalTechInfo
- Created: 2024-11-23T16:45:23.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-06-09T17:15:32.000Z (4 months ago)
- Last Synced: 2025-06-09T18:24:51.227Z (4 months ago)
- Topics: baileys, baileys-bot, baileys-md, bot, express-pairing, express-session, pair, pair-code, pairing, qr-code, qrcode, qrcode-generator, qrcode-scanner, session, whatsapp, whatsapp-api, whatsapp-automation, whatsapp-bot, whatsapp-web, whatsappbot
- Language: JavaScript
- Homepage:
- Size: 179 KB
- Stars: 6
- Watchers: 1
- Forks: 72
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Session Id Generator For WhatsApp Bots Using Mega
**It Will Uploads Your Creds To Mega And Will Sends You Id Of That File.**
**How Session Id Will Works?**
Click Here To View?
```js
import { fileURLToPath } from 'url';import path from 'path';
import { writeFileSync } from 'fs';
import * as mega from 'megajs';
// This imports everything from the `megajs` module (which is a JavaScript library to interact with Mega.nz) as an object `mega`.
// This module allows interacting with files stored on the Mega cloud storage.async function SaveCreds(txt) {
// Declares an asynchronous function named `SaveCreds` that takes `txt` as an argument. The function will save credentials ( in JSON format) to a local file.const __filename = fileURLToPath(import.meta.url);
// `import.meta.url` gives the URL of the current module. The `fileURLToPath` function converts that URL to a file path for the current file.const __dirname = path.dirname(__filename);
// `path.dirname` extracts the directory name from the `__filename` path, so it provides the path to the directory containing the current file.const megaCode = txt.replace('', '');
//if you did used some prefix before the session idconst megaUrl = `https://mega.nz/file/${megaCode}`;
// Creates a Mega URL using the `file id` . It constructs the full URL to access the file stored on Mega.console.log(megaUrl);
// Logs the generated Mega URL to the console for debugging or confirmation purposes.const file = mega.File.fromURL(megaUrl);
// Uses the `mega.File.fromURL` method from `megajs` to create a `file` object from the Mega URL. This object represents the file to be downloaded.try {
const stream = file.download();
// Downloads the file from Mega as a stream. This returns a readable stream of the file's data.let data = '';
// Initializes an empty string `data` to accumulate the chunks of data downloaded from the stream.for await (const chunk of stream) {
// Iterates over each chunk in the stream asynchronously (i.e., handles the data as it is downloaded).
data += chunk.toString();
// Converts each chunk (which may be a Buffer) to a string and appends it to the `data` variable.
}const credsPath = path.join(__dirname, '..', 'session', 'creds.json');
// Joins several path segments to form the path to save the credentials file (it goes up one directory level and then to `session/creds.json`).writeFileSync(credsPath, data);
// Writes the `data` (credentials) to the `creds.json` file synchronously at the specified `credsPath`.console.log('Saved credentials to', credsPath);
// Logs a message to the console indicating that the credentials were successfully saved to the specified path.} catch (error) {
// If an error occurs during the download or file writing process, this block catches it.console.error('Error downloading or saving credentials:', error);
// Logs the error message to the console, providing feedback if something goes wrong.
}
}export default SaveCreds;
// Exports the `SaveCreds` function as the default export of this module, making it available for use in main file.//Now Import Function In Main File
dotenv.config()
import SaveCreds from './some-file.js'async function main() {
const txt = process.env.SESSION_IDif (!txt) {
console.error('Environment variable not found.')
return
}try {
await SaveCreds(txt)
console.log('process SaveCreds completed.')
} catch (error) {
console.error('Error:', error)
}
}main()
// Now Use Further code
```CRAFTED USING TEMPLATES OF SUHAILTECHINFO ( QR ) AND PRABATH ( PAIR )
BOTH PAIR CODE AND QR CODE WORKING
YOU CAN DEPLOY IT ON ANY CLOUD PLATFORM e.g `HEROKU` `RENDER` `KOYEB` etc.
**⭐ THE REPO IF YOU ARE GOING TO COPY OR FORK**
Note: Make Sure Add Your Email And Password ( Required In mega.js ) Before Running/Deploying The API.
## OTHER PROJECTS:
- [PASTE SESSION](https://github.com/GlobalTechInfo/PAIRING-WEB)
- [WHATSAPP BOT](https://github.com/GlobalTechInfo/MEGA-AI)
- [TELEGRAM BOT](https://github.com/GlobalTechInfo/TELEGRAM-AI#readme)| [](https://github.com/GlobalTechInfo) |
| --- |
| [Qasim Ali](https://github.com/GlobalTechInfo) |