@eryxenx/insta-chat 2.0.0 → 2.0.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.
- package/CHANGELOG.md +95 -8
- package/index.js +105 -1
- package/module/login.js +51 -1
- package/package.json +9 -2
- package/src/api/action/getAppState.js +19 -1
- package/src/api/action/getCookies.js +7 -1
- package/src/api/action/getCurrentUserID.js +7 -1
- package/src/api/action/setOptions.js +8 -1
- package/src/api/messaging/editMessage.js +19 -1
- package/src/api/messaging/markAsRead.js +7 -1
- package/src/api/messaging/resolvePhotoUrl.js +8 -1
- package/src/api/messaging/sendMessage.js +45 -1
- package/src/api/messaging/sendMessageSync.js +8 -1
- package/src/api/messaging/sendTypingIndicator.js +7 -1
- package/src/api/messaging/setMessageReaction.js +19 -1
- package/src/api/messaging/shareContact.js +19 -1
- package/src/api/messaging/unsendMessage.js +16 -1
- package/src/api/realtime/getInbox.js +7 -1
- package/src/api/realtime/listen.js +7 -1
- package/src/api/realtime/stopListening.js +7 -1
- package/src/api/threads/getThreadHistory.js +16 -1
- package/src/api/threads/getThreadInfo.js +59 -1
- package/src/api/threads/getThreadList.js +22 -1
- package/src/api/users/getUID.js +12 -1
- package/src/api/users/getUserInfo.js +37 -1
- package/src/api.js +253 -1
- package/src/app/InstaClient.js +352 -1
- package/src/app/InstaContext.js +46 -1
- package/src/app/createFcaClient.js +59 -1
- package/src/app/loadApiMethods.js +30 -1
- package/src/constants.js +53 -1
- package/src/cookies.js +41 -1
- package/src/deviceIdentity.js +31 -1
- package/src/events/normalizeEvent.js +142 -1
- package/src/http.js +381 -1
- package/src/messageContent.js +73 -1
- package/src/methods/inbox.js +464 -1
- package/src/methods/media.js +218 -1
- package/src/methods/message.js +115 -1
- package/src/methods/reactions.js +52 -1
- package/src/methods/thread.js +96 -1
- package/src/methods/typing.js +35 -1
- package/src/methods/user.js +33 -1
- package/src/session.js +94 -1
- package/src/threadDetail.js +36 -1
- package/src/utils/antiSuspension.js +269 -0
- package/src/utils/dataDir.js +11 -0
- package/src/utils/errors.js +106 -0
- package/src/utils/format.js +38 -1
- package/src/utils/messageStyle.js +57 -1
- package/src/utils/sessionGuard.js +93 -0
|
@@ -4,4 +4,10 @@
|
|
|
4
4
|
* Licensed under the Apache License, Version 2.0. See LICENSE and NOTICE.
|
|
5
5
|
* Original author credit must be retained in all copies and derivatives.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
// fca.sendTypingIndicator(threadID)
|
|
9
|
+
module.exports = function (client) {
|
|
10
|
+
return async function sendTypingIndicator(threadID) {
|
|
11
|
+
return client.api.startTyping(String(threadID)).catch(() => false);
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -4,4 +4,22 @@
|
|
|
4
4
|
* Licensed under the Apache License, Version 2.0. See LICENSE and NOTICE.
|
|
5
5
|
* Original author credit must be retained in all copies and derivatives.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
// fca.setMessageReaction(emoji, messageID, callback, force). Commands pass
|
|
9
|
+
// `true` as the 4th argument, so anything that is not a real thread id is
|
|
10
|
+
// ignored and the thread the message was seen in is used instead.
|
|
11
|
+
module.exports = function (client) {
|
|
12
|
+
return async function setMessageReaction(emoji, messageID, callback, threadID) {
|
|
13
|
+
const cb = typeof callback === "function" ? callback : null;
|
|
14
|
+
try {
|
|
15
|
+
const tid = client._resolveThread(messageID, threadID);
|
|
16
|
+
await client.api.sendReaction(tid, String(messageID), emoji);
|
|
17
|
+
const info = { messageID, threadID: tid };
|
|
18
|
+
if (cb) cb(null, info);
|
|
19
|
+
return info;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (cb) cb(error, null);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -4,4 +4,22 @@
|
|
|
4
4
|
* Licensed under the Apache License, Version 2.0. See LICENSE and NOTICE.
|
|
5
5
|
* Original author credit must be retained in all copies and derivatives.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
// Instagram has no contact-card message, so fca.shareContact(uid, uid, threadID,
|
|
9
|
+
// messageID) is answered with the user's profile link + id as a normal message.
|
|
10
|
+
module.exports = function (client) {
|
|
11
|
+
return async function shareContact(uid, _uid2, threadID, callback) {
|
|
12
|
+
const cb = typeof callback === "function" ? callback : null;
|
|
13
|
+
try {
|
|
14
|
+
const u = await client.api.getUserInfo(String(uid)).catch(() => null);
|
|
15
|
+
const name = u?.full_name || u?.username || String(uid);
|
|
16
|
+
const link = u?.username ? `https://instagram.com/${u.username}` : `https://instagram.com/${uid}`;
|
|
17
|
+
const info = await client.sendMessage({ body: `\u{1F464} ${name}\n\u{1F517} ${link}\n\u{1F194} ${uid}` }, String(threadID));
|
|
18
|
+
if (cb) cb(null, info);
|
|
19
|
+
return info;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (cb) cb(error, null);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -4,4 +4,19 @@
|
|
|
4
4
|
* Licensed under the Apache License, Version 2.0. See LICENSE and NOTICE.
|
|
5
5
|
* Original author credit must be retained in all copies and derivatives.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
// fca.unsendMessage(messageID) — the thread is resolved from the id.
|
|
9
|
+
module.exports = function (client) {
|
|
10
|
+
return async function unsendMessage(messageID, callback) {
|
|
11
|
+
const cb = typeof callback === "function" ? callback : null;
|
|
12
|
+
try {
|
|
13
|
+
const tid = client._resolveThread(messageID);
|
|
14
|
+
const ok = await client.api.unsendMessage(tid, String(messageID));
|
|
15
|
+
if (cb) cb(null, ok);
|
|
16
|
+
return ok;
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if (cb) cb(error, null);
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -4,4 +4,10 @@
|
|
|
4
4
|
* Licensed under the Apache License, Version 2.0. See LICENSE and NOTICE.
|
|
5
5
|
* Original author credit must be retained in all copies and derivatives.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
// Instagram-specific: read the DM inbox directly.
|
|
9
|
+
module.exports = function (client) {
|
|
10
|
+
return function getInbox(cursor) {
|
|
11
|
+
return client.api.getInbox(cursor);
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -4,4 +4,10 @@
|
|
|
4
4
|
* Licensed under the Apache License, Version 2.0. See LICENSE and NOTICE.
|
|
5
5
|
* Original author credit must be retained in all copies and derivatives.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
// fca.listen(callback) - the Instagram inbox poller.
|
|
9
|
+
module.exports = function (client) {
|
|
10
|
+
return function listen(callback, intervalMs) {
|
|
11
|
+
return client.api.listen(callback, intervalMs || client.options.pollInterval);
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -4,4 +4,10 @@
|
|
|
4
4
|
* Licensed under the Apache License, Version 2.0. See LICENSE and NOTICE.
|
|
5
5
|
* Original author credit must be retained in all copies and derivatives.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
// fca.stopListening()
|
|
9
|
+
module.exports = function (client) {
|
|
10
|
+
return function stopListening() {
|
|
11
|
+
return client.api.stopListening();
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -4,4 +4,19 @@
|
|
|
4
4
|
* Licensed under the Apache License, Version 2.0. See LICENSE and NOTICE.
|
|
5
5
|
* Original author credit must be retained in all copies and derivatives.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
// fca.getThreadHistory(threadID, amount, timestamp, callback).
|
|
9
|
+
module.exports = function (client) {
|
|
10
|
+
return async function getThreadHistory(threadID, _amount, _timestamp, callback) {
|
|
11
|
+
const cb = typeof callback === "function" ? callback : null;
|
|
12
|
+
try {
|
|
13
|
+
const limit = Math.max(Number(_amount) || 0, 20);
|
|
14
|
+
const items = await client.api.getThreadHistory(String(threadID), limit);
|
|
15
|
+
if (cb) cb(null, items);
|
|
16
|
+
return items;
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if (cb) cb(error, null);
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -4,4 +4,62 @@
|
|
|
4
4
|
* Licensed under the Apache License, Version 2.0. See LICENSE and NOTICE.
|
|
5
5
|
* Original author credit must be retained in all copies and derivatives.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
// fca.getThreadInfo(threadID, callback) - Instagram thread detail reshaped into
|
|
9
|
+
// the fca thread-info object commands expect. Commands iterate `userInfo` and
|
|
10
|
+
// `.some()`/`.find()` `adminIDs`, so both are arrays here (GoatBot-Pro shape:
|
|
11
|
+
// userInfo [{ id, name, firstName, gender }], adminIDs [{ id }]).
|
|
12
|
+
module.exports = function (client) {
|
|
13
|
+
return async function getThreadInfo(threadID, callback) {
|
|
14
|
+
const cb = typeof callback === "function" ? callback : null;
|
|
15
|
+
try {
|
|
16
|
+
const thread = await client.api.getThreadInfo(String(threadID));
|
|
17
|
+
client._learnThreads(thread);
|
|
18
|
+
const users = (thread?.users || []).slice();
|
|
19
|
+
const viewer = thread?.viewer;
|
|
20
|
+
// The thread-detail query lists only *other* participants; re-add the
|
|
21
|
+
// viewer so participantIDs/name lookups are complete.
|
|
22
|
+
const hasViewer = viewer && users.some((u) => String(u.id || u.pk) === String(viewer.id));
|
|
23
|
+
if (viewer && !hasViewer) {
|
|
24
|
+
users.unshift({
|
|
25
|
+
id: viewer.id, pk: viewer.id, username: viewer.username,
|
|
26
|
+
interop_messaging_user_fbid: viewer.interop_messaging_user_fbid,
|
|
27
|
+
profile_pic_url: viewer.profile_pic_url
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const userInfo = users.map((u) => ({
|
|
31
|
+
id: String(u.pk || u.id),
|
|
32
|
+
name: u.full_name || u.username || String(u.pk || u.id),
|
|
33
|
+
firstName: (u.full_name || u.username || "").split(" ")[0] || "",
|
|
34
|
+
username: u.username || null,
|
|
35
|
+
gender: u.gender === undefined ? 0 : u.gender,
|
|
36
|
+
type: "User",
|
|
37
|
+
profileUrl: u.profile_pic_url || null,
|
|
38
|
+
thumbSrc: u.profile_pic_url || null
|
|
39
|
+
}));
|
|
40
|
+
const userIds = new Set(userInfo.map((u) => u.id));
|
|
41
|
+
const adminIDs = (thread?.admin_user_ids || [])
|
|
42
|
+
.map(String)
|
|
43
|
+
.filter((id) => userIds.has(id))
|
|
44
|
+
.map((id) => ({ id }));
|
|
45
|
+
const info = {
|
|
46
|
+
threadID: String(threadID),
|
|
47
|
+
threadName: thread?.thread_title || (users[0]?.username ?? null),
|
|
48
|
+
participantIDs: userInfo.map((u) => u.id),
|
|
49
|
+
userInfo,
|
|
50
|
+
adminIDs,
|
|
51
|
+
members: userInfo,
|
|
52
|
+
nicknames: thread?.nicknames || {},
|
|
53
|
+
isGroup: typeof thread?.is_group === "boolean" ? thread.is_group : users.length > 1,
|
|
54
|
+
messageCount: thread?.slide_messages?.edges?.length ?? thread?.items?.length ?? 0,
|
|
55
|
+
emoji: null,
|
|
56
|
+
color: null
|
|
57
|
+
};
|
|
58
|
+
if (cb) cb(null, info);
|
|
59
|
+
return info;
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (cb) cb(error, null);
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
};
|
|
@@ -4,4 +4,25 @@
|
|
|
4
4
|
* Licensed under the Apache License, Version 2.0. See LICENSE and NOTICE.
|
|
5
5
|
* Original author credit must be retained in all copies and derivatives.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
// fca.getThreadList(limit, timestamp, tags, callback) - the DM inbox.
|
|
9
|
+
module.exports = function (client) {
|
|
10
|
+
return async function getThreadList(limit = 10, _timestamp, _tags, callback) {
|
|
11
|
+
const cb = typeof callback === "function" ? callback : null;
|
|
12
|
+
try {
|
|
13
|
+
const { threads } = await client.api.getInbox();
|
|
14
|
+
const list = threads.slice(0, limit).map((t) => ({
|
|
15
|
+
threadID: String(t.id || t.thread_id),
|
|
16
|
+
name: t.thread_title || null,
|
|
17
|
+
snippet: t.items?.[0]?.text || "",
|
|
18
|
+
timestamp: t.items?.[0]?.timestamp || null,
|
|
19
|
+
unreadCount: t.read_state ?? 0
|
|
20
|
+
}));
|
|
21
|
+
if (cb) cb(null, list);
|
|
22
|
+
return list;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (cb) cb(error, null);
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
package/src/api/users/getUID.js
CHANGED
|
@@ -4,4 +4,15 @@
|
|
|
4
4
|
* Licensed under the Apache License, Version 2.0. See LICENSE and NOTICE.
|
|
5
5
|
* Original author credit must be retained in all copies and derivatives.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
// Frozen pp.js calls api.getUID(<profile link>) then treats the result as an id.
|
|
9
|
+
// Extract the trailing username/id from the URL, else fall back to the current
|
|
10
|
+
// user.
|
|
11
|
+
module.exports = function (client) {
|
|
12
|
+
return function getUID(input) {
|
|
13
|
+
const s = String(input || "");
|
|
14
|
+
const m = s.match(/instagram\.com\/([^/?#]+)/i) || s.match(/facebook\.com\/([^/?#]+)/i);
|
|
15
|
+
if (m) return m[1];
|
|
16
|
+
return client.userID;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -4,4 +4,40 @@
|
|
|
4
4
|
* Licensed under the Apache License, Version 2.0. See LICENSE and NOTICE.
|
|
5
5
|
* Original author credit must be retained in all copies and derivatives.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
// fca.getUserInfo(id | id[], callback) -> { <id>: { name, firstName, username,
|
|
9
|
+
// profileUrl, thumbSrc, gender } }.
|
|
10
|
+
module.exports = function (client) {
|
|
11
|
+
return async function getUserInfo(ids, callback) {
|
|
12
|
+
const cb = typeof callback === "function" ? callback : null;
|
|
13
|
+
const list = Array.isArray(ids) ? ids : [ids];
|
|
14
|
+
try {
|
|
15
|
+
const out = {};
|
|
16
|
+
for (const id of list) {
|
|
17
|
+
const key = String(id);
|
|
18
|
+
// A handle learned from the inbox/thread views answers without a
|
|
19
|
+
// rate-limited lookup (usernameinfo / user info both 429 on web).
|
|
20
|
+
const known = client.getUserByUsername ? client.getUserByUsername(key) : null;
|
|
21
|
+
const u = known || await client.api.getUserInfo(key).catch(() => null);
|
|
22
|
+
const cachedPic = client._picCache.get(key) ||
|
|
23
|
+
client._picCache.get(client._picCache.get(`name:${key}`)) || null;
|
|
24
|
+
const cachedName = client._picCache.get(`name:${key}`) || null;
|
|
25
|
+
out[key] = {
|
|
26
|
+
name: u?.full_name || u?.username || cachedName || String(id),
|
|
27
|
+
firstName: u?.full_name || u?.username || cachedName || "",
|
|
28
|
+
username: u?.username || cachedName || null,
|
|
29
|
+
profileUrl: u?.profile_pic_url || cachedPic || null,
|
|
30
|
+
thumbSrc: u?.profile_pic_url || cachedPic || null,
|
|
31
|
+
gender: u?.gender ?? null
|
|
32
|
+
};
|
|
33
|
+
if (u?.profile_pic_url) client._picCache.set(key, u.profile_pic_url);
|
|
34
|
+
if (u?.username) client._picCache.set(`name:${key}`, u.username);
|
|
35
|
+
}
|
|
36
|
+
if (cb) cb(null, out);
|
|
37
|
+
return out;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (cb) cb(error, null);
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
};
|