rubjs 2.6.0 → 2.6.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rubjs",
3
- "version": "2.6.0",
3
+ "version": "2.6.1",
4
4
  "main": "rubjs/index.js",
5
5
  "types": "rubjs/index.d.ts",
6
6
  "keywords": [
@@ -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
  }
@@ -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,
@@ -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");
@@ -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", {
@@ -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() {