From a3efa7702a0b2f54722b78032f78bfa4c05ea610 Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Sat, 23 Mar 2019 21:26:43 +0100 Subject: [PATCH] Add possibility to reply to messages and to (partly) fetch the replied messages --- fbchat/_client.py | 17 ++++++++++------- fbchat/_graphql.py | 2 ++ fbchat/_message.py | 4 ++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/fbchat/_client.py b/fbchat/_client.py index a4a363d..3cd0c3b 100644 --- a/fbchat/_client.py +++ b/fbchat/_client.py @@ -390,9 +390,9 @@ class Client(object): if "home" in r.url: return r - del (data["approvals_code"]) - del (data["submit[Submit Code]"]) - del (data["codes_submitted"]) + del data["approvals_code"] + del data["submit[Submit Code]"] + del data["codes_submitted"] data["name_action_selected"] = "save_device" data["submit[Continue]"] = "Continue" @@ -404,7 +404,7 @@ class Client(object): if "home" in r.url: return r - del (data["name_action_selected"]) + del data["name_action_selected"] log.info( "Starting Facebook checkup flow." ) # At this stage, we have dtsg, nh, submit[Continue] @@ -413,7 +413,7 @@ class Client(object): if "home" in r.url: return r - del (data["submit[Continue]"]) + del data["submit[Continue]"] data["submit[This was me]"] = "This Was Me" log.info( "Verifying login attempt." @@ -423,7 +423,7 @@ class Client(object): if "home" in r.url: return r - del (data["submit[This was me]"]) + del data["submit[This was me]"] data["submit[Continue]"] = "Continue" data["name_action_selected"] = "save_device" log.info( @@ -1084,7 +1084,7 @@ class Client(object): j = self.graphql_request( GraphQL( - doc_id="1386147188135407", + doc_id="1860982147341344", params={ "id": thread_id, "message_limit": limit, @@ -1379,6 +1379,9 @@ class Client(object): xmd["quick_replies"] = xmd["quick_replies"][0] data["platform_xmd"] = json.dumps(xmd) + if message.reply_to_id: + data["replied_to_message_id"] = message.reply_to_id + return data def _doSendRequest(self, data, get_thread_id=False): diff --git a/fbchat/_graphql.py b/fbchat/_graphql.py index 4bf8cab..ea8c56a 100644 --- a/fbchat/_graphql.py +++ b/fbchat/_graphql.py @@ -401,6 +401,8 @@ def graphql_to_message(message): rtn.unsent = True elif attachment: rtn.attachments.append(attachment) + if message.get("replied_to_message") is not None: + rtn.replied_to = graphql_to_message(message["replied_to_message"]["message"]) return rtn diff --git a/fbchat/_message.py b/fbchat/_message.py index 3f6f03d..3203778 100644 --- a/fbchat/_message.py +++ b/fbchat/_message.py @@ -68,6 +68,10 @@ class Message(object): quick_replies = attr.ib(factory=list, converter=lambda x: [] if x is None else x) #: Whether the message is unsent (deleted for everyone) unsent = attr.ib(False, init=False) + #: Message ID you want to reply to + reply_to_id = attr.ib(None) + #: Replied message + replied_to = attr.ib(None, init=False) @classmethod def formatMentions(cls, text, *args, **kwargs):