From c95544dcb04b21c74a11ddf24cc69ade308c7072 Mon Sep 17 00:00:00 2001 From: Dainius Date: Tue, 16 May 2017 19:35:00 +0300 Subject: [PATCH] add typing indicator --- fbchat/client.py | 20 ++++++++++++++++++++ fbchat/models.py | 2 +- fbchat/utils.py | 4 +++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index b0f8984..9a4e32c 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -821,6 +821,26 @@ class Client(object): r = self._post(ReqUrl.MESSAGE_REACTION + "/?" + parse.urlencode(full_data)) return r.ok + def setTypingStatus(self, status, thread_id=None, thread_type=None): + # type: (TypingStatus, str, ThreadType) -> bool + """ + Sets users typing status. + + :param status: typing or not typing + :param thread_id: user/group chat ID + :return: True if status changed + """ + thread_id, thread_type = self._setThread(thread_id, None) + + data = { + "typ": status.value, + "thread": thread_id, + "to": thread_id if thread_type == ThreadType.USER else "", + "source": "mercury-chat" + } + + r = self._post(ReqUrl.TYPING, data) + return r.ok """ END SEND METHODS diff --git a/fbchat/models.py b/fbchat/models.py index e704690..68d0daf 100644 --- a/fbchat/models.py +++ b/fbchat/models.py @@ -69,7 +69,7 @@ class ThreadType(Enum): GROUP = 2 class TypingStatus(Enum): - DELETED = 0 + STOPPED = 0 TYPING = 1 class EmojiSize(Enum): diff --git a/fbchat/utils.py b/fbchat/utils.py index 212910f..89d927a 100644 --- a/fbchat/utils.py +++ b/fbchat/utils.py @@ -3,7 +3,8 @@ import json from time import time from random import random import warnings -from enum import Enum +from .models import * + USER_AGENTS = [ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/601.1.10 (KHTML, like Gecko) Version/8.0.5 Safari/601.1.10", @@ -51,6 +52,7 @@ class ReqUrl: CHECKPOINT = "https://m.facebook.com/login/checkpoint/" CHAT_COLOR = "https://www.facebook.com/messaging/save_thread_color/?source=thread_settings&dpr=1" MESSAGE_REACTION = "https://www.facebook.com/webgraphql/mutation" + TYPING = "https://www.facebook.com/ajax/messaging/typ.php" facebookEncoding = 'UTF-8'