/// <summary> /// Get thread list of your facebook account /// </summary> /// <param name="limit">Max.number of threads to retrieve. Capped at 20</param> /// <param name="thread_location">models.ThreadLocation: INBOX, PENDING, ARCHIVED or OTHER</param> /// <param name="before">A unix timestamp, indicating from which point to retrieve messages</param> public async Task <List <FB_Thread> > fetchThreadList(int limit = 20, string thread_location = ThreadLocation.INBOX, string before = null) { /* * Get thread list of your facebook account * :param limit: Max.number of threads to retrieve.Capped at 20 * :param thread_location: models.ThreadLocation: INBOX, PENDING, ARCHIVED or OTHER * :param before: A timestamp (in milliseconds), indicating from which point to retrieve threads * :type limit: int * :return: `models.Thread` objects * :rtype: list * :raises: Exception if request failed */ if (limit > 20 || limit < 1) { throw new FBchatUserError("`limit` should be between 1 and 20"); } var dict = new Dictionary <string, object>() { { "limit", limit }, { "tags", new string[] { thread_location } }, { "before", before }, { "includeDeliveryReceipts", true }, { "includeSeqID", false } }; var j = await this._session.graphql_request(GraphQL.from_doc_id(doc_id: "1349387578499440", param: dict)); var rtn = new List <FB_Thread>(); foreach (var node in j.get("viewer")?.get("message_threads")?.get("nodes")) { var _type = node.get("thread_type")?.Value <string>(); if (_type == "GROUP") { rtn.Add(FB_Group._from_graphql(_session, node)); } else if (_type == "ONE_TO_ONE") { rtn.Add(FB_User._from_thread_fetch(_session, node)); } else if (_type == "MARKETPLACE") { rtn.Add(FB_Marketplace._from_graphql(_session, node)); } else { throw new FBchatException(string.Format("Unknown thread type: {0}", _type)); } } return(rtn); }
internal async Task <JToken> _forcedFetch(string mid) { var param = new Dictionary <string, object>() { { "thread_and_message_id", new Dictionary <string, object>() { { "thread_id", this.uid }, { "message_id", mid } } } }; return(await this.session.graphql_request(GraphQL.from_doc_id("1768656253222505", param))); }
private async Task _usersApproval(List <string> user_ids, bool approve) { var uuser_ids = Utils.require_list <string>(user_ids).ToList(); var data = new Dictionary <string, object>() { { "client_mutation_id", "0" }, { "actor_id", this.session.user.uid }, { "thread_fbid", this.uid }, { "user_ids", user_ids }, { "response", approve ? "ACCEPT" : "DENY" }, { "surface", "ADMIN_MODEL_APPROVAL_CENTER" } }; var j = await this.session.graphql_request( GraphQL.from_doc_id("1574519202665847", new Dictionary <string, object>() { { "data", data } }) ); }
private async Task <int> _fetch_mqtt_sequence_id() { // Get the sync sequence ID used for the /messenger_sync_create_queue call later. // This is the same request as fetch_thread_list, but with includeSeqID=true var j = await this._session.graphql_request(GraphQL.from_doc_id("1349387578499440", new Dictionary <string, object> { { "limit", 0 }, { "tags", new string[] { ThreadLocation.INBOX } }, { "before", null }, { "includeDeliveryReceipts", false }, { "includeSeqID", true }, })); var sequence_id = j.get("viewer")?.get("message_threads")?.get("sync_sequence_id")?.Value <int>(); if (sequence_id == null) { throw new FBchatException("Could not fetch sequence id"); } return((int)sequence_id); }
/// <summary> /// Get threads' info from IDs, unordered /// </summary> /// <param name="thread_ids">One or more thread ID(s) to query</param> /// <returns>A dictionary of FB_Thread objects, labeled by their ID</returns> public async Task <Dictionary <string, FB_Thread> > fetchThreadInfo(List <string> thread_ids) { /* * Get threads" info from IDs, unordered * ..warning:: * Sends two requests if users or pages are present, to fetch all available info! * :param thread_ids: One or more thread ID(s) to query * :return: `models.Thread` objects, labeled by their ID * :rtype: dict * :raises: Exception if request failed */ var queries = new List <GraphQL>(); foreach (var thread_id in thread_ids) { queries.Add(GraphQL.from_doc_id(doc_id: "2147762685294928", param: new Dictionary <string, object>() { { "id", thread_id }, { "message_limit", 0.ToString() }, { "load_messages", false.ToString() }, { "load_read_receipts", false.ToString() }, { "before", null } })); } var j = await this._session.graphql_requests(queries); foreach (var obj in j.Select((x, index) => new { entry = x, i = index })) { if (obj.entry.get("message_thread") == null) { // If you don't have an existing thread with this person, attempt to retrieve user data anyways j[obj.i]["message_thread"] = new JObject( new JProperty("thread_key", new JObject( new JProperty("other_user_id", thread_ids[obj.i]))), new JProperty("thread_type", "ONE_TO_ONE")); } } var pages_and_user_ids = j.Where(k => k.get("message_thread")?.get("thread_type")?.Value <string>()?.Equals("ONE_TO_ONE") ?? false) .Select(k => k.get("message_thread")?.get("thread_key")?.get("other_user_id")?.Value <string>()); JObject pages_and_users = null; if (pages_and_user_ids.Count() != 0) { pages_and_users = await this._fetchInfo(pages_and_user_ids.ToList()); } var rtn = new Dictionary <string, FB_Thread>(); foreach (var obj in j.Select((x, index) => new { entry = x, i = index })) { var entry = obj.entry.get("message_thread"); if (entry.get("thread_type")?.Value <string>()?.Equals("GROUP") ?? false) { var _id = entry.get("thread_key")?.get("thread_fbid").Value <string>(); rtn[_id] = FB_Group._from_graphql(_session, entry); } if (entry.get("thread_type")?.Value <string>()?.Equals("MARKETPLACE") ?? false) { var _id = entry.get("thread_key")?.get("thread_fbid").Value <string>(); rtn[_id] = FB_Marketplace._from_graphql(_session, entry); } else if (entry.get("thread_type")?.Value <string>()?.Equals("ONE_TO_ONE") ?? false) { var _id = entry.get("thread_key")?.get("other_user_id")?.Value <string>(); if (pages_and_users[_id] == null) { throw new FBchatException(string.Format("Could not fetch thread {0}", _id)); } foreach (var elem in pages_and_users[_id]) { entry[((JProperty)elem).Name] = ((JProperty)elem).Value; } if (entry.get("first_name") != null) { rtn[_id] = FB_User._from_graphql(_session, entry); } else { rtn[_id] = FB_Page._from_graphql(_session, entry); } } else { throw new FBchatException(string.Format("{0} had an unknown thread type: {1}", thread_ids[obj.i], entry)); } } return(rtn); }