From 5f9c357a1506859f1555659ac33e6d08a68cfb53 Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Sun, 9 Dec 2018 01:07:33 +0100 Subject: [PATCH] Fixed graphql and added method for replying on quick replies --- fbchat/client.py | 13 +++++++++++++ fbchat/graphql.py | 22 +++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 3b6a7a5..32c72b2 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -1130,6 +1130,19 @@ class Client(object): data['specific_to_list[0]'] = "fbid:{}".format(thread_id) return self._doSendRequest(data) + def quickReply(self, quick_reply, thread_id=None, thread_type=None): + """ + Replies to a chosen quick reply + + :param thread_id: User/Group ID to send to. See :ref:`intro_threads` + :param thread_type: See :ref:`intro_threads` + :type thread_type: models.ThreadType + :return: :ref:`Message ID ` of the sent message + :raises: FBchatException if request failed + """ + quick_reply.is_response = True + return self.send(Message(text=quick_reply.title, quick_replies=[quick_reply])) + def _upload(self, files): """ Uploads files to Facebook diff --git a/fbchat/graphql.py b/fbchat/graphql.py index 066ee31..397448b 100644 --- a/fbchat/graphql.py +++ b/fbchat/graphql.py @@ -194,13 +194,21 @@ def graphql_to_plan(a): return rtn def graphql_to_quick_reply(q, is_response=False): - rtn = QuickReply( - title=q.get('title'), - image_url=q.get('image_url'), - payload=q.get('payload'), - data=q.get('data'), - is_response=is_response, - ) + data = dict() + if q.get('title') is not None: data["title"] = q["title"] + if q.get('image_url') is not None: data["image_url"] = q["image_url"] + if q.get('payload') is not None: data["payload"] = q["payload"] + if q.get('data') is not None: data["data"] = q["data"] + data["is_response"] = is_response + _type = QuickReplyType(q.get('content_type').upper()) + if _type == QuickReplyType.TEXT: + rtn = QuickReplyText(**data) + elif _type == QuickReplyType.LOCATION: + rtn = QuickReplyLocation(**data) + elif _type == QuickReplyType.PHONE_NUMBER: + rtn = QuickReplyPhoneNumber(**data) + elif _type == QuickReplyType.EMAIL: + rtn = QuickReplyEmail(**data) return rtn def graphql_to_message(message):