@eryxenx/insta-chat 2.0.10 → 2.0.11

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": "@eryxenx/insta-chat",
3
- "version": "2.0.10",
3
+ "version": "2.0.11",
4
4
  "description": " Unofficial Instagram Chat API for Node.js | Build Instagram DM bots on personal accounts — send messages, media, voice notes, reactions, edit & unsend, listen for incoming chats. No browser at runtime",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/src/constants.js CHANGED
@@ -49,6 +49,7 @@ const EP = {
49
49
  USER_INFO: (userID) => `${BASE}/users/${userID}/info/`,
50
50
  USER_BY_USERNAME: (username) => `${BASE}/users/${username}/usernameinfo/`,
51
51
  USER_SEARCH: (query, count) => `${BASE}/users/search/?q=${encodeURIComponent(query)}&count=${count}`,
52
+ TOPSEARCH: (query) => `${WEB}/web/search/topsearch/?query=${encodeURIComponent(query)}&context=blended`,
52
53
  RUPLOAD_PHOTO: (uploadName) => `https://i.instagram.com/rupload_igphoto/${uploadName}`,
53
54
  RUPLOAD_VIDEO: (uploadName) => `https://i.instagram.com/rupload_igvideo/${uploadName}`,
54
55
  RUPLOAD_AUDIO: (uploadName) => `https://i.instagram.com/rupload_igdirect/${uploadName}`,
@@ -34,6 +34,17 @@ class UserMethods {
34
34
  const match = (res?.users || []).find(
35
35
  (u) => u.username?.toLowerCase() === username.toLowerCase()
36
36
  );
37
+ if (match) return match;
38
+ } catch (_) {}
39
+
40
+ // web/search/topsearch is the path a logged-in web session actually gets an
41
+ // answer from; the /api/v1 users/* REST paths above are 302'd for web. It
42
+ // returns an exact-match user object (with pk) at users[].user.
43
+ try {
44
+ const res = await this.http.get(EP.TOPSEARCH(username));
45
+ const match = (res?.users || [])
46
+ .map((entry) => entry.user || entry)
47
+ .find((u) => u?.username?.toLowerCase() === username.toLowerCase());
37
48
  return match || null;
38
49
  } catch (_) {
39
50
  return null;