forked from orkestral/venom
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
369 additions
and
67 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { options, defaultOptions } from './options'; |
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,108 @@ | ||
import { LaunchOptions } from 'puppeteer'; | ||
import { puppeteerConfig } from './puppeteer.config'; | ||
|
||
// Server config | ||
export interface options { | ||
/** | ||
* logs info updates automatically in terminal | ||
* @default true | ||
*/ | ||
updatesLog?: boolean; | ||
/** | ||
* name of the token to be generated, a folder with all customer information will be created | ||
* @default 'session' | ||
*/ | ||
session?: string; | ||
/** folder name when saving tokens | ||
* @default 'tokens' | ||
*/ | ||
folderNameToken?: string; | ||
/** | ||
* folder directory tokens, just inside the venom folder, example: { mkdirFolderToken: '/node_modules', } //will save the tokens folder in the node_modules directory | ||
* @default 'null' | ||
*/ | ||
mkdirFolderToken?: string; | ||
/** | ||
* Headless chrome | ||
* @default true | ||
*/ | ||
headless?: boolean | 'new'; | ||
/** | ||
* If you want to use browserWSEndpoint | ||
*/ | ||
browserWS?: string; | ||
/** | ||
* Parameters to be added into the chrome browser instance | ||
*/ | ||
browserArgs?: string[]; | ||
/** | ||
* Add broserArgs without overwriting the project's original | ||
*/ | ||
addBrowserArgs?: string[]; | ||
/** | ||
* Will be passed to puppeteer.launch | ||
*/ | ||
puppeteerOptions?: LaunchOptions; | ||
/** | ||
* Logs QR automatically in terminal | ||
* @default true | ||
*/ | ||
logQR?: boolean; | ||
/** | ||
* Will disable the welcoming message which appears in the beginning | ||
* @default false | ||
*/ | ||
disableWelcome?: boolean; | ||
/** | ||
* Automatically closes the venom-bot only when scanning the QR code (default 60000 miliseconds, if you want to turn it off, assign 0 or false) | ||
* @default 60000 | ||
*/ | ||
autoClose?: number; | ||
/** | ||
* Creates a folder when inserting an object in the client's browser, to work it is necessary to pass the parameters in the function create browserSessionToken | ||
* @default true | ||
*/ | ||
createPathFileToken?: boolean; | ||
/** | ||
* automatically download Chromium browser | ||
* @default true | ||
*/ | ||
BrowserFetcher?: boolean; | ||
/** | ||
* Add proxy server | ||
* @default null | ||
*/ | ||
addProxy?: string[]; | ||
/** | ||
* Proxy username | ||
* @default null | ||
*/ | ||
userProxy?: string; | ||
/** | ||
* Proxy password | ||
* @default null | ||
*/ | ||
userPass?: string; | ||
/** | ||
* Open devtools by default | ||
* @default false | ||
*/ | ||
devtools?: boolean; | ||
} | ||
|
||
export const defaultOptions: options = { | ||
session: 'name-session', | ||
folderNameToken: 'tokens', | ||
disableWelcome: false, | ||
BrowserFetcher: true, | ||
updatesLog: true, | ||
headless: true, | ||
logQR: true, | ||
devtools: false, | ||
mkdirFolderToken: '', | ||
browserWS: '', | ||
browserArgs: puppeteerConfig.chromiumArgs, | ||
addBrowserArgs: [], | ||
autoClose: 120000, | ||
addProxy: [] | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Browser, Page } from 'puppeteer'; | ||
import { checkUpdates } from './check-up-to-date'; | ||
import { options, defaultOptions } from '../config'; | ||
import { initWhatsapp, initBrowser, statusLog } from './browser'; | ||
|
||
export async function connect(options?: options); | ||
|
||
export async function connect(options?: options) { | ||
const mergeOptionsDefault = { ...defaultOptions, ...options }; | ||
|
||
if (!!mergeOptionsDefault.session && mergeOptionsDefault.session.length) { | ||
const sessionName = mergeOptionsDefault.session; | ||
const replaceSession = sessionName.replace(/[^0-9a-zA-Zs]/g, ''); | ||
if (replaceSession.length) { | ||
mergeOptionsDefault.session = replaceSession; | ||
} else { | ||
mergeOptionsDefault.session = defaultOptions.session; | ||
} | ||
} | ||
|
||
if (mergeOptionsDefault.updatesLog) { | ||
await checkUpdates(); | ||
} | ||
|
||
const wpage: Browser | boolean = await initBrowser(mergeOptionsDefault); | ||
if (typeof wpage !== 'boolean') { | ||
const page: boolean | Page = await initWhatsapp(mergeOptionsDefault, wpage); | ||
if (typeof page !== 'boolean') { | ||
console.log('New option'); | ||
} | ||
} | ||
} |
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