rubjs 2.6.0 → 2.7.3

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.
Files changed (52) hide show
  1. package/package.json +2 -1
  2. package/rubjs/client.d.ts +2 -0
  3. package/rubjs/index.d.ts +2 -2
  4. package/rubjs/index.js +2 -1
  5. package/rubjs/methods/auth/registerDevice.js +1 -1
  6. package/rubjs/methods/auth/sendCode.js +4 -2
  7. package/rubjs/methods/channels/banChannelMember.js +4 -2
  8. package/rubjs/methods/channels/editChannelInfo.js +4 -2
  9. package/rubjs/methods/channels/joinChannelAction.js +4 -2
  10. package/rubjs/methods/chats/searchChatMessages.js +4 -2
  11. package/rubjs/methods/chats/sendChatActivity.js +4 -2
  12. package/rubjs/methods/chats/setActionChat.js +4 -2
  13. package/rubjs/methods/extras/index.d.ts +4 -1
  14. package/rubjs/methods/extras/index.js +7 -1
  15. package/rubjs/methods/extras/joinVoiceChat.d.ts +3 -0
  16. package/rubjs/methods/extras/joinVoiceChat.js +22 -0
  17. package/rubjs/methods/extras/sendVoiceChatActivity.d.ts +3 -0
  18. package/rubjs/methods/extras/sendVoiceChatActivity.js +24 -0
  19. package/rubjs/methods/extras/setVoiceChatState.d.ts +3 -0
  20. package/rubjs/methods/extras/setVoiceChatState.js +25 -0
  21. package/rubjs/methods/groups/banGroupMember.js +4 -2
  22. package/rubjs/methods/groups/createGroupVoiceChat.d.ts +1 -1
  23. package/rubjs/methods/groups/createGroupVoiceChat.js +2 -2
  24. package/rubjs/methods/groups/editGroupInfo.js +2 -1
  25. package/rubjs/methods/groups/getGroupVoiceChatParticipants.d.ts +3 -0
  26. package/rubjs/methods/groups/getGroupVoiceChatParticipants.js +18 -0
  27. package/rubjs/methods/groups/index.d.ts +3 -1
  28. package/rubjs/methods/groups/index.js +5 -1
  29. package/rubjs/methods/groups/joinGroupVoiceChat.d.ts +3 -0
  30. package/rubjs/methods/groups/joinGroupVoiceChat.js +22 -0
  31. package/rubjs/methods/groups/setGroupAdmin.js +4 -2
  32. package/rubjs/methods/index.d.ts +5 -0
  33. package/rubjs/methods/index.js +25 -0
  34. package/rubjs/methods/messages/createPoll.d.ts +1 -1
  35. package/rubjs/methods/messages/createPoll.js +5 -3
  36. package/rubjs/methods/messages/deleteMessages.js +4 -2
  37. package/rubjs/methods/messages/sendMessage.js +1 -1
  38. package/rubjs/methods/messages/setPinMessage.js +4 -2
  39. package/rubjs/methods/settings/setSetting.js +20 -10
  40. package/rubjs/methods/stickers/actionOnStickerSet.js +4 -2
  41. package/rubjs/methods/users/setBlockUser.js +3 -2
  42. package/rubjs/methods/utilities/start.js +0 -2
  43. package/rubjs/network/index.d.ts +8 -10
  44. package/rubjs/network/index.js +65 -46
  45. package/rubjs/session/index.js +1 -1
  46. package/rubjs/types/message.js +2 -3
  47. package/rubjs/utils/VoiceChatClient.d.ts +27 -0
  48. package/rubjs/utils/VoiceChatClient.js +133 -0
  49. package/rubjs/utils/filters.d.ts +2 -0
  50. package/rubjs/utils/filters.js +24 -0
  51. package/rubjs/utils/index.d.ts +2 -1
  52. package/rubjs/utils/index.js +3 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rubjs",
3
- "version": "2.6.0",
3
+ "version": "2.7.3",
4
4
  "main": "rubjs/index.js",
5
5
  "types": "rubjs/index.d.ts",
6
6
  "keywords": [
@@ -30,6 +30,7 @@
30
30
  "music-metadata": "^10.9.0",
31
31
  "node-rsa": "^1.1.1",
32
32
  "sharp": "^0.33.5",
33
+ "wrtc": "^0.4.7",
33
34
  "ws": "^8.18.0"
34
35
  },
35
36
  "devDependencies": {
package/rubjs/client.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import Methods from "./methods";
2
2
  import Network from "./network";
3
3
  import SQLiteSession from "./session";
4
+ import { VoiceChatClient } from "./utils";
4
5
  interface Platform {
5
6
  app_name: string;
6
7
  app_version: string;
@@ -30,6 +31,7 @@ declare class Client extends Methods {
30
31
  filters: ((msg: any) => boolean)[] | ((msg: any) => boolean)[][];
31
32
  updateType: TypeUpdate;
32
33
  }[];
34
+ voiceChatClient: VoiceChatClient;
33
35
  constructor(sessionFile: string, timeout?: number, platform?: PlatformType);
34
36
  }
35
37
  export default Client;
package/rubjs/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import Client from "./client";
2
2
  import Crypto from "./crypto";
3
3
  import * as Types from "./types";
4
- import { Filters, Utils } from "./utils";
4
+ import { Filters, Utils, VoiceChatClient } from "./utils";
5
5
  export default Client;
6
- export { Client, Crypto, Utils, Filters, Types };
6
+ export { Client, Crypto, Utils, VoiceChatClient, Filters, Types };
package/rubjs/index.js CHANGED
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.Types = exports.Filters = exports.Utils = exports.Crypto = exports.Client = void 0;
39
+ exports.Types = exports.Filters = exports.VoiceChatClient = exports.Utils = exports.Crypto = exports.Client = void 0;
40
40
  const client_1 = __importDefault(require("./client"));
41
41
  exports.Client = client_1.default;
42
42
  const crypto_1 = __importDefault(require("./crypto"));
@@ -46,4 +46,5 @@ exports.Types = Types;
46
46
  const utils_1 = require("./utils");
47
47
  Object.defineProperty(exports, "Filters", { enumerable: true, get: function () { return utils_1.Filters; } });
48
48
  Object.defineProperty(exports, "Utils", { enumerable: true, get: function () { return utils_1.Utils; } });
49
+ Object.defineProperty(exports, "VoiceChatClient", { enumerable: true, get: function () { return utils_1.VoiceChatClient; } });
49
50
  exports.default = client_1.default;
@@ -28,7 +28,7 @@ function getBrowser(userAgent, langCode, appVersion, ...args) {
28
28
  .match(/(opera|chrome|safari|firefox|msie|trident)\/(\d+)/);
29
29
  let deviceModel = "Unknown";
30
30
  if (!deviceModelMatch) {
31
- console.warn(`Cannot parse user-agent (${userAgent})`);
31
+ throw new Error(`Cannot parse user-agent (${userAgent})`);
32
32
  }
33
33
  else {
34
34
  deviceModel = `${deviceModelMatch[1]} ${deviceModelMatch[2]}`;
@@ -11,8 +11,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  function sendCode(phone_number_1) {
13
13
  return __awaiter(this, arguments, void 0, function* (phone_number, pass_key = null, send_type = "SMS") {
14
- if (!["SMS", "Internal"].includes(send_type))
15
- throw new Error("send_type can only be `SMS` or `Internal`.");
14
+ if (!["SMS", "Internal"].includes(send_type)) {
15
+ console.warn("`send_type` should be `SMS` or `Internal`. Using default `SMS`.");
16
+ send_type = "SMS";
17
+ }
16
18
  const data = {
17
19
  phone_number,
18
20
  pass_key,
@@ -11,8 +11,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  function banChannelMember(channel_guid_1, member_guid_1) {
13
13
  return __awaiter(this, arguments, void 0, function* (channel_guid, member_guid, action = "Set") {
14
- if (!["Set", "Unset"].includes(action))
15
- throw new Error(`${action} argument can only be in ["Set", "Unset"]`);
14
+ if (!["Set", "Unset"].includes(action)) {
15
+ console.warn(`${action} argument can only be in ["Set", "Unset"]. Using default "Set".`);
16
+ action = "Set";
17
+ }
16
18
  return yield this.builder("banChannelMember", {
17
19
  channel_guid,
18
20
  member_guid,
@@ -37,8 +37,10 @@ function editChannelInfo(channel_guid, title, description, channel_type, sign_me
37
37
  input.updated_parameters.push("is_restricted_content");
38
38
  }
39
39
  if (chat_history_for_new_members) {
40
- if (!["Hidden", "Visible"].includes(chat_history_for_new_members))
41
- throw new Error('`chat_history_for_new_members` argument can only be in `["Hidden", "Visible"]`.');
40
+ if (!["Hidden", "Visible"].includes(chat_history_for_new_members)) {
41
+ console.warn('`chat_history_for_new_members` should be in `["Hidden", "Visible"]`. Using default "Hidden".');
42
+ chat_history_for_new_members = "Hidden";
43
+ }
42
44
  input.chat_history_for_new_members = chat_history_for_new_members;
43
45
  input.updated_parameters.push("chat_history_for_new_members");
44
46
  }
@@ -11,8 +11,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  function joinChannelAction(channel_guid_1) {
13
13
  return __awaiter(this, arguments, void 0, function* (channel_guid, action = "Join") {
14
- if (!["Join", "Remove", "Archive"].includes(action))
15
- throw new Error('The `action` argument can only be in `["Join", "Remove", "Archive"]`.');
14
+ if (!["Join", "Remove", "Archive"].includes(action)) {
15
+ console.warn('The `action` argument can only be in `["Join", "Remove", "Archive"]`. Using default "Join".');
16
+ action = "Join";
17
+ }
16
18
  return yield this.builder("joinChannelAction", { channel_guid, action });
17
19
  });
18
20
  }
@@ -11,8 +11,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  function searchChatMessages(object_guid, search_text, type) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
- if (!["Text", "Hashtag"].includes(type))
15
- throw new Error('`type` argument can only be in ("text", "Hashtag").');
14
+ if (!["Text", "Hashtag"].includes(type)) {
15
+ console.warn('`type` argument can only be in ("text", "Hashtag"). Using default "Text".');
16
+ type = "Text";
17
+ }
16
18
  return yield this.builder("searchChatMessages", {
17
19
  object_guid,
18
20
  search_text,
@@ -11,8 +11,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  function sendChatActivity(object_guid, activity) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
- if (["Typing", "Uploading", "Recording"].includes(activity))
15
- throw new Error('`activity` argument can only be in `["Typing", "Uploading", "Recording"]`');
14
+ if (["Typing", "Uploading", "Recording"].includes(activity)) {
15
+ console.warn('`activity` argument can only be in `["Typing", "Uploading", "Recording"]` Using default "Typing".');
16
+ activity = "Typing";
17
+ }
16
18
  return yield this.builder("sendChatActivity", { object_guid, activity });
17
19
  });
18
20
  }
@@ -11,8 +11,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  function setActionChat(object_guid, action) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
- if (["Mute", "Unmute"].includes(action))
15
- throw new Error('`action` argument can only be in `["Mute", "Unmute"]`');
14
+ if (["Mute", "Unmute"].includes(action)) {
15
+ console.warn('`action` argument can only be in `["Mute", "Unmute"]` Using default "Mute".');
16
+ action = "Mute";
17
+ }
16
18
  return yield this.builder("setActionChat", { object_guid, action });
17
19
  });
18
20
  }
@@ -6,10 +6,13 @@ import getProfileLinkItems from "./getProfileLinkItems";
6
6
  import getRelatedObjects from "./getRelatedObjects";
7
7
  import getTranscription from "./getTranscription";
8
8
  import join from "./join";
9
+ import joinVoiceChat from "./joinVoiceChat";
9
10
  import leaveChat from "./leaveChat";
10
11
  import onEditMessages from "./onEditMessages";
11
12
  import reportObject from "./reportObject";
12
13
  import searchGlobalObjects from "./searchGlobalObjects";
14
+ import sendVoiceChatActivity from "./sendVoiceChatActivity";
15
+ import setVoiceChatState from "./setVoiceChatState";
13
16
  import transcribeVoice from "./transcribeVoice";
14
17
  import userIsAdmin from "./userIsAdmin";
15
- export { banMember, getInfo, getObjectByUsername, getProfileLinkItems, getRelatedObjects, getTranscription, join, leaveChat, onEditMessages, reportObject, searchGlobalObjects, transcribeVoice, userIsAdmin, deleteMessagebyCount };
18
+ export { banMember, getInfo, getObjectByUsername, getProfileLinkItems, getRelatedObjects, getTranscription, join, leaveChat, onEditMessages, reportObject, searchGlobalObjects, transcribeVoice, userIsAdmin, deleteMessagebyCount, joinVoiceChat, setVoiceChatState, sendVoiceChatActivity };
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.deleteMessagebyCount = exports.userIsAdmin = exports.transcribeVoice = exports.searchGlobalObjects = exports.reportObject = exports.onEditMessages = exports.leaveChat = exports.join = exports.getTranscription = exports.getRelatedObjects = exports.getProfileLinkItems = exports.getObjectByUsername = exports.getInfo = exports.banMember = void 0;
6
+ exports.sendVoiceChatActivity = exports.setVoiceChatState = exports.joinVoiceChat = exports.deleteMessagebyCount = exports.userIsAdmin = exports.transcribeVoice = exports.searchGlobalObjects = exports.reportObject = exports.onEditMessages = exports.leaveChat = exports.join = exports.getTranscription = exports.getRelatedObjects = exports.getProfileLinkItems = exports.getObjectByUsername = exports.getInfo = exports.banMember = void 0;
7
7
  const banMember_1 = __importDefault(require("./banMember"));
8
8
  exports.banMember = banMember_1.default;
9
9
  const deleteMessagebyCount_1 = __importDefault(require("./deleteMessagebyCount"));
@@ -20,6 +20,8 @@ const getTranscription_1 = __importDefault(require("./getTranscription"));
20
20
  exports.getTranscription = getTranscription_1.default;
21
21
  const join_1 = __importDefault(require("./join"));
22
22
  exports.join = join_1.default;
23
+ const joinVoiceChat_1 = __importDefault(require("./joinVoiceChat"));
24
+ exports.joinVoiceChat = joinVoiceChat_1.default;
23
25
  const leaveChat_1 = __importDefault(require("./leaveChat"));
24
26
  exports.leaveChat = leaveChat_1.default;
25
27
  const onEditMessages_1 = __importDefault(require("./onEditMessages"));
@@ -28,6 +30,10 @@ const reportObject_1 = __importDefault(require("./reportObject"));
28
30
  exports.reportObject = reportObject_1.default;
29
31
  const searchGlobalObjects_1 = __importDefault(require("./searchGlobalObjects"));
30
32
  exports.searchGlobalObjects = searchGlobalObjects_1.default;
33
+ const sendVoiceChatActivity_1 = __importDefault(require("./sendVoiceChatActivity"));
34
+ exports.sendVoiceChatActivity = sendVoiceChatActivity_1.default;
35
+ const setVoiceChatState_1 = __importDefault(require("./setVoiceChatState"));
36
+ exports.setVoiceChatState = setVoiceChatState_1.default;
31
37
  const transcribeVoice_1 = __importDefault(require("./transcribeVoice"));
32
38
  exports.transcribeVoice = transcribeVoice_1.default;
33
39
  const userIsAdmin_1 = __importDefault(require("./userIsAdmin"));
@@ -0,0 +1,3 @@
1
+ import Client from "../..";
2
+ declare function joinVoiceChat(this: Client, chat_guid: string, voice_chat_id: string, sdp_offer_data: string): Promise<any>;
3
+ export default joinVoiceChat;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ function joinVoiceChat(chat_guid, voice_chat_id, sdp_offer_data) {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ return yield this.builder(chat_guid.startsWith("g0") ? "joinGroupVoiceChat" : "joinChannelVoiceChat", {
15
+ chat_guid,
16
+ voice_chat_id,
17
+ sdp_offer_data,
18
+ self_object_guid: this.userGuid,
19
+ });
20
+ });
21
+ }
22
+ exports.default = joinVoiceChat;
@@ -0,0 +1,3 @@
1
+ import Client from "../..";
2
+ declare function sendVoiceChatActivity(this: Client, chat_guid: string, voice_chat_id: string, participant_object_guid: string, activity?: "Speaking"): Promise<any>;
3
+ export default sendVoiceChatActivity;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ function sendVoiceChatActivity(chat_guid_1, voice_chat_id_1, participant_object_guid_1) {
13
+ return __awaiter(this, arguments, void 0, function* (chat_guid, voice_chat_id, participant_object_guid, activity = "Speaking") {
14
+ return yield this.builder(chat_guid.startsWith("g0")
15
+ ? "sendGroupVoiceChatActivity"
16
+ : "sendChannelVoiceChatActivity", {
17
+ chat_guid,
18
+ voice_chat_id,
19
+ activity,
20
+ participant_object_guid: participant_object_guid || this.userGuid,
21
+ });
22
+ });
23
+ }
24
+ exports.default = sendVoiceChatActivity;
@@ -0,0 +1,3 @@
1
+ import Client from "../..";
2
+ declare function setVoiceChatState(this: Client, chat_guid: string, voice_chat_id: string, participant_object_guid?: string, action?: "Mute" | "Unmute"): Promise<any>;
3
+ export default setVoiceChatState;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ function setVoiceChatState(chat_guid_1, voice_chat_id_1, participant_object_guid_1) {
13
+ return __awaiter(this, arguments, void 0, function* (chat_guid, voice_chat_id, participant_object_guid, action = "Unmute") {
14
+ const method = chat_guid.startsWith("g0")
15
+ ? "setGroupVoiceChatState"
16
+ : "setChannelVoiceChatState";
17
+ return yield this.builder(method, {
18
+ chat_guid,
19
+ voice_chat_id,
20
+ participant_object_guid,
21
+ action,
22
+ });
23
+ });
24
+ }
25
+ exports.default = setVoiceChatState;
@@ -11,8 +11,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  function banGroupMember(group_guid_1, member_guid_1) {
13
13
  return __awaiter(this, arguments, void 0, function* (group_guid, member_guid, action = "Set") {
14
- if (!["Set", "Unset"].includes(action))
15
- throw new Error(`${action} argument can only be in ["Set", "Unset"].`);
14
+ if (!["Set", "Unset"].includes(action)) {
15
+ console.warn(`${action} argument can only be in ["Set", "Unset"]. Using default "Set".`);
16
+ action = "Set";
17
+ }
16
18
  return yield this.builder("banGroupMember", {
17
19
  group_guid,
18
20
  member_guid,
@@ -1,3 +1,3 @@
1
1
  import Client from "../..";
2
- declare function createGroupVoiceChat(this: Client, group_guid: string): Promise<any>;
2
+ declare function createGroupVoiceChat(this: Client, chat_guid: string): Promise<any>;
3
3
  export default createGroupVoiceChat;
@@ -9,9 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- function createGroupVoiceChat(group_guid) {
12
+ function createGroupVoiceChat(chat_guid) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
- return yield this.builder("createGroupVoiceChat", { group_guid });
14
+ return yield this.builder("createGroupVoiceChat", { chat_guid });
15
15
  });
16
16
  }
17
17
  exports.default = createGroupVoiceChat;
@@ -39,7 +39,8 @@ function editGroupInfo(group_guid, title, description, slow_mode, event_messages
39
39
  }
40
40
  if (chat_history_for_new_members !== undefined) {
41
41
  if (!["Hidden", "Visible"].includes(chat_history_for_new_members)) {
42
- throw new Error('`chat_history_for_new_members` argument can only be "Hidden" or "Visible".');
42
+ console.warn('`chat_history_for_new_members` argument can only be "Hidden" or "Visible". Using default "Hidden".');
43
+ chat_history_for_new_members = "Hidden";
43
44
  }
44
45
  input_data.chat_history_for_new_members = chat_history_for_new_members;
45
46
  updated_parameters.push("chat_history_for_new_members");
@@ -0,0 +1,3 @@
1
+ import Client from '../..';
2
+ declare function getGroupVoiceChatParticipants(this: Client, chat_guid: string, voice_chat_id: string): Promise<any>;
3
+ export default getGroupVoiceChatParticipants;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ function getGroupVoiceChatParticipants(chat_guid, voice_chat_id) {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ return yield this.builder('getGroupVoiceChatParticipants', { chat_guid, voice_chat_id });
15
+ });
16
+ }
17
+ ;
18
+ exports.default = getGroupVoiceChatParticipants;
@@ -14,9 +14,11 @@ import getGroupInfo from "./getGroupInfo";
14
14
  import getGroupLink from "./getGroupLink";
15
15
  import getGroupMentionList from "./getGroupMentionList";
16
16
  import getGroupOnlineCount from "./getGroupOnlineCount";
17
+ import getGroupVoiceChatParticipants from "./getGroupVoiceChatParticipants";
17
18
  import getGroupVoiceChatUpdates from "./getGroupVoiceChatUpdates";
18
19
  import groupPreviewByJoinLink from "./groupPreviewByJoinLink";
19
20
  import joinGroup from "./joinGroup";
21
+ import joinGroupVoiceChat from "./joinGroupVoiceChat";
20
22
  import leaveGroup from "./leaveGroup";
21
23
  import leaveGroupVoiceChat from "./leaveGroupVoiceChat";
22
24
  import removeGroup from "./removeGroup";
@@ -25,4 +27,4 @@ import setGroupAdmin from "./setGroupAdmin";
25
27
  import setGroupDefaultAccess from "./setGroupDefaultAccess";
26
28
  import setGroupLink from "./setGroupLink";
27
29
  import setGroupVoiceChatSetting from "./setGroupVoiceChatSetting";
28
- export { addGroup, addGroupMembers, banGroupMember, seenGroupMessages, discardGroupVoiceChat, createGroupVoiceChat, deleteNoAccessGroupChat, editGroupInfo, getBannedGroupMembers, getGroupAdminAccessList, getGroupAdminMembers, getGroupAllMembers, getGroupDefaultAccess, getGroupInfo, getGroupLink, getGroupOnlineCount, getGroupMentionList, getGroupVoiceChatUpdates, groupPreviewByJoinLink, joinGroup, leaveGroup, leaveGroupVoiceChat, removeGroup, setGroupAdmin, setGroupDefaultAccess, setGroupLink, setGroupVoiceChatSetting, };
30
+ export { addGroup, addGroupMembers, banGroupMember, seenGroupMessages, discardGroupVoiceChat, createGroupVoiceChat, deleteNoAccessGroupChat, editGroupInfo, getBannedGroupMembers, getGroupAdminAccessList, getGroupAdminMembers, getGroupAllMembers, getGroupDefaultAccess, getGroupInfo, getGroupLink, getGroupOnlineCount, getGroupMentionList, getGroupVoiceChatUpdates, groupPreviewByJoinLink, joinGroup, leaveGroup, leaveGroupVoiceChat, removeGroup, setGroupAdmin, setGroupDefaultAccess, setGroupLink, setGroupVoiceChatSetting, joinGroupVoiceChat, getGroupVoiceChatParticipants, };
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.setGroupVoiceChatSetting = exports.setGroupLink = exports.setGroupDefaultAccess = exports.setGroupAdmin = exports.removeGroup = exports.leaveGroupVoiceChat = exports.leaveGroup = exports.joinGroup = exports.groupPreviewByJoinLink = exports.getGroupVoiceChatUpdates = exports.getGroupMentionList = exports.getGroupOnlineCount = exports.getGroupLink = exports.getGroupInfo = exports.getGroupDefaultAccess = exports.getGroupAllMembers = exports.getGroupAdminMembers = exports.getGroupAdminAccessList = exports.getBannedGroupMembers = exports.editGroupInfo = exports.deleteNoAccessGroupChat = exports.createGroupVoiceChat = exports.discardGroupVoiceChat = exports.seenGroupMessages = exports.banGroupMember = exports.addGroupMembers = exports.addGroup = void 0;
6
+ exports.getGroupVoiceChatParticipants = exports.joinGroupVoiceChat = exports.setGroupVoiceChatSetting = exports.setGroupLink = exports.setGroupDefaultAccess = exports.setGroupAdmin = exports.removeGroup = exports.leaveGroupVoiceChat = exports.leaveGroup = exports.joinGroup = exports.groupPreviewByJoinLink = exports.getGroupVoiceChatUpdates = exports.getGroupMentionList = exports.getGroupOnlineCount = exports.getGroupLink = exports.getGroupInfo = exports.getGroupDefaultAccess = exports.getGroupAllMembers = exports.getGroupAdminMembers = exports.getGroupAdminAccessList = exports.getBannedGroupMembers = exports.editGroupInfo = exports.deleteNoAccessGroupChat = exports.createGroupVoiceChat = exports.discardGroupVoiceChat = exports.seenGroupMessages = exports.banGroupMember = exports.addGroupMembers = exports.addGroup = void 0;
7
7
  const addGroup_1 = __importDefault(require("./addGroup"));
8
8
  exports.addGroup = addGroup_1.default;
9
9
  const addGroupMembers_1 = __importDefault(require("./addGroupMembers"));
@@ -36,12 +36,16 @@ const getGroupMentionList_1 = __importDefault(require("./getGroupMentionList"));
36
36
  exports.getGroupMentionList = getGroupMentionList_1.default;
37
37
  const getGroupOnlineCount_1 = __importDefault(require("./getGroupOnlineCount"));
38
38
  exports.getGroupOnlineCount = getGroupOnlineCount_1.default;
39
+ const getGroupVoiceChatParticipants_1 = __importDefault(require("./getGroupVoiceChatParticipants"));
40
+ exports.getGroupVoiceChatParticipants = getGroupVoiceChatParticipants_1.default;
39
41
  const getGroupVoiceChatUpdates_1 = __importDefault(require("./getGroupVoiceChatUpdates"));
40
42
  exports.getGroupVoiceChatUpdates = getGroupVoiceChatUpdates_1.default;
41
43
  const groupPreviewByJoinLink_1 = __importDefault(require("./groupPreviewByJoinLink"));
42
44
  exports.groupPreviewByJoinLink = groupPreviewByJoinLink_1.default;
43
45
  const joinGroup_1 = __importDefault(require("./joinGroup"));
44
46
  exports.joinGroup = joinGroup_1.default;
47
+ const joinGroupVoiceChat_1 = __importDefault(require("./joinGroupVoiceChat"));
48
+ exports.joinGroupVoiceChat = joinGroupVoiceChat_1.default;
45
49
  const leaveGroup_1 = __importDefault(require("./leaveGroup"));
46
50
  exports.leaveGroup = leaveGroup_1.default;
47
51
  const leaveGroupVoiceChat_1 = __importDefault(require("./leaveGroupVoiceChat"));
@@ -0,0 +1,3 @@
1
+ import Client from "../..";
2
+ declare function joinGroupVoiceChat(this: Client, chat_guid: string, voice_chat_id: string, sdp_offer_data: string, self_object_guid: string): Promise<any>;
3
+ export default joinGroupVoiceChat;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ function joinGroupVoiceChat(chat_guid, voice_chat_id, sdp_offer_data, self_object_guid) {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ return yield this.builder("joinGroupVoiceChat", {
15
+ chat_guid,
16
+ voice_chat_id,
17
+ sdp_offer_data,
18
+ self_object_guid,
19
+ });
20
+ });
21
+ }
22
+ exports.default = joinGroupVoiceChat;
@@ -11,8 +11,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  function setGroupAdmin(group_guid, member_guid, action, access_list) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
- if (!["SetAdmin", "UnsetAdmin"].includes(action))
15
- throw new Error(`${action} argument can only be in ["SetAdmin", "UnsetAdmin"].`);
14
+ if (!["SetAdmin", "UnsetAdmin"].includes(action)) {
15
+ console.warn(`${action} argument can only be in ["SetAdmin", "UnsetAdmin"]. Using default "SetAdmin".`);
16
+ action = "SetAdmin";
17
+ }
16
18
  if (typeof access_list === "string")
17
19
  access_list = [access_list];
18
20
  return yield this.builder("setGroupAdmin", {
@@ -101,6 +101,9 @@ declare class Methods {
101
101
  transcribeVoice(this: Client, ...args: Parameters<typeof Extras.transcribeVoice>): Promise<any>;
102
102
  userIsAdmin(this: Client, ...args: Parameters<typeof Extras.userIsAdmin>): Promise<any>;
103
103
  deleteMessagebyCount(this: Client, ...args: Parameters<typeof Extras.deleteMessagebyCount>): Promise<any>;
104
+ joinVoiceChat(this: Client, ...args: Parameters<typeof Extras.joinVoiceChat>): Promise<any>;
105
+ setVoiceChatState(this: Client, ...args: Parameters<typeof Extras.setVoiceChatState>): Promise<any>;
106
+ sendVoiceChatActivity(this: Client, ...args: Parameters<typeof Extras.sendVoiceChatActivity>): Promise<any>;
104
107
  addToMyGifSet(this: Client, ...args: Parameters<typeof Gif.addToMyGifSet>): Promise<any>;
105
108
  getMyGifSet(this: Client, ...args: Parameters<typeof Gif.getMyGifSet>): Promise<any>;
106
109
  removeFromMyGifSet(this: Client, ...args: Parameters<typeof Gif.removeFromMyGifSet>): Promise<any>;
@@ -131,6 +134,8 @@ declare class Methods {
131
134
  seenGroupMessages(this: Client, ...args: Parameters<typeof Groups.seenGroupMessages>): Promise<any>;
132
135
  setGroupLink(this: Client, ...args: Parameters<typeof Groups.setGroupLink>): Promise<any>;
133
136
  setGroupVoiceChatSetting(this: Client, ...args: Parameters<typeof Groups.setGroupVoiceChatSetting>): Promise<any>;
137
+ joinGroupVoiceChat(this: Client, ...args: Parameters<typeof Groups.joinGroupVoiceChat>): Promise<any>;
138
+ getGroupVoiceChatParticipants(this: Client, ...args: Parameters<typeof Groups.getGroupVoiceChatParticipants>): Promise<any>;
134
139
  actionOnMessageReaction(this: Client, ...args: Parameters<typeof Messages.actionOnMessageReaction>): Promise<{
135
140
  reactions: MessagesTypes.Reaction[];
136
141
  }>;
@@ -470,6 +470,21 @@ class Methods {
470
470
  return Extras.deleteMessagebyCount.apply(this, args);
471
471
  });
472
472
  }
473
+ joinVoiceChat(...args) {
474
+ return __awaiter(this, void 0, void 0, function* () {
475
+ return Extras.joinVoiceChat.apply(this, args);
476
+ });
477
+ }
478
+ setVoiceChatState(...args) {
479
+ return __awaiter(this, void 0, void 0, function* () {
480
+ return Extras.setVoiceChatState.apply(this, args);
481
+ });
482
+ }
483
+ sendVoiceChatActivity(...args) {
484
+ return __awaiter(this, void 0, void 0, function* () {
485
+ return Extras.sendVoiceChatActivity.apply(this, args);
486
+ });
487
+ }
473
488
  // gif
474
489
  addToMyGifSet(...args) {
475
490
  return __awaiter(this, void 0, void 0, function* () {
@@ -622,6 +637,16 @@ class Methods {
622
637
  return Groups.setGroupVoiceChatSetting.apply(this, args);
623
638
  });
624
639
  }
640
+ joinGroupVoiceChat(...args) {
641
+ return __awaiter(this, void 0, void 0, function* () {
642
+ return Groups.joinGroupVoiceChat.apply(this, args);
643
+ });
644
+ }
645
+ getGroupVoiceChatParticipants(...args) {
646
+ return __awaiter(this, void 0, void 0, function* () {
647
+ return Groups.getGroupVoiceChatParticipants.apply(this, args);
648
+ });
649
+ }
625
650
  // messages
626
651
  actionOnMessageReaction(...args) {
627
652
  return __awaiter(this, void 0, void 0, function* () {
@@ -1,3 +1,3 @@
1
- import Client from '../..';
1
+ import Client from "../..";
2
2
  declare function createPoll(this: Client, object_guid: string, question: string, options: string[], type?: "Regular" | "Quiz", is_anonymous?: boolean, allows_multiple_answers?: boolean, correct_option_index?: number, explanation?: string, reply_to_message_id?: string): Promise<any>;
3
3
  export default createPoll;
@@ -12,9 +12,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  function createPoll(object_guid_1, question_1, options_1) {
13
13
  return __awaiter(this, arguments, void 0, function* (object_guid, question, options, type = "Regular", is_anonymous = true, allows_multiple_answers = true, correct_option_index, explanation, reply_to_message_id) {
14
14
  if (options.length <= 1)
15
- throw new Error("The `options` argument must have more than two string values.");
16
- if (!["Quiz", "Regular"].includes(type))
17
- throw new Error('The `type` argument can only be in `["Quiz", "Regular"]`.');
15
+ return console.warn("The `options` argument must have more than two string values.");
16
+ if (!["Quiz", "Regular"].includes(type)) {
17
+ console.warn('The `type` argument can only be in `["Quiz", "Regular"]`. Using default "Quiz".');
18
+ type = "Quiz";
19
+ }
18
20
  const input = {
19
21
  object_guid,
20
22
  question,
@@ -11,8 +11,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  function deleteMessages(object_guid_1, message_ids_1) {
13
13
  return __awaiter(this, arguments, void 0, function* (object_guid, message_ids, type = "Global") {
14
- if (!["Global", "Local"].includes(type))
15
- throw new Error('`type` argument can only be in ("Global", "Local").');
14
+ if (!["Global", "Local"].includes(type)) {
15
+ console.warn('`type` argument can only be in ("Global", "Local"). Using default "Global".');
16
+ type = "Global";
17
+ }
16
18
  if (typeof message_ids === "string") {
17
19
  message_ids = [message_ids];
18
20
  }
@@ -69,7 +69,7 @@ function sendMessage(object_guid_1) {
69
69
  if (typeof file_inline === "string") {
70
70
  fileName = file_inline;
71
71
  if (!fs.existsSync(fileName)) {
72
- throw new Error("File not found in the given path");
72
+ return console.warn("File not found in the given path");
73
73
  }
74
74
  file_inline = yield fs.promises.readFile(fileName);
75
75
  }
@@ -11,8 +11,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  function setPinMessage(object_guid_1, message_id_1) {
13
13
  return __awaiter(this, arguments, void 0, function* (object_guid, message_id, action = "Pin") {
14
- if (!["Pin", "Unpin"].includes(action))
15
- throw new Error(`The ${action} argument can only be in ("Pin", "Unpin").`);
14
+ if (!["Pin", "Unpin"].includes(action)) {
15
+ console.warn(`The ${action} argument can only be in ("Pin", "Unpin"). Using default "Pin".`);
16
+ action = "Pin";
17
+ }
16
18
  return yield this.builder("setPinMessage", {
17
19
  object_guid,
18
20
  message_id,
@@ -15,32 +15,42 @@ function setSetting(show_my_last_online, show_my_phone_number, link_forward_mess
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
16
  let input = {};
17
17
  if (typeof show_my_last_online === "string") {
18
- if (!allSettingsType.includes(show_my_last_online))
19
- throw new Error('The `show_my_last_online` can only be in `["Nobody", "Everybody", "MyContacts"]`.');
18
+ if (!allSettingsType.includes(show_my_last_online)) {
19
+ console.warn('The `show_my_last_online` can only be in `["Nobody", "Everybody", "MyContacts"]`. Using default "Hidden".');
20
+ show_my_last_online = "Everybody";
21
+ }
20
22
  input.show_my_last_online = show_my_last_online;
21
23
  input.updated_parameters.push("show_my_last_online");
22
24
  }
23
25
  if (typeof show_my_phone_number === "string") {
24
- if (!allSettingsType.includes(show_my_phone_number))
25
- throw new Error('The `show_my_phone_number` can only be in `["Nobody", "Everybody", "MyContacts"]`.');
26
+ if (!allSettingsType.includes(show_my_phone_number)) {
27
+ console.warn('The `show_my_phone_number` can only be in `["Nobody", "Everybody", "MyContacts"]`. Using default "Hidden".');
28
+ show_my_phone_number = "Everybody";
29
+ }
26
30
  input.show_my_phone_number = show_my_phone_number;
27
31
  input.updated_parameters.push("show_my_phone_number");
28
32
  }
29
33
  if (typeof link_forward_message === "string") {
30
- if (!allSettingsType.includes(link_forward_message))
31
- throw new Error('The `link_forward_message` can only be in `["Nobody", "Everybody", "MyContacts"]`.');
34
+ if (!allSettingsType.includes(link_forward_message)) {
35
+ console.warn('The `link_forward_message` can only be in `["Nobody", "Everybody", "MyContacts"]`. Using default "Hidden".');
36
+ link_forward_message = "Everybody";
37
+ }
32
38
  input.link_forward_message = link_forward_message;
33
39
  input.updated_parameters.push("link_forward_message");
34
40
  }
35
41
  if (typeof show_my_profile_photo === "string") {
36
- if (!settingsType.includes(show_my_profile_photo))
37
- throw new Error('The `show_my_profile_photo` can only be in `["Everybody", "MyContacts"]`.');
42
+ if (!settingsType.includes(show_my_profile_photo)) {
43
+ console.warn('The `show_my_profile_photo` can only be in `["Everybody", "MyContacts"]`. Using default "Hidden".');
44
+ show_my_profile_photo = "Everybody";
45
+ }
38
46
  input.show_my_profile_photo = show_my_profile_photo;
39
47
  input.updated_parameters.push("show_my_profile_photo");
40
48
  }
41
49
  if (typeof can_join_chat_by === "string") {
42
- if (!settingsType.includes(can_join_chat_by))
43
- throw new Error('The `can_join_chat_by` can only be in `["Everybody", "MyContacts"]`.');
50
+ if (!settingsType.includes(can_join_chat_by)) {
51
+ console.warn('The `can_join_chat_by` can only be in `["Everybody", "MyContacts"]`. Using default "Hidden".');
52
+ can_join_chat_by = "Everybody";
53
+ }
44
54
  input.can_join_chat_by = can_join_chat_by;
45
55
  input.updated_parameters.push("can_join_chat_by");
46
56
  }
@@ -11,8 +11,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  function actionOnStickerSet(sticker_set_id, action) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
- if (!["Add", "Remove"].includes(action))
15
- throw new Error('The `action` argument can only be in `("Add", "Remove")`.');
14
+ if (!["Add", "Remove"].includes(action)) {
15
+ console.warn('The `action` argument can only be in `("Add", "Remove")`. Using default "Add".');
16
+ action = "Add";
17
+ }
16
18
  return yield this.builder("actionOnStickerSet", { sticker_set_id, action });
17
19
  });
18
20
  }
@@ -11,8 +11,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  function setBlockUser(user_guid_1) {
13
13
  return __awaiter(this, arguments, void 0, function* (user_guid, action = "Block") {
14
- if (!["Block", "Unblock"].includes(action))
15
- throw new Error("`action` argument can only be `Block` or `Unblock`.");
14
+ if (!["Block", "Unblock"].includes(action)) {
15
+ console.warn("`action` argument can only be `Block` or `Unblock`. Using default 'Block'.");
16
+ }
16
17
  return yield this.builder("setBlockUser", { user_guid, action });
17
18
  });
18
19
  }
@@ -24,8 +24,6 @@ function start() {
24
24
  this.initialize = true;
25
25
  }
26
26
  catch (error) {
27
- if (this.auth)
28
- throw new Error("robot has any error" + error.message);
29
27
  let phone_number = yield input_1.default.text("Phone Number: ");
30
28
  let is_phone_number_true = true;
31
29
  const phoneRegex = /^[0-9]{11}$/;
@@ -1,18 +1,15 @@
1
1
  import { Axios } from "axios";
2
- import WebSocket from "ws";
3
- import https from "https";
4
2
  import Client from "..";
5
3
  declare class Network {
6
4
  private heartbeatInterval;
7
- Headers: {
8
- [key: string]: string;
9
- };
10
- client: Client;
5
+ private inactivityTimeout;
6
+ private Headers;
7
+ private client;
8
+ private apiUrl;
9
+ private wssUrl;
10
+ private ws;
11
+ private agent;
11
12
  session: Axios;
12
- apiUrl: null | string;
13
- wssUrl: null | string;
14
- ws: WebSocket;
15
- agent: https.Agent;
16
13
  constructor(client: Client);
17
14
  getDcs(): Promise<boolean>;
18
15
  request(url: string, data: Record<string, any>): Promise<any>;
@@ -25,6 +22,7 @@ declare class Network {
25
22
  handleConnect(): Promise<void>;
26
23
  resetConnection(): Promise<void>;
27
24
  handleMessage(message: string): Promise<void>;
25
+ private resetInactivityTimer;
28
26
  uploadFile(file: Buffer<ArrayBufferLike> | string, mime?: string | null, fileName?: string | null, chunk?: number, callback?: any): Promise<{
29
27
  mime: string;
30
28
  size: number;
@@ -55,29 +55,29 @@ const types_1 = require("../types");
55
55
  class Network {
56
56
  constructor(client) {
57
57
  this.heartbeatInterval = null;
58
+ this.inactivityTimeout = null;
59
+ this.apiUrl = null;
60
+ this.wssUrl = null;
61
+ this.ws = null;
62
+ this.client = client;
58
63
  this.Headers = {
59
64
  origin: "https://web.rubika.ir",
60
65
  referer: "https://web.rubika.ir/",
61
66
  "content-type": "application/json",
62
67
  connection: "keep-alive",
68
+ "user-agent": client.userAgent,
63
69
  };
64
- this.client = client;
65
- this.Headers["user-agent"] = this.client.userAgent;
66
- if (this.client.defaultPlatform.platform === "Android") {
70
+ if (client.defaultPlatform.platform === "Android") {
67
71
  delete this.Headers.origin;
68
72
  delete this.Headers.referer;
69
73
  this.Headers["user-agent"] = "okhttp/3.12.1";
70
74
  }
71
75
  this.agent = new https_1.default.Agent({ rejectUnauthorized: false });
72
- const axiosConfig = {
76
+ this.session = axios_1.default.create({
73
77
  headers: this.Headers,
74
- timeout: this.client.timeout || 10000,
78
+ timeout: client.timeout || 10000,
75
79
  httpsAgent: this.agent,
76
- };
77
- this.session = axios_1.default.create(axiosConfig);
78
- this.apiUrl = null;
79
- this.wssUrl = null;
80
- this.ws = null;
80
+ });
81
81
  }
82
82
  getDcs() {
83
83
  return __awaiter(this, void 0, void 0, function* () {
@@ -95,8 +95,8 @@ class Network {
95
95
  }
96
96
  catch (_a) {
97
97
  console.error("Error while fetching dcs");
98
- continue;
99
98
  }
99
+ yield new Promise((resolve) => setTimeout(resolve, 3000));
100
100
  }
101
101
  });
102
102
  }
@@ -105,13 +105,11 @@ class Network {
105
105
  for (let i = 0; i < 3; i++) {
106
106
  try {
107
107
  const response = yield this.session.post(url, data);
108
- if (response.status === 200) {
108
+ if (response.status === 200)
109
109
  return response.data;
110
- }
111
110
  }
112
- catch (error) {
113
- console.error("Error in request ");
114
- continue;
111
+ catch (_a) {
112
+ console.error("Error in request");
115
113
  }
116
114
  }
117
115
  throw new Error("Failed to get response after 3 attempts");
@@ -119,19 +117,17 @@ class Network {
119
117
  }
120
118
  send(_a) {
121
119
  return __awaiter(this, arguments, void 0, function* ({ input = {}, method = "getUserInfo", tmp_session, }) {
122
- let api_version = this.client.apiVersion;
123
- let auth = this.client.auth;
124
- let client = this.client.defaultPlatform;
125
120
  if (!this.apiUrl)
126
121
  yield this.getDcs();
127
- let url = this.apiUrl;
128
- let data = { api_version };
129
- data[tmp_session ? "tmp_session" : "auth"] = tmp_session
130
- ? auth
131
- : this.client.decode_auth;
132
- if (api_version === "6") {
122
+ const data = {
123
+ api_version: this.client.apiVersion,
124
+ [tmp_session ? "tmp_session" : "auth"]: tmp_session
125
+ ? this.client.auth
126
+ : this.client.decode_auth,
127
+ };
128
+ if (this.client.apiVersion === "6") {
133
129
  const data_enc = JSON.stringify({
134
- client,
130
+ client: this.client.defaultPlatform,
135
131
  method,
136
132
  input,
137
133
  });
@@ -139,8 +135,8 @@ class Network {
139
135
  if (!tmp_session) {
140
136
  data["sign"] = crypto_1.default.sign(data["data_enc"], this.client.privateKey);
141
137
  }
142
- return yield this.request(url, data);
143
138
  }
139
+ return yield this.request(this.apiUrl, data);
144
140
  });
145
141
  }
146
142
  getUpdates() {
@@ -148,33 +144,51 @@ class Network {
148
144
  if (!this.wssUrl)
149
145
  yield this.getDcs();
150
146
  this.ws = new ws_1.default(this.wssUrl);
151
- this.ws.on("open", () => __awaiter(this, void 0, void 0, function* () { return yield this.handleConnect(); }));
152
- this.ws.on("message", (message) => __awaiter(this, void 0, void 0, function* () { return yield this.handleMessage(message); }));
153
- this.ws.on("error", () => __awaiter(this, void 0, void 0, function* () { return yield this.resetConnection(); }));
147
+ this.ws.on("open", () => __awaiter(this, void 0, void 0, function* () {
148
+ console.log("WebSocket connected.");
149
+ yield this.handleConnect();
150
+ this.resetInactivityTimer();
151
+ }));
152
+ this.ws.on("message", (message) => __awaiter(this, void 0, void 0, function* () {
153
+ yield this.handleMessage(message);
154
+ this.resetInactivityTimer();
155
+ }));
156
+ this.ws.on("error", () => __awaiter(this, void 0, void 0, function* () {
157
+ console.error("WebSocket error, reconnecting...");
158
+ yield this.resetConnection();
159
+ }));
160
+ this.ws.on("close", () => __awaiter(this, void 0, void 0, function* () {
161
+ console.warn("WebSocket closed, reconnecting...");
162
+ yield this.resetConnection();
163
+ }));
154
164
  });
155
165
  }
156
166
  handleConnect() {
157
167
  return __awaiter(this, void 0, void 0, function* () {
168
+ var _a;
158
169
  console.log("Start Bot..");
159
- const handshakeRequest = {
160
- api_version: "5",
161
- auth: this.client.auth,
162
- data: "",
163
- method: "handShake",
164
- };
165
- this.ws.send(JSON.stringify(handshakeRequest));
166
- if (this.heartbeatInterval) {
167
- clearInterval(this.heartbeatInterval);
170
+ if (this.ws.readyState === ws_1.default.OPEN) {
171
+ (_a = this.ws) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify({
172
+ api_version: "5",
173
+ auth: this.client.auth,
174
+ data: "",
175
+ method: "handShake",
176
+ }));
168
177
  }
178
+ clearInterval(this.heartbeatInterval);
169
179
  this.heartbeatInterval = setInterval(() => {
170
- if (this.ws.readyState === ws_1.default.OPEN) {
180
+ var _a;
181
+ if (((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN) {
171
182
  this.ws.send(JSON.stringify({}));
172
183
  }
173
- }, 30 * 1000);
184
+ }, 30000);
174
185
  });
175
186
  }
176
187
  resetConnection() {
177
188
  return __awaiter(this, void 0, void 0, function* () {
189
+ var _a;
190
+ (_a = this.ws) === null || _a === void 0 ? void 0 : _a.close();
191
+ this.ws = null;
178
192
  setTimeout(() => this.getUpdates(), 5000);
179
193
  });
180
194
  }
@@ -202,10 +216,8 @@ class Network {
202
216
  }
203
217
  return false;
204
218
  });
205
- const dataMessage = new types_1.Message(this.client, messageData);
206
- if (isValid) {
207
- yield callback(dataMessage);
208
- }
219
+ if (isValid)
220
+ yield callback(new types_1.Message(this.client, messageData));
209
221
  }
210
222
  }
211
223
  }));
@@ -215,6 +227,13 @@ class Network {
215
227
  }
216
228
  });
217
229
  }
230
+ resetInactivityTimer() {
231
+ clearTimeout(this.inactivityTimeout);
232
+ this.inactivityTimeout = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
233
+ console.warn("No updates received for 10 minutes. Reconnecting WebSocket...");
234
+ yield this.resetConnection();
235
+ }), 10 * 60 * 1000);
236
+ }
218
237
  uploadFile(file_1) {
219
238
  return __awaiter(this, arguments, void 0, function* (file, mime = null, fileName = null, chunk = 1048576, callback = null) {
220
239
  var _a;
@@ -279,7 +298,7 @@ class Network {
279
298
  }
280
299
  if (response.data.status === "OK" && response.data.status_det === "OK") {
281
300
  if (!((_a = response.data.data) === null || _a === void 0 ? void 0 : _a.access_hash_rec))
282
- throw new Error("Error in upload file!!");
301
+ console.warn("Error in upload file!!");
283
302
  return {
284
303
  mime,
285
304
  size: file.length,
@@ -16,7 +16,7 @@ class SQLiteSession {
16
16
  }
17
17
  catch (error) {
18
18
  console.error(`Error in ${operation}:`, error);
19
- throw new Error(`Failed to execute ${operation}`);
19
+ console.warn(`Failed to execute ${operation}`);
20
20
  }
21
21
  }
22
22
  initializeDB() {
@@ -11,9 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const getOriginalType = (message) => {
13
13
  var _a;
14
- if (!((_a = message === null || message === void 0 ? void 0 : message.message) === null || _a === void 0 ? void 0 : _a.type)) {
15
- return console.log(message);
16
- }
14
+ if (!((_a = message === null || message === void 0 ? void 0 : message.message) === null || _a === void 0 ? void 0 : _a.type))
15
+ return "Delete";
17
16
  if (message.message.type.includes("FileInline")) {
18
17
  return message.message.file_inline.type;
19
18
  }
@@ -0,0 +1,27 @@
1
+ import Client from "..";
2
+ declare class VoiceChatClient {
3
+ private pc;
4
+ private source;
5
+ private track;
6
+ private ffmpeg?;
7
+ private buffer;
8
+ private frameSize;
9
+ private playlist;
10
+ private currentIndex;
11
+ private chatGuid?;
12
+ private voiceChatId?;
13
+ private client?;
14
+ private isPaused;
15
+ private lastPosition;
16
+ private intervalId?;
17
+ constructor();
18
+ play(filePath?: string): Promise<void>;
19
+ stop(): void;
20
+ resume(): void;
21
+ next(): void;
22
+ previous(): void;
23
+ addToPlaylist(filePath: string): void;
24
+ joinVoiceChat(chatGuid: string, voiceChatId: string, client: Client): Promise<void>;
25
+ private clearIntervals;
26
+ }
27
+ export default VoiceChatClient;
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const child_process_1 = require("child_process");
13
+ const wrtc_1 = require("wrtc");
14
+ class VoiceChatClient {
15
+ constructor() {
16
+ this.buffer = Buffer.alloc(0);
17
+ this.frameSize = 960;
18
+ this.playlist = [];
19
+ this.currentIndex = 0;
20
+ this.isPaused = false;
21
+ this.lastPosition = 0;
22
+ this.pc = new wrtc_1.RTCPeerConnection();
23
+ this.source = new wrtc_1.nonstandard.RTCAudioSource();
24
+ this.track = this.source.createTrack();
25
+ this.pc.addTrack(this.track);
26
+ }
27
+ play(filePath) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ if (this.ffmpeg)
30
+ this.stop();
31
+ if (!filePath) {
32
+ if (this.playlist.length === 0)
33
+ return;
34
+ filePath = this.playlist[this.currentIndex];
35
+ }
36
+ if (!this.chatGuid || !this.voiceChatId || !this.client) {
37
+ throw new Error("Voice chat not initialized. Call `joinVoiceChat` first.");
38
+ }
39
+ this.isPaused = false;
40
+ this.buffer = Buffer.alloc(0);
41
+ const seekArgs = this.lastPosition > 0 ? ["-ss", this.lastPosition.toString()] : [];
42
+ this.ffmpeg = (0, child_process_1.spawn)("ffmpeg", [
43
+ "-loglevel", "quiet",
44
+ "-re",
45
+ "-threads", "1", // کاهش مصرف رم و پردازش
46
+ ...seekArgs,
47
+ "-i", filePath,
48
+ "-acodec", "pcm_s16le",
49
+ "-ar", "48000",
50
+ "-ac", "1",
51
+ "-f", "s16le",
52
+ "pipe:1",
53
+ ]);
54
+ this.ffmpeg.stdout.on("data", (chunk) => {
55
+ this.buffer = Buffer.concat([this.buffer, chunk]);
56
+ while (this.buffer.length >= this.frameSize) {
57
+ if (this.isPaused)
58
+ return;
59
+ const frame = this.buffer.subarray(0, this.frameSize);
60
+ this.buffer = this.buffer.subarray(this.frameSize);
61
+ const samples = new Int16Array(frame.buffer, frame.byteOffset, this.frameSize / 2);
62
+ const trimmedSamples = samples.slice(0, 960);
63
+ this.source.onData({ samples: trimmedSamples, sampleRate: 48000 });
64
+ this.lastPosition += 0.02;
65
+ }
66
+ });
67
+ this.ffmpeg.on("close", () => this.next());
68
+ this.ffmpeg.on("exit", () => this.next());
69
+ });
70
+ }
71
+ stop() {
72
+ if (this.ffmpeg) {
73
+ this.ffmpeg.kill();
74
+ this.ffmpeg = undefined;
75
+ this.isPaused = true;
76
+ this.buffer = Buffer.alloc(0); // پاک کردن بافر برای کاهش مصرف رم
77
+ }
78
+ }
79
+ resume() {
80
+ if (this.isPaused)
81
+ this.play();
82
+ }
83
+ next() {
84
+ if (this.playlist.length > this.currentIndex + 1) {
85
+ this.currentIndex++;
86
+ this.lastPosition = 0;
87
+ this.play();
88
+ }
89
+ }
90
+ previous() {
91
+ if (this.currentIndex > 0) {
92
+ this.currentIndex--;
93
+ this.lastPosition = 0;
94
+ this.play();
95
+ }
96
+ }
97
+ addToPlaylist(filePath) {
98
+ this.playlist.push(filePath);
99
+ }
100
+ joinVoiceChat(chatGuid, voiceChatId, client) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ this.chatGuid = chatGuid;
103
+ this.voiceChatId = voiceChatId;
104
+ this.client = client;
105
+ const offer = yield this.pc.createOffer();
106
+ yield this.pc.setLocalDescription(offer);
107
+ const connect = yield client.joinGroupVoiceChat(chatGuid, voiceChatId, offer.sdp, client.userGuid);
108
+ const sdpAnswer = connect.sdp_answer_data;
109
+ yield this.pc.setRemoteDescription(new wrtc_1.RTCSessionDescription({ type: "answer", sdp: sdpAnswer }));
110
+ yield client.setVoiceChatState(chatGuid, voiceChatId);
111
+ this.clearIntervals();
112
+ this.intervalId = setInterval(() => __awaiter(this, void 0, void 0, function* () {
113
+ try {
114
+ yield client.getGroupVoiceChatUpdates(chatGuid, voiceChatId);
115
+ }
116
+ catch (_a) { }
117
+ }), 10 * 1000);
118
+ this.intervalId = setInterval(() => __awaiter(this, void 0, void 0, function* () {
119
+ try {
120
+ yield client.sendVoiceChatActivity(chatGuid, voiceChatId, client.userGuid);
121
+ }
122
+ catch (_a) { }
123
+ }), 2 * 1000);
124
+ });
125
+ }
126
+ clearIntervals() {
127
+ if (this.intervalId) {
128
+ clearInterval(this.intervalId);
129
+ this.intervalId = undefined;
130
+ }
131
+ }
132
+ }
133
+ exports.default = VoiceChatClient;
@@ -26,5 +26,7 @@ declare class Filters {
26
26
  static isPoll(message: MessageUpdate): boolean;
27
27
  static isLive(message: MessageUpdate): boolean;
28
28
  static isEvent(message: MessageUpdate): boolean;
29
+ static startsWithCommand(text: string, object_guid?: string): (message: MessageUpdate) => boolean;
30
+ static equalCommand(text: string, object_guid?: string): (message: MessageUpdate) => boolean;
29
31
  }
30
32
  export default Filters;
@@ -122,5 +122,29 @@ class Filters {
122
122
  static isEvent(message) {
123
123
  return !!Filters.findKey(message, "event_data");
124
124
  }
125
+ static startsWithCommand(text, object_guid) {
126
+ return (message) => {
127
+ var _a;
128
+ if (object_guid) {
129
+ if (object_guid !== message.object_guid)
130
+ return false;
131
+ }
132
+ if ((_a = message === null || message === void 0 ? void 0 : message.message) === null || _a === void 0 ? void 0 : _a.text) {
133
+ return message.message.text.startsWith(text);
134
+ }
135
+ };
136
+ }
137
+ static equalCommand(text, object_guid) {
138
+ return (message) => {
139
+ var _a;
140
+ if (object_guid) {
141
+ if (object_guid !== message.object_guid)
142
+ return false;
143
+ }
144
+ if ((_a = message === null || message === void 0 ? void 0 : message.message) === null || _a === void 0 ? void 0 : _a.text) {
145
+ return message.message.text === text;
146
+ }
147
+ };
148
+ }
125
149
  }
126
150
  exports.default = Filters;
@@ -1,3 +1,4 @@
1
1
  import Filters from "./filters";
2
2
  import Utils from "./utils";
3
- export { Filters, Utils };
3
+ import VoiceChatClient from "./VoiceChatClient";
4
+ export { Filters, Utils, VoiceChatClient };
@@ -3,8 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Utils = exports.Filters = void 0;
6
+ exports.VoiceChatClient = exports.Utils = exports.Filters = void 0;
7
7
  const filters_1 = __importDefault(require("./filters"));
8
8
  exports.Filters = filters_1.default;
9
9
  const utils_1 = __importDefault(require("./utils"));
10
10
  exports.Utils = utils_1.default;
11
+ const VoiceChatClient_1 = __importDefault(require("./VoiceChatClient"));
12
+ exports.VoiceChatClient = VoiceChatClient_1.default;