Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/typescript-eslint/…
Browse files Browse the repository at this point in the history
…eslint-plugin-4.18.0
  • Loading branch information
jonalan7 committed Mar 20, 2021
2 parents 53d9b94 + e37f264 commit d1839ac
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 68 deletions.
13 changes: 12 additions & 1 deletion README.md
Expand Up @@ -157,6 +157,11 @@ venom
'{"key":"+i/nRgWJ....","encKey":"kGdMR5t....","macKey":"+i/nRgW...."}',
WAToken1: '"0i8...."',
WAToken2: '"1@lPpzwC...."',
},
// BrowserInstance
(browser, waPage) => {
console.log("Browser PID:", browser.process().pid);
waPage.screenshot({path: 'screenshot.png'});
}
)
.then((client) => {
Expand Down Expand Up @@ -776,7 +781,13 @@ await client.clearChatMessages('000000000000@c.us');
await client.archiveChat(chatId, true);

// Delete message (last parameter: delete only locally)
await client.deleteMessage('000000000000@c.us', message.id.toString(), false);
await client.deleteMessage('000000000000@c.us', ['false_000000000000@c.us_B70847EE89E22D20FB86ECA0C1B11609','false_000000000000@c.us_B70847EE89E22D20FB86ECA0C1B11777'],)
.then((result) => {
console.log('Result: ', result); //return object success
})
.catch((erro) => {
console.error('Error when sending: ', erro); //return object error
});

// Mark chat as not seen (returns true if it works)
await client.markUnseenMessage('000000000000@c.us');
Expand Down
5 changes: 5 additions & 0 deletions examples/screenshot/.gitignore
@@ -0,0 +1,5 @@
node_modules
tokens
package-lock.json
debug.log
*screenshot.png
3 changes: 3 additions & 0 deletions examples/screenshot/README.md
@@ -0,0 +1,3 @@
# Screenshot

Get screenshot to see what happen behind the hood.
25 changes: 25 additions & 0 deletions examples/screenshot/index.js
@@ -0,0 +1,25 @@
const venom = require('../../dist');

venom
.create(
'sessionName', //session
null, //catchQR
null, //statusFind
null, //options
null, //BrowserSessionToken
(browser, waPage) => {
// Show broser process ID
console.log('Browser PID:', browser.process().pid);
// Take screenshot before logged-in
waPage.screenshot({ path: 'before-screenshot.png' });
}
)
.then((client) => start(client))
.catch((erro) => {
console.log(erro);
});

function start(client) {
// Taks screenshot after logged-in
client.waPage.screenshot({ path: 'after-screenshot.png' });
}
11 changes: 11 additions & 0 deletions examples/screenshot/package.json
@@ -0,0 +1,11 @@
{
"name": "venom-bot-functions",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "ISC"
}
34 changes: 26 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 40 additions & 8 deletions src/api/layers/controls.layer.ts
Expand Up @@ -55,6 +55,9 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
import { Page } from 'puppeteer';
import { CreateConfig } from '../../config/create-config';
import { UILayer } from './ui.layer';
import { Scope, checkValuesSender } from '../helpers/layers-interface';

let obj: Scope;

export class ControlsLayer extends UILayer {
constructor(public page: Page, session?: string, options?: CreateConfig) {
Expand Down Expand Up @@ -165,14 +168,43 @@ export class ControlsLayer extends UILayer {
*/
public async deleteMessage(
chatId: string,
messageId: string[] | string,
onlyLocal = false
) {
return await this.page.evaluate(
({ contactId, messageId, onlyLocal }) =>
WAPI.deleteMessages(contactId, messageId, onlyLocal),
{ contactId: chatId, messageId, onlyLocal }
);
messageId: string[]
): Promise<Object> {
return new Promise(async (resolve, reject) => {
const typeFunction = 'deleteMessage';
const type = 'string';
const check = [
{
param: 'chatId',
type: type,
value: chatId,
function: typeFunction,
isUser: true,
},
{
param: 'messageId',
type: 'object',
value: messageId,
function: typeFunction,
isUser: true,
},
];

const validating = checkValuesSender(check);
if (typeof validating === 'object') {
return reject(validating);
}
const result = await this.page.evaluate(
({ chatId, messageId }) => WAPI.deleteMessages(chatId, messageId),
{ chatId, messageId }
);

if (result['erro'] == true) {
return reject(result);
} else {
return resolve(result);
}
});
}

/**
Expand Down
7 changes: 1 addition & 6 deletions src/api/layers/sender.layer.ts
Expand Up @@ -63,12 +63,7 @@ import {
stickerSelect,
} from '../helpers';
import { filenameFromMimeType } from '../helpers/filename-from-mimetype';
import {
Message,
SendFileResult,
SendLinkResult,
SendStickerResult,
} from '../model';
import { Message, SendFileResult, SendStickerResult } from '../model';
import { ChatState } from '../model/enum';
import { ListenerLayer } from './listener.layer';
import { Scope, checkValuesSender } from '../helpers/layers-interface';
Expand Down
20 changes: 18 additions & 2 deletions src/controllers/initializer.ts
Expand Up @@ -62,6 +62,7 @@ import { getSpinnies } from '../utils/spinnies';
import { SocketState } from '../api/model/enum';
import { deleteFiles, checkingCloses } from '../api/helpers';
import { tokenSession } from '../config/tokenSession.config';
import { Browser, Page } from 'puppeteer';

/**
* A callback will be received, informing the status of the qrcode
Expand All @@ -78,6 +79,14 @@ export type CatchQR = (
*/
export type StatusFind = (statusGet: string, session: string) => void;

/**
* A callback will be received, informing user about browser and page instance
*/
export type BrowserInstance = (
browser: string | Browser,
waPage: false | Page
) => void;

export interface CreateOptions extends CreateConfig {
/**
* You must pass a string type parameter, this parameter will be the name of the client's session. If the parameter is not passed, the section name will be "session".
Expand All @@ -95,6 +104,10 @@ export interface CreateOptions extends CreateConfig {
* Pass the session token information you can receive this token with the await client.getSessionTokenBrowser () function
*/
browserSessionToken?: tokenSession;
/**
* A callback will be received, informing user about browser and page instance
*/
browserInstance?: BrowserInstance;
}

/**
Expand All @@ -112,15 +125,17 @@ export async function create(
catchQR?: CatchQR,
statusFind?: StatusFind,
options?: CreateConfig,
browserSessionToken?: tokenSession
browserSessionToken?: tokenSession,
browserInstance?: BrowserInstance
): Promise<Whatsapp>;

export async function create(
sessionOrOption: string | CreateOptions,
catchQR?: CatchQR,
statusFind?: StatusFind,
options?: CreateConfig,
browserSessionToken?: tokenSession
browserSessionToken?: tokenSession,
browserInstance?: BrowserInstance
): Promise<Whatsapp> {
let session = 'session';

Expand All @@ -135,6 +150,7 @@ export async function create(
statusFind = sessionOrOption.statusFind || statusFind;
browserSessionToken =
sessionOrOption.browserSessionToken || browserSessionToken;
browserInstance = sessionOrOption.browserInstance || browserInstance;
options = sessionOrOption;
}
let browserToken: any;
Expand Down

0 comments on commit d1839ac

Please sign in to comment.