zalo-toolkit 1.0.8 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,6 @@ import { ZaloApiError } from "../Errors/ZaloApiError.js";
2
2
  import { apiFactory } from "../utils.js";
3
3
  export const getAliasListFactory = apiFactory()((api, ctx, utils) => {
4
4
  return async function getListAlias(page = 1, limit = 200) {
5
- console.log('getListAlias', page, ctx.uid);
6
5
  try {
7
6
  const params = {
8
7
  page,
@@ -1,6 +1,6 @@
1
1
  import { ZaloApiError } from '../Errors/ZaloApiError.js';
2
2
  import { apiFactory } from '../utils.js';
3
- export const getGroupMembersInfoFactory = apiFactory()((api, _, utils) => {
3
+ export const getGroupMembersInfoFactory = apiFactory()((api, ctx, utils) => {
4
4
  const serviceURL = utils.makeURL(`${api.zpwServiceMap.profile[0]}/api/social/group/members`);
5
5
  /**
6
6
  * Get group information
@@ -10,15 +10,32 @@ export const getGroupMembersInfoFactory = apiFactory()((api, _, utils) => {
10
10
  * @throws {ZaloApiError}
11
11
  */
12
12
  return async function getGroupMembersInfo(memberId) {
13
- if (!Array.isArray(memberId))
14
- memberId = [memberId];
13
+ if (!memberId)
14
+ throw new ZaloApiError('Missing user id');
15
+ const friend_pversion_map = [];
16
+ if (Array.isArray(memberId)) {
17
+ memberId.forEach((item) => {
18
+ friend_pversion_map.push(`${item}_0`);
19
+ });
20
+ }
21
+ else {
22
+ friend_pversion_map.push(`${memberId}_0`);
23
+ }
15
24
  const params = {
16
- friend_pversion_map: memberId.map((id) => (id.endsWith('_0') ? id : `${id}_0`)),
25
+ friend_pversion_map: friend_pversion_map,
26
+ avatar_size: 240,
27
+ language: ctx.language,
28
+ imei: ctx.imei,
17
29
  };
18
30
  const encryptedParams = utils.encodeAES(JSON.stringify(params));
19
31
  if (!encryptedParams)
20
32
  throw new ZaloApiError('Failed to encrypt message');
21
- const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }));
33
+ const response = await utils.request(serviceURL, {
34
+ method: 'POST',
35
+ body: new URLSearchParams({
36
+ params: encryptedParams,
37
+ }),
38
+ });
22
39
  return utils.resolve(response);
23
40
  };
24
41
  });
@@ -8,7 +8,7 @@ import { Reaction } from '../models/Reaction.js';
8
8
  import { GroupSeenMessage, UserSeenMessage } from '../models/SeenMessage.js';
9
9
  import { GroupTyping, UserTyping } from '../models/Typing.js';
10
10
  import { Undo } from '../models/Undo.js';
11
- import { decodeEventData, FibonacciRetry, getFriendEventType, getGroupEventType, logger, looksLikeJson, makeURL } from '../utils.js';
11
+ import { decodeEventData, FibonacciRetry, getFriendEventType, getGroupEventType, hasOwn, logger, looksLikeJson, makeURL } from '../utils.js';
12
12
  import { ConfigSocket } from '../socket/config-socket.js';
13
13
  import { ZaloApiError } from '../Errors/ZaloApiError.js';
14
14
  import WebSocket from 'ws';
@@ -169,7 +169,7 @@ export class Listener extends EventEmitter {
169
169
  this.emit(SocketEvent.ON_PING_ACTIVE_KEEP_ALIVE, parsed);
170
170
  }
171
171
  }
172
- if (version == 1 && cmd == 1 && subCmd == 1 && parsed.hasOwnProperty('key')) {
172
+ if (version == 1 && cmd == 1 && subCmd == 1 && hasOwn(parsed, 'key')) {
173
173
  this.cipherKey = parsed.key;
174
174
  this.emit('cipher_key', parsed.key);
175
175
  this.clearPingTimer();
@@ -186,7 +186,7 @@ export class Listener extends EventEmitter {
186
186
  const listUndo = [];
187
187
  const listMessages = [];
188
188
  for (const msg of msgs) {
189
- if (typeof msg.content == 'object' && msg.content.hasOwnProperty('deleteMsg')) {
189
+ if (typeof msg.content == 'object' && hasOwn(msg.content, 'deleteMsg')) {
190
190
  const undoObject = new Undo(this.ctx.uid, msg, false);
191
191
  if (undoObject.isSelf && !this.selfListen)
192
192
  continue;
@@ -213,7 +213,7 @@ export class Listener extends EventEmitter {
213
213
  const listUndo = [];
214
214
  const listMessages = [];
215
215
  for (const msg of groupMsgs) {
216
- if (typeof msg.content == 'object' && msg.content.hasOwnProperty('deleteMsg')) {
216
+ if (typeof msg.content == 'object' && hasOwn(msg.content, 'deleteMsg')) {
217
217
  const undoObject = new Undo(this.ctx.uid, msg, true);
218
218
  if (undoObject.isSelf && !this.selfListen)
219
219
  continue;
@@ -337,7 +337,7 @@ export class Listener extends EventEmitter {
337
337
  const responseUndos = [];
338
338
  const responseMsgs = [];
339
339
  msgs.forEach((msg) => {
340
- if (typeof msg.content == 'object' && msg.content.hasOwnProperty('deleteMsg')) {
340
+ if (typeof msg.content == 'object' && hasOwn(msg.content, 'deleteMsg')) {
341
341
  const undoObject = new Undo(this.ctx.uid, msg, false);
342
342
  responseUndos.push(undoObject);
343
343
  }
@@ -359,7 +359,7 @@ export class Listener extends EventEmitter {
359
359
  const responseUndos = [];
360
360
  const responseMsgs = [];
361
361
  for (const msg of groupMsgs) {
362
- if (typeof msg.content == 'object' && msg.content.hasOwnProperty('deleteMsg')) {
362
+ if (typeof msg.content == 'object' && hasOwn(msg.content, 'deleteMsg')) {
363
363
  const undoObject = new Undo(this.ctx.uid, msg, true);
364
364
  responseUndos.push(undoObject);
365
365
  }
@@ -443,6 +443,7 @@ export class Listener extends EventEmitter {
443
443
  }
444
444
  }
445
445
  catch (error) {
446
+ console.log(error);
446
447
  this.onErrorCallback(error);
447
448
  }
448
449
  };
@@ -267,7 +267,6 @@ export async function handleWaitingConfirm(ctx, version, code) {
267
267
  throw new ZaloApiError('Không thể lấy thông tin tài khoản');
268
268
  if (!userInfo.data.logged)
269
269
  throw new ZaloApiError('Không thể đăng nhập');
270
- console.log('test', ctx.cookie.toJSON().cookies);
271
270
  return {
272
271
  cookies: ctx.cookie.toJSON().cookies,
273
272
  userInfo: userInfo.data.info,
@@ -5,7 +5,6 @@ var utils = require('../utils.cjs');
5
5
 
6
6
  const getAliasListFactory = utils.apiFactory()((api, ctx, utils) => {
7
7
  return async function getListAlias(page = 1, limit = 200) {
8
- console.log('getListAlias', page, ctx.uid);
9
8
  try {
10
9
  const params = {
11
10
  page,
@@ -3,7 +3,7 @@
3
3
  var ZaloApiError = require('../Errors/ZaloApiError.cjs');
4
4
  var utils = require('../utils.cjs');
5
5
 
6
- const getGroupMembersInfoFactory = utils.apiFactory()((api, _, utils) => {
6
+ const getGroupMembersInfoFactory = utils.apiFactory()((api, ctx, utils) => {
7
7
  const serviceURL = utils.makeURL(`${api.zpwServiceMap.profile[0]}/api/social/group/members`);
8
8
  /**
9
9
  * Get group information
@@ -13,15 +13,32 @@ const getGroupMembersInfoFactory = utils.apiFactory()((api, _, utils) => {
13
13
  * @throws {ZaloApiError}
14
14
  */
15
15
  return async function getGroupMembersInfo(memberId) {
16
- if (!Array.isArray(memberId))
17
- memberId = [memberId];
16
+ if (!memberId)
17
+ throw new ZaloApiError.ZaloApiError('Missing user id');
18
+ const friend_pversion_map = [];
19
+ if (Array.isArray(memberId)) {
20
+ memberId.forEach((item) => {
21
+ friend_pversion_map.push(`${item}_0`);
22
+ });
23
+ }
24
+ else {
25
+ friend_pversion_map.push(`${memberId}_0`);
26
+ }
18
27
  const params = {
19
- friend_pversion_map: memberId.map((id) => (id.endsWith('_0') ? id : `${id}_0`)),
28
+ friend_pversion_map: friend_pversion_map,
29
+ avatar_size: 240,
30
+ language: ctx.language,
31
+ imei: ctx.imei,
20
32
  };
21
33
  const encryptedParams = utils.encodeAES(JSON.stringify(params));
22
34
  if (!encryptedParams)
23
35
  throw new ZaloApiError.ZaloApiError('Failed to encrypt message');
24
- const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }));
36
+ const response = await utils.request(serviceURL, {
37
+ method: 'POST',
38
+ body: new URLSearchParams({
39
+ params: encryptedParams,
40
+ }),
41
+ });
25
42
  return utils.resolve(response);
26
43
  };
27
44
  });
@@ -172,7 +172,7 @@ class Listener extends stream.EventEmitter {
172
172
  this.emit(Listen.SocketEvent.ON_PING_ACTIVE_KEEP_ALIVE, parsed);
173
173
  }
174
174
  }
175
- if (version == 1 && cmd == 1 && subCmd == 1 && parsed.hasOwnProperty('key')) {
175
+ if (version == 1 && cmd == 1 && subCmd == 1 && utils.hasOwn(parsed, 'key')) {
176
176
  this.cipherKey = parsed.key;
177
177
  this.emit('cipher_key', parsed.key);
178
178
  this.clearPingTimer();
@@ -189,7 +189,7 @@ class Listener extends stream.EventEmitter {
189
189
  const listUndo = [];
190
190
  const listMessages = [];
191
191
  for (const msg of msgs) {
192
- if (typeof msg.content == 'object' && msg.content.hasOwnProperty('deleteMsg')) {
192
+ if (typeof msg.content == 'object' && utils.hasOwn(msg.content, 'deleteMsg')) {
193
193
  const undoObject = new Undo.Undo(this.ctx.uid, msg, false);
194
194
  if (undoObject.isSelf && !this.selfListen)
195
195
  continue;
@@ -216,7 +216,7 @@ class Listener extends stream.EventEmitter {
216
216
  const listUndo = [];
217
217
  const listMessages = [];
218
218
  for (const msg of groupMsgs) {
219
- if (typeof msg.content == 'object' && msg.content.hasOwnProperty('deleteMsg')) {
219
+ if (typeof msg.content == 'object' && utils.hasOwn(msg.content, 'deleteMsg')) {
220
220
  const undoObject = new Undo.Undo(this.ctx.uid, msg, true);
221
221
  if (undoObject.isSelf && !this.selfListen)
222
222
  continue;
@@ -340,7 +340,7 @@ class Listener extends stream.EventEmitter {
340
340
  const responseUndos = [];
341
341
  const responseMsgs = [];
342
342
  msgs.forEach((msg) => {
343
- if (typeof msg.content == 'object' && msg.content.hasOwnProperty('deleteMsg')) {
343
+ if (typeof msg.content == 'object' && utils.hasOwn(msg.content, 'deleteMsg')) {
344
344
  const undoObject = new Undo.Undo(this.ctx.uid, msg, false);
345
345
  responseUndos.push(undoObject);
346
346
  }
@@ -362,7 +362,7 @@ class Listener extends stream.EventEmitter {
362
362
  const responseUndos = [];
363
363
  const responseMsgs = [];
364
364
  for (const msg of groupMsgs) {
365
- if (typeof msg.content == 'object' && msg.content.hasOwnProperty('deleteMsg')) {
365
+ if (typeof msg.content == 'object' && utils.hasOwn(msg.content, 'deleteMsg')) {
366
366
  const undoObject = new Undo.Undo(this.ctx.uid, msg, true);
367
367
  responseUndos.push(undoObject);
368
368
  }
@@ -446,6 +446,7 @@ class Listener extends stream.EventEmitter {
446
446
  }
447
447
  }
448
448
  catch (error) {
449
+ console.log(error);
449
450
  this.onErrorCallback(error);
450
451
  }
451
452
  };
@@ -270,7 +270,6 @@ async function handleWaitingConfirm(ctx, version, code) {
270
270
  throw new ZaloApiError.ZaloApiError('Không thể lấy thông tin tài khoản');
271
271
  if (!userInfo.data.logged)
272
272
  throw new ZaloApiError.ZaloApiError('Không thể đăng nhập');
273
- console.log('test', ctx.cookie.toJSON().cookies);
274
273
  return {
275
274
  cookies: ctx.cookie.toJSON().cookies,
276
275
  userInfo: userInfo.data.info,
@@ -2,6 +2,7 @@
2
2
 
3
3
  var Listen = require('../models/Listen.cjs');
4
4
  var WebSocket = require('ws');
5
+ var utils = require('../utils.cjs');
5
6
 
6
7
  class ConfigSocket {
7
8
  constructor(ws, features, ctx, listen) {
@@ -17,7 +18,7 @@ class ConfigSocket {
17
18
  }
18
19
  getLastActionIdsForSocket(socketKey) {
19
20
  const defaultResult = { lastId: 1, preIds: [] };
20
- if (this.pollId.hasOwnProperty(socketKey)) {
21
+ if (utils.hasOwn(this.pollId, socketKey)) {
21
22
  const { lastId } = this.pollId[socketKey];
22
23
  const preIds = this.pollId[socketKey].control.getLastActionIdsArray(lastId).slice(0, 10);
23
24
  return { lastId, preIds };
package/dist/cjs/zalo.cjs CHANGED
@@ -116,9 +116,7 @@ class Zalo {
116
116
  }
117
117
  async waitingConfirm(props) {
118
118
  const { ctx, loginVersion, code, imei, getPreviousImei } = props;
119
- console.log(props);
120
119
  const loginQRResult = await loginQR.handleWaitingConfirm(ctx, loginVersion, code);
121
- console.log(loginQRResult);
122
120
  if (!loginQRResult || !(ctx === null || ctx === void 0 ? void 0 : ctx.userAgent))
123
121
  return null;
124
122
  return this.loginCookie({
@@ -1,5 +1,6 @@
1
1
  import { EventTypes, MAX_CHUNK_WS, MessageCommand, MessageTypes, SignalCommands } from '../models/Listen.js';
2
2
  import { WebSocket } from 'ws';
3
+ import { hasOwn } from '../utils.js';
3
4
  export class ConfigSocket {
4
5
  constructor(ws, features, ctx, listen) {
5
6
  this.overflowTracker = {};
@@ -14,7 +15,7 @@ export class ConfigSocket {
14
15
  }
15
16
  getLastActionIdsForSocket(socketKey) {
16
17
  const defaultResult = { lastId: 1, preIds: [] };
17
- if (this.pollId.hasOwnProperty(socketKey)) {
18
+ if (hasOwn(this.pollId, socketKey)) {
18
19
  const { lastId } = this.pollId[socketKey];
19
20
  const preIds = this.pollId[socketKey].control.getLastActionIdsArray(lastId).slice(0, 10);
20
21
  return { lastId, preIds };
package/dist/zalo.js CHANGED
@@ -94,9 +94,7 @@ export class Zalo {
94
94
  }
95
95
  async waitingConfirm(props) {
96
96
  const { ctx, loginVersion, code, imei, getPreviousImei } = props;
97
- console.log(props);
98
97
  const loginQRResult = await handleWaitingConfirm(ctx, loginVersion, code);
99
- console.log(loginQRResult);
100
98
  if (!loginQRResult || !(ctx === null || ctx === void 0 ? void 0 : ctx.userAgent))
101
99
  return null;
102
100
  return this.loginCookie({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zalo-toolkit",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "description": "Unofficial Zalo API for JavaScript",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",