alicezetion 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.cache/replit/__replit_disk_meta.json +1 -0
- package/.cache/replit/modules.stamp +0 -0
- package/.cache/replit/nix/env.json +1 -0
- package/.travis.yml +6 -0
- package/README.md +40 -0
- package/alice/add.js +99 -0
- package/alice/admin.js +65 -0
- package/alice/archive.js +41 -0
- package/alice/block.js +72 -0
- package/alice/chat.js +415 -0
- package/alice/color.js +53 -0
- package/alice/deletegc.js +43 -0
- package/alice/deletemsg.js +43 -0
- package/alice/delivered.js +41 -0
- package/alice/emoji.js +41 -0
- package/alice/emojiurl.js +29 -0
- package/alice/forward.js +47 -0
- package/alice/friend.js +70 -0
- package/alice/gchistorydeprecated.js +76 -0
- package/alice/gcimage.js +115 -0
- package/alice/gcimg.js +66 -0
- package/alice/gcinfo.js +170 -0
- package/alice/gcinfodeprecated.js +65 -0
- package/alice/gclist.js +220 -0
- package/alice/gclistdeprecated.js +75 -0
- package/alice/gcolor.js +22 -0
- package/alice/gcsearch.js +39 -0
- package/alice/history.js +632 -0
- package/alice/id.js +7 -0
- package/alice/kick.js +65 -0
- package/alice/listen.js +553 -0
- package/alice/listenMqtt.js +560 -0
- package/alice/logout.js +59 -0
- package/alice/msgrequest.js +51 -0
- package/alice/mute.js +38 -0
- package/alice/nickname.js +44 -0
- package/alice/poll.js +55 -0
- package/alice/react.js +82 -0
- package/alice/read.js +52 -0
- package/alice/resolveimgurl.js +31 -0
- package/alice/seen.js +36 -0
- package/alice/title.js +73 -0
- package/alice/typeindicator.js +77 -0
- package/alice/unsend.js +35 -0
- package/alice/userid.js +52 -0
- package/alice/userinfo.js +57 -0
- package/index.js +423 -0
- package/package.json +70 -0
- package/utils.js +1283 -0
package/alice/gclist.js
ADDED
@@ -0,0 +1,220 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const utils = require("../utils");
|
4
|
+
const log = require("npmlog");
|
5
|
+
|
6
|
+
function createProfileUrl(url, username, id) {
|
7
|
+
if (url) return url;
|
8
|
+
return "https://www.facebook.com/" + (username || utils.formatID(id.toString()));
|
9
|
+
}
|
10
|
+
|
11
|
+
function formatParticipants(participants) {
|
12
|
+
return participants.nodes.map((p)=>{
|
13
|
+
p = p.messaging_actor;
|
14
|
+
switch (p["__typename"]) {
|
15
|
+
case "User":
|
16
|
+
return {
|
17
|
+
accountType: p["__typename"],
|
18
|
+
userID: utils.formatID(p.id.toString()), // do we need .toString()? when it is not a string?
|
19
|
+
name: p.name,
|
20
|
+
shortName: p.short_name,
|
21
|
+
gender: p.gender,
|
22
|
+
url: p.url, // how about making it profileURL
|
23
|
+
profilePicture: p.big_image_src.uri,
|
24
|
+
username: (p.username||null),
|
25
|
+
// TODO: maybe better names for these?
|
26
|
+
isViewerFriend: p.is_viewer_friend, // true/false
|
27
|
+
isMessengerUser: p.is_messenger_user, // true/false
|
28
|
+
isVerified: p.is_verified, // true/false
|
29
|
+
isMessageBlockedByViewer: p.is_message_blocked_by_viewer, // true/false
|
30
|
+
isViewerCoworker: p.is_viewer_coworker, // true/false
|
31
|
+
isEmployee: p.is_employee // null? when it is something other? can someone check?
|
32
|
+
};
|
33
|
+
case "Page":
|
34
|
+
return {
|
35
|
+
accountType: p["__typename"],
|
36
|
+
userID: utils.formatID(p.id.toString()), // or maybe... pageID?
|
37
|
+
name: p.name,
|
38
|
+
url: p.url,
|
39
|
+
profilePicture: p.big_image_src.uri,
|
40
|
+
username: (p.username||null),
|
41
|
+
// uhm... better names maybe?
|
42
|
+
acceptsMessengerUserFeedback: p.accepts_messenger_user_feedback, // true/false
|
43
|
+
isMessengerUser: p.is_messenger_user, // true/false
|
44
|
+
isVerified: p.is_verified, // true/false
|
45
|
+
isMessengerPlatformBot: p.is_messenger_platform_bot, // true/false
|
46
|
+
isMessageBlockedByViewer: p.is_message_blocked_by_viewer, // true/false
|
47
|
+
};
|
48
|
+
case "ReducedMessagingActor":
|
49
|
+
return {
|
50
|
+
accountType: p["__typename"],
|
51
|
+
userID: utils.formatID(p.id.toString()),
|
52
|
+
name: p.name,
|
53
|
+
url: createProfileUrl(p.url, p.username, p.id), // in this case p.url is null all the time
|
54
|
+
profilePicture: p.big_image_src.uri, // in this case it is default facebook photo, we could determine gender using it
|
55
|
+
username: (p.username||null), // maybe we could use it to generate profile URL?
|
56
|
+
isMessageBlockedByViewer: p.is_message_blocked_by_viewer, // true/false
|
57
|
+
};
|
58
|
+
case "UnavailableMessagingActor":
|
59
|
+
return {
|
60
|
+
accountType: p["__typename"],
|
61
|
+
userID: utils.formatID(p.id.toString()),
|
62
|
+
name: p.name, // "Facebook User" in user's language
|
63
|
+
url: createProfileUrl(p.url, p.username, p.id), // in this case p.url is null all the time
|
64
|
+
profilePicture: p.big_image_src.uri, // default male facebook photo
|
65
|
+
username: (p.username||null), // maybe we could use it to generate profile URL?
|
66
|
+
isMessageBlockedByViewer: p.is_message_blocked_by_viewer, // true/false
|
67
|
+
};
|
68
|
+
default:
|
69
|
+
log.warn("getThreadList", "Found participant with unsupported typename. Please open an issue at https://github.com/Schmavery/facebook-chat-api/issues\n" + JSON.stringify(p, null, 2));
|
70
|
+
return {
|
71
|
+
accountType: p["__typename"],
|
72
|
+
userID: utils.formatID(p.id.toString()),
|
73
|
+
name: p.name || `[unknown ${p["__typename"]}]`, // probably it will always be something... but fallback to [unknown], just in case
|
74
|
+
};
|
75
|
+
}
|
76
|
+
});
|
77
|
+
}
|
78
|
+
|
79
|
+
// "FF8C0077" -> "8C0077"
|
80
|
+
function formatColor(color) {
|
81
|
+
if (color && color.match(/^(?:[0-9a-fA-F]{8})$/g)) {
|
82
|
+
return color.slice(2);
|
83
|
+
}
|
84
|
+
return color;
|
85
|
+
}
|
86
|
+
|
87
|
+
function getThreadName(t) {
|
88
|
+
if (t.name || t.thread_key.thread_fbid) return t.name;
|
89
|
+
|
90
|
+
for (let p of t.all_participants.nodes) {
|
91
|
+
if (p.messaging_actor.id === t.thread_key.other_user_id) return p.messaging_actor.name;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
function mapNicknames(customizationInfo) {
|
96
|
+
return (customizationInfo && customizationInfo.participant_customizations) ? customizationInfo.participant_customizations.map(u => {
|
97
|
+
return {
|
98
|
+
"userID": u.participant_id,
|
99
|
+
"nickname": u.nickname
|
100
|
+
};
|
101
|
+
}):[];
|
102
|
+
}
|
103
|
+
|
104
|
+
function formatThreadList(data) {
|
105
|
+
return data.map(t => {
|
106
|
+
let lastMessageNode = (t.last_message&&t.last_message.nodes&&t.last_message.nodes.length>0)?t.last_message.nodes[0]:null;
|
107
|
+
return {
|
108
|
+
threadID: t.thread_key?utils.formatID(t.thread_key.thread_fbid || t.thread_key.other_user_id):null, // shall never be null
|
109
|
+
name: getThreadName(t),
|
110
|
+
unreadCount: t.unread_count,
|
111
|
+
messageCount: t.messages_count,
|
112
|
+
imageSrc: t.image?t.image.uri:null,
|
113
|
+
emoji: t.customization_info?t.customization_info.emoji:null,
|
114
|
+
color: formatColor(t.customization_info?t.customization_info.outgoing_bubble_color:null),
|
115
|
+
nicknames: mapNicknames(t.customization_info),
|
116
|
+
muteUntil: t.mute_until,
|
117
|
+
participants: formatParticipants(t.all_participants),
|
118
|
+
adminIDs: t.thread_admins.map(a => a.id),
|
119
|
+
folder: t.folder,
|
120
|
+
isGroup: t.thread_type === "GROUP",
|
121
|
+
// rtc_call_data: t.rtc_call_data, // TODO: format and document this
|
122
|
+
// isPinProtected: t.is_pin_protected, // feature from future? always false (2018-04-04)
|
123
|
+
customizationEnabled: t.customization_enabled, // false for ONE_TO_ONE with Page or ReducedMessagingActor
|
124
|
+
participantAddMode: t.participant_add_mode_as_string, // "ADD" if "GROUP" and null if "ONE_TO_ONE"
|
125
|
+
montageThread: t.montage_thread?Buffer.from(t.montage_thread.id,"base64").toString():null, // base64 encoded string "message_thread:0000000000000000"
|
126
|
+
// it is not userID nor any other ID known to me...
|
127
|
+
// can somebody inspect it? where is it used?
|
128
|
+
// probably Messenger Day uses it
|
129
|
+
reactionsMuteMode: t.reactions_mute_mode,
|
130
|
+
mentionsMuteMode: t.mentions_mute_mode,
|
131
|
+
isArchived: t.has_viewer_archived,
|
132
|
+
isSubscribed: t.is_viewer_subscribed,
|
133
|
+
timestamp: t.updated_time_precise, // in miliseconds
|
134
|
+
// isCanonicalUser: t.is_canonical_neo_user, // is it always false?
|
135
|
+
// TODO: how about putting snippet in another object? current implementation does not handle every possibile message type etc.
|
136
|
+
snippet: lastMessageNode?lastMessageNode.snippet:null,
|
137
|
+
snippetAttachments: lastMessageNode?lastMessageNode.extensible_attachment:null, // TODO: not sure if it works
|
138
|
+
snippetSender: lastMessageNode?utils.formatID((lastMessageNode.message_sender.messaging_actor.id || "").toString()):null,
|
139
|
+
lastMessageTimestamp: lastMessageNode?lastMessageNode.timestamp_precise:null, // timestamp in miliseconds
|
140
|
+
lastReadTimestamp: (t.last_read_receipt&&t.last_read_receipt.nodes.length>0)
|
141
|
+
? (t.last_read_receipt.nodes[0]?t.last_read_receipt.nodes[0].timestamp_precise:null)
|
142
|
+
: null, // timestamp in miliseconds
|
143
|
+
cannotReplyReason: t.cannot_reply_reason, // TODO: inspect possible values
|
144
|
+
|
145
|
+
// @Legacy
|
146
|
+
participantIDs: formatParticipants(t.all_participants).map(participant => participant.userID),
|
147
|
+
threadType: t.thread_type === "GROUP" ? 2 : 1 // "GROUP" or "ONE_TO_ONE"
|
148
|
+
};
|
149
|
+
});
|
150
|
+
}
|
151
|
+
|
152
|
+
module.exports = function(defaultFuncs, bot, ctx) {
|
153
|
+
return function getThreadList(limit, timestamp, tags, callback) {
|
154
|
+
if (!callback && (utils.getType(tags) === "Function" || utils.getType(tags) === "AsyncFunction")) {
|
155
|
+
callback = tags;
|
156
|
+
tags = [""];
|
157
|
+
}
|
158
|
+
if (utils.getType(limit) !== "Number" || !Number.isInteger(limit) || limit <= 0) {
|
159
|
+
throw {error: "getThreadList: limit must be a positive integer"};
|
160
|
+
}
|
161
|
+
if (utils.getType(timestamp) !== "Null" &&
|
162
|
+
(utils.getType(timestamp) !== "Number" || !Number.isInteger(timestamp))) {
|
163
|
+
throw {error: "getThreadList: timestamp must be an integer or null"};
|
164
|
+
}
|
165
|
+
if (utils.getType(tags) === "String") {
|
166
|
+
tags = [tags];
|
167
|
+
}
|
168
|
+
if (utils.getType(tags) !== "Array") {
|
169
|
+
throw {error: "getThreadList: tags must be an array"};
|
170
|
+
}
|
171
|
+
if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
|
172
|
+
throw {error: "getThreadList: need callback"};
|
173
|
+
}
|
174
|
+
|
175
|
+
const form = {
|
176
|
+
"av": ctx.globalOptions.pageID,
|
177
|
+
"queries": JSON.stringify({
|
178
|
+
"o0": {
|
179
|
+
// This doc_id was valid on 2018-04-04.
|
180
|
+
"doc_id": "1349387578499440",
|
181
|
+
"query_params": {
|
182
|
+
"limit": limit+(timestamp?1:0),
|
183
|
+
"before": timestamp,
|
184
|
+
"tags": tags,
|
185
|
+
"includeDeliveryReceipts": true,
|
186
|
+
"includeSeqID": false
|
187
|
+
}
|
188
|
+
}
|
189
|
+
})
|
190
|
+
};
|
191
|
+
|
192
|
+
defaultFuncs
|
193
|
+
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
194
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
195
|
+
.then((resData) => {
|
196
|
+
if (resData[resData.length - 1].error_results > 0) {
|
197
|
+
throw resData[0].o0.errors;
|
198
|
+
}
|
199
|
+
|
200
|
+
if (resData[resData.length - 1].successful_results === 0) {
|
201
|
+
throw {error: "getThreadList: there was no successful_results", res: resData};
|
202
|
+
}
|
203
|
+
|
204
|
+
// When we ask for threads using timestamp from the previous request,
|
205
|
+
// we are getting the last thread repeated as the first thread in this response.
|
206
|
+
// .shift() gets rid of it
|
207
|
+
// It is also the reason for increasing limit by 1 when timestamp is set
|
208
|
+
// this way user asks for 10 threads, we are asking for 11,
|
209
|
+
// but after removing the duplicated one, it is again 10
|
210
|
+
if (timestamp) {
|
211
|
+
resData[0].o0.data.viewer.message_threads.nodes.shift();
|
212
|
+
}
|
213
|
+
callback(null, formatThreadList(resData[0].o0.data.viewer.message_threads.nodes));
|
214
|
+
})
|
215
|
+
.catch((err) => {
|
216
|
+
log.error("getThreadList", err);
|
217
|
+
return callback(err);
|
218
|
+
});
|
219
|
+
};
|
220
|
+
};
|
@@ -0,0 +1,75 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
|
6
|
+
module.exports = function(defaultFuncs, bot, ctx) {
|
7
|
+
return function getThreadList(start, end, type, callback) {
|
8
|
+
if (utils.getType(callback) === "Undefined") {
|
9
|
+
if (utils.getType(end) !== "Number") {
|
10
|
+
throw {
|
11
|
+
error: "Please pass a number as a second argument."
|
12
|
+
};
|
13
|
+
} else if (
|
14
|
+
utils.getType(type) === "Function" ||
|
15
|
+
utils.getType(type) === "AsyncFunction"
|
16
|
+
) {
|
17
|
+
callback = type;
|
18
|
+
type = "inbox"; //default to inbox
|
19
|
+
} else if (utils.getType(type) !== "String") {
|
20
|
+
throw {
|
21
|
+
error:
|
22
|
+
"Please pass a String as a third argument. Your options are: inbox, pending, and archived"
|
23
|
+
};
|
24
|
+
} else {
|
25
|
+
throw {
|
26
|
+
error: "getThreadList: need callback"
|
27
|
+
};
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
if (type === "archived") {
|
32
|
+
type = "action:archived";
|
33
|
+
} else if (type !== "inbox" && type !== "pending" && type !== "other") {
|
34
|
+
throw {
|
35
|
+
error:
|
36
|
+
"type can only be one of the following: inbox, pending, archived, other"
|
37
|
+
};
|
38
|
+
}
|
39
|
+
|
40
|
+
if (end <= start) end = start + 20;
|
41
|
+
|
42
|
+
var form = {
|
43
|
+
client: "mercury"
|
44
|
+
};
|
45
|
+
|
46
|
+
form[type + "[offset]"] = start;
|
47
|
+
form[type + "[limit]"] = end - start;
|
48
|
+
|
49
|
+
if (ctx.globalOptions.pageID) {
|
50
|
+
form.request_user_id = ctx.globalOptions.pageID;
|
51
|
+
}
|
52
|
+
|
53
|
+
defaultFuncs
|
54
|
+
.post(
|
55
|
+
"https://www.facebook.com/ajax/mercury/threadlist_info.php",
|
56
|
+
ctx.jar,
|
57
|
+
form
|
58
|
+
)
|
59
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
60
|
+
.then(function(resData) {
|
61
|
+
if (resData.error) {
|
62
|
+
throw resData;
|
63
|
+
}
|
64
|
+
log.verbose("getThreadList", JSON.stringify(resData.payload.threads));
|
65
|
+
return callback(
|
66
|
+
null,
|
67
|
+
(resData.payload.threads || []).map(utils.formatThread)
|
68
|
+
);
|
69
|
+
})
|
70
|
+
.catch(function(err) {
|
71
|
+
log.error("getThreadList", err);
|
72
|
+
return callback(err);
|
73
|
+
});
|
74
|
+
};
|
75
|
+
};
|
package/alice/gcolor.js
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
module.exports = function(defaultFuncs, bot, ctx) {
|
4
|
+
// Currently the only colors that can be passed to api.changeThreadColor(); may change if Facebook adds more
|
5
|
+
return {
|
6
|
+
MessengerBlue: null,
|
7
|
+
Viking: "#44bec7",
|
8
|
+
GoldenPoppy: "#ffc300",
|
9
|
+
RadicalRed: "#fa3c4c",
|
10
|
+
Shocking: "#d696bb",
|
11
|
+
PictonBlue: "#6699cc",
|
12
|
+
FreeSpeechGreen: "#13cf13",
|
13
|
+
Pumpkin: "#ff7e29",
|
14
|
+
LightCoral: "#e68585",
|
15
|
+
MediumSlateBlue: "#7646ff",
|
16
|
+
DeepSkyBlue: "#20cef5",
|
17
|
+
Fern: "#67b868",
|
18
|
+
Cameo: "#d4a88c",
|
19
|
+
BrilliantRose: "#ff5ca1",
|
20
|
+
BilobaFlower: "#a695c7"
|
21
|
+
};
|
22
|
+
};
|
@@ -0,0 +1,39 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
|
5
|
+
module.exports = function(defaultFuncs, bot, ctx) {
|
6
|
+
return function searchForThread(name, callback) {
|
7
|
+
if (!callback) {
|
8
|
+
throw { error: "searchForThread: need callback" };
|
9
|
+
}
|
10
|
+
|
11
|
+
var tmpForm = {
|
12
|
+
client: "web_messenger",
|
13
|
+
query: name,
|
14
|
+
offset: 0,
|
15
|
+
limit: 21,
|
16
|
+
index: "fbid"
|
17
|
+
};
|
18
|
+
|
19
|
+
defaultFuncs
|
20
|
+
.post(
|
21
|
+
"https://www.facebook.com/ajax/mercury/search_threads.php",
|
22
|
+
ctx.jar,
|
23
|
+
tmpForm
|
24
|
+
)
|
25
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
26
|
+
.then(function(resData) {
|
27
|
+
if (resData.error) {
|
28
|
+
throw resData;
|
29
|
+
}
|
30
|
+
if (!resData.payload.mercury_payload.threads) {
|
31
|
+
return callback({ error: "Could not find thread `" + name + "`." });
|
32
|
+
}
|
33
|
+
return callback(
|
34
|
+
null,
|
35
|
+
resData.payload.mercury_payload.threads.map(utils.formatThread)
|
36
|
+
);
|
37
|
+
});
|
38
|
+
};
|
39
|
+
};
|