Add possibility to reply to messages

and to (partly) fetch the replied messages
This commit is contained in:
Kacper Ziubryniewicz
2019-03-23 21:26:43 +01:00
parent d7a5d00439
commit a3efa7702a
3 changed files with 16 additions and 7 deletions

View File

@@ -390,9 +390,9 @@ class Client(object):
if "home" in r.url: if "home" in r.url:
return r return r
del (data["approvals_code"]) del data["approvals_code"]
del (data["submit[Submit Code]"]) del data["submit[Submit Code]"]
del (data["codes_submitted"]) del data["codes_submitted"]
data["name_action_selected"] = "save_device" data["name_action_selected"] = "save_device"
data["submit[Continue]"] = "Continue" data["submit[Continue]"] = "Continue"
@@ -404,7 +404,7 @@ class Client(object):
if "home" in r.url: if "home" in r.url:
return r return r
del (data["name_action_selected"]) del data["name_action_selected"]
log.info( log.info(
"Starting Facebook checkup flow." "Starting Facebook checkup flow."
) # At this stage, we have dtsg, nh, submit[Continue] ) # At this stage, we have dtsg, nh, submit[Continue]
@@ -413,7 +413,7 @@ class Client(object):
if "home" in r.url: if "home" in r.url:
return r return r
del (data["submit[Continue]"]) del data["submit[Continue]"]
data["submit[This was me]"] = "This Was Me" data["submit[This was me]"] = "This Was Me"
log.info( log.info(
"Verifying login attempt." "Verifying login attempt."
@@ -423,7 +423,7 @@ class Client(object):
if "home" in r.url: if "home" in r.url:
return r return r
del (data["submit[This was me]"]) del data["submit[This was me]"]
data["submit[Continue]"] = "Continue" data["submit[Continue]"] = "Continue"
data["name_action_selected"] = "save_device" data["name_action_selected"] = "save_device"
log.info( log.info(
@@ -1084,7 +1084,7 @@ class Client(object):
j = self.graphql_request( j = self.graphql_request(
GraphQL( GraphQL(
doc_id="1386147188135407", doc_id="1860982147341344",
params={ params={
"id": thread_id, "id": thread_id,
"message_limit": limit, "message_limit": limit,
@@ -1379,6 +1379,9 @@ class Client(object):
xmd["quick_replies"] = xmd["quick_replies"][0] xmd["quick_replies"] = xmd["quick_replies"][0]
data["platform_xmd"] = json.dumps(xmd) data["platform_xmd"] = json.dumps(xmd)
if message.reply_to_id:
data["replied_to_message_id"] = message.reply_to_id
return data return data
def _doSendRequest(self, data, get_thread_id=False): def _doSendRequest(self, data, get_thread_id=False):

View File

@@ -401,6 +401,8 @@ def graphql_to_message(message):
rtn.unsent = True rtn.unsent = True
elif attachment: elif attachment:
rtn.attachments.append(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 return rtn

View File

@@ -68,6 +68,10 @@ class Message(object):
quick_replies = attr.ib(factory=list, converter=lambda x: [] if x is None else x) quick_replies = attr.ib(factory=list, converter=lambda x: [] if x is None else x)
#: Whether the message is unsent (deleted for everyone) #: Whether the message is unsent (deleted for everyone)
unsent = attr.ib(False, init=False) 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 @classmethod
def formatMentions(cls, text, *args, **kwargs): def formatMentions(cls, text, *args, **kwargs):