From 26444104bedd795d26d1f017753186aa34d97dfd Mon Sep 17 00:00:00 2001 From: Sven Skender Date: Sat, 12 Nov 2016 19:49:07 +0100 Subject: [PATCH 1/4] Update client.py to kick chat participants remove_user_from_chat(threadID, userID) --- fbchat/client.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/fbchat/client.py b/fbchat/client.py index 777de09..95e1e80 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -39,6 +39,7 @@ StickyURL ="https://0-edge-chat.facebook.com/pull" PingURL ="https://0-channel-proxy-06-ash2.facebook.com/active_ping" UploadURL ="https://upload.facebook.com/ajax/mercury/upload.php" UserInfoURL ="https://www.facebook.com/chat/user_info/" +RemoveUserURL="https://www.facebook.com/chat/remove_participants/" class Client(object): """A client for the Facebook Chat (Messenger). @@ -574,6 +575,24 @@ class Client(object): return full_data + def remove_user_from_chat(self, threadID, userID): + """Remove user (userID) from group chat (threadID) + + :param threadID: group chat id + :param userID: user id to remove from chat + """ + + data = { + "uid" : userID, + "tid" : threadID + } + + r = self._post(RemoveUserURL, data) + + self._console(r) + self._console(data) + + return r.ok From 0f1bb94a7fe6a83cb4dafb6b373b8131bbc9945e Mon Sep 17 00:00:00 2001 From: Sven Skender Date: Sat, 10 Dec 2016 21:28:05 +0100 Subject: [PATCH 2/4] Update client.py --- fbchat/client.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/fbchat/client.py b/fbchat/client.py index 95e1e80..9513725 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -595,6 +595,52 @@ class Client(object): return r.ok + def changeThreadTitle(self, threadID, newTitle): + """Change title of a group conversation + + :param threadID: group chat id + :param newTitle: new group chat title + """ + + messageAndOTID = generateOfflineThreadingID() + timestamp = now() + date = datetime.now() + data = { + 'client' : self.client, + 'action_type' : 'ma-type:log-message', + 'author' : 'fbid:' + str(self.uid), + 'thread_id' : '', + 'author_email' : '', + 'coordinates' : '', + 'timestamp' : timestamp, + 'timestamp_absolute' : 'Today', + 'timestamp_relative' : str(date.hour) + ":" + str(date.minute).zfill(2), + 'timestamp_time_passed' : '0', + 'is_unread' : False, + 'is_cleared' : False, + 'is_forward' : False, + 'is_filtered_content' : False, + 'is_spoof_warning' : False, + 'source' : 'source:chat:web', + 'source_tags[0]' : 'source:chat', + 'status' : '0', + 'offline_threading_id' : messageAndOTID, + 'message_id' : messageAndOTID, + 'threading_id': generateMessageID(self.client_id), + 'manual_retry_cnt' : '0', + 'thread_fbid' : threadID, + 'log_message_data[name]' : newTitle, + 'log_message_type' : 'log:thread-name' + } + + r = self._post(SendURL, data) + + self._console(r) + self._console(data) + + return r.ok + + def on_message(self, mid, author_id, author_name, message, metadata): ''' From 932bde4f9f8871fcae111f7d076b32e727118f59 Mon Sep 17 00:00:00 2001 From: John Westhoff Date: Thu, 29 Dec 2016 13:12:17 -0500 Subject: [PATCH 3/4] Added support for group threds in getThreadInfo --- fbchat/client.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 777de09..8b07dce 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -326,21 +326,27 @@ class Client(object): # Strip the start and parse out the returned image_id return json.loads(r._content[9:])['payload']['metadata'][0]['image_id'] - def getThreadInfo(self, userID, start, end=None): + def getThreadInfo(self, userID, start, end=None, thread_type='user'): """Get the info of one Thread :param userID: ID of the user you want the messages from :param start: the start index of a thread :param end: (optional) the last index of a thread + :param thread_type: (optional) change from 'user' for group threads """ if not end: end = start + 20 if end <= start: end = start + end data = {} - data['messages[user_ids][%s][offset]'%userID] = start - data['messages[user_ids][%s][limit]'%userID] = end - data['messages[user_ids][%s][timestamp]'%userID] = now() + if thread_type == 'user': + key = 'user_ids' + else: + key = 'thread_fbids' + + data['messages[{}][{}][offset]'.format(key, userID)] = start + data['messages[{}][{}][limit]'.format(key, userID)] = end + data['messages[{}][{}][timestamp]'.format(key, userID)] = now() r = self._post(MessagesURL, query=data) if not r.ok or len(r.text) == 0: From 8400fd1be0ac7971bd4e86f3256f4421918818b6 Mon Sep 17 00:00:00 2001 From: "Bankde@hotmail.com" Date: Wed, 18 Jan 2017 19:43:38 +0700 Subject: [PATCH 4/4] Add logout feature --- fbchat/client.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fbchat/client.py b/fbchat/client.py index 777de09..245dcf5 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -39,6 +39,7 @@ StickyURL ="https://0-edge-chat.facebook.com/pull" PingURL ="https://0-channel-proxy-06-ash2.facebook.com/active_ping" UploadURL ="https://upload.facebook.com/ajax/mercury/upload.php" UserInfoURL ="https://www.facebook.com/chat/user_info/" +LogoutURL ="https://www.facebook.com/logout.php" class Client(object): """A client for the Facebook Chat (Messenger). @@ -159,6 +160,7 @@ class Client(object): r = self._get(BaseURL) soup = bs(r.text, "lxml") self.fb_dtsg = soup.find("input", {'name':'fb_dtsg'})['value'] + self.fb_h = soup.find("input", {'name':'h'})['value'] self._setttstamp() # Set default payload self.payloadDefault['__rev'] = int(r.text.split('"revision":',1)[1].split(",",1)[0]) @@ -187,6 +189,19 @@ class Client(object): else: return False + def logout(self, timeout=30): + data = {} + data['ref'] = "mb" + data['h'] = self.fb_h + payload=self._generatePayload(data) + r = self._session.get(LogoutURL, headers=self._header, params=payload, timeout=timeout) + # reset value + self.payloadDefault={} + self._session = requests.session() + self.req_counter = 1 + self.seq = "0" + return r + def listen(self): pass