Skip to content

Commit

Permalink
Merge branch 'release'
Browse files Browse the repository at this point in the history
  • Loading branch information
ghayman committed Sep 26, 2024
2 parents fc62cc3 + 17be91b commit 95c3054
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 53 deletions.
70 changes: 70 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* eslint-disable */
const venom = require('./dist/index');

try {
venom
.create({
session: 'sessionName_0001',
headless: false,
devtools: true,
})
.then((client) => start(client))
.catch(async (err) => {
console.log('Startup error: ' + err);
});
} catch (e) {
console.log(e);
}

async function start(client) {
console.log('We have started');
console.log(await client.getWAVersion());

const page = client.waPage;
const browser = page.browser();
const pid = browser.process().pid;

console.log(JSON.stringify(pid, null, 2));

console.log(await client.isLoggedIn());

let lastMessageId = "";

client.onAnyMessage((message) => {
if (lastMessageId === message.id) {
console.log('Duplicate message: ' + lastMessageId)
} else {
lastMessageId = message.id;
console.log(message);
console.log('New message: ' + message.id + ' ' + message.type);
}

if (message['isGroupMsg']) {
const ids = client
.getGroupMembers(message['chatId'], 1000)
.then((ids) => {
console.log(ids);
});
}
});

client.onMessageEdit((message) => {
console.log('EDIT!');
console.log(message);
});

client.onMessageDelete((message) => {
console.log('DELETE!');
console.log(message);
});

client.onMessageEdit((message) => {
console.log('EDIT!');
console.log(message);
});

client.onMessageReaction((reaction) => {
console.log('REACTION!');
console.log(reaction);
});
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"release": "release-it",
"start": "npm run build:venom & tsc app.ts && node app.js",
"test": "node ./test/index.js",
"test:app": "node ./app.js",
"watch": "concurrently \"tsc -w\" \"nodemon dist/index.js\""
},
"husky": {
Expand Down
2 changes: 1 addition & 1 deletion src/api/layers/group.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export class GroupLayer extends RetrieverLayer {
if (typeof validating === 'object') {
return reject(validating);
}
const result = this.page.evaluate(
const result = await this.page.evaluate(
(groupId: string, time: string) =>
WAPI.getGroupParticipant(groupId, time),
groupId,
Expand Down
99 changes: 47 additions & 52 deletions src/lib/wapi/functions/get-group-participant.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,55 @@ export async function getGroupParticipant(groupId, time = 1000) {
return WAPI.scope(undefined, true, null, 'Use to groupId string');
}

const chat = await WAPI.sendExist(groupId);
const moduleGroup = await window.Store.GroupMetadata._models.filter(
(e) => e.id._serialized === groupId
);

if (chat && chat.status != 404 && chat.id) {
const moduleGroup = await window.Store.GroupMetadata._models.filter(
(e) => e.id._serialized === groupId
);
const participants =
moduleGroup.length && moduleGroup[0].participants
? moduleGroup[0].participants
: undefined;

const participants =
moduleGroup.length && moduleGroup[0].participants
? moduleGroup[0].participants
: undefined;
if (participants) {
const output = participants.map((participant) => {
return {
id: participant.id,
displayName:
participant.contact && participant.contact.displayName
? participant.contact.displayName
: null,
mentionName:
participant.contact && participant.contact.mentionName
? participant.contact.mentionName
: null,
notifyName:
participant.contact && participant.contact.notifyName
? participant.contact.notifyName
: null,
isBusiness:
participant.contact && participant.contact.isBusiness
? participant.contact.isBusiness
: null,
pushname:
participant.contact && participant.contact.pushname
? participant.contact.pushname
: null,
isUser:
participant.contact && participant.contact.isUser
? participant.contact.isUser
: null,
isMyContact:
participant.contact && participant.contact.isMyContact
? participant.contact.isMyContact
: null,
isMe:
participant.contact && participant.contact.isMe
? participant.contact.isMe
: null
};
});

if (participants) {
const output = participants.map((participant) => {
return {
id: participant.id,
displayName:
participant.contact && participant.contact.displayName
? participant.contact.displayName
: null,
mentionName:
participant.contact && participant.contact.mentionName
? participant.contact.mentionName
: null,
notifyName:
participant.contact && participant.contact.notifyName
? participant.contact.notifyName
: null,
isBusiness:
participant.contact && participant.contact.isBusiness
? participant.contact.isBusiness
: null,
pushname:
participant.contact && participant.contact.pushname
? participant.contact.pushname
: null,
isUser:
participant.contact && participant.contact.isUser
? participant.contact.isUser
: null,
isMyContact:
participant.contact && participant.contact.isMyContact
? participant.contact.isMyContact
: null,
isMe:
participant.contact && participant.contact.isMe
? participant.contact.isMe
: null
};
});

return output;
}
return WAPI.scope(undefined, true, null, 'Error find Group');
return output;
}
return WAPI.scope(undefined, true, null, 'Group not found');
return WAPI.scope(undefined, true, null, 'Error find Group');
}

0 comments on commit 95c3054

Please sign in to comment.