@@ -176,6 +176,7 @@ class Client(object):
|
|||||||
|
|
||||||
:param name: name of a person
|
:param name: name of a person
|
||||||
"""
|
"""
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
'value' : name.lower(),
|
'value' : name.lower(),
|
||||||
'viewer' : self.uid,
|
'viewer' : self.uid,
|
||||||
@@ -230,6 +231,7 @@ class Client(object):
|
|||||||
'message_batch[0][thread_fbid]' : thread_id,
|
'message_batch[0][thread_fbid]' : thread_id,
|
||||||
'message_batch[0][has_attachment]' : False
|
'message_batch[0][has_attachment]' : False
|
||||||
}
|
}
|
||||||
|
|
||||||
if like:
|
if like:
|
||||||
try:
|
try:
|
||||||
sticker = LIKES[like.lower()]
|
sticker = LIKES[like.lower()]
|
||||||
@@ -237,9 +239,11 @@ class Client(object):
|
|||||||
# if user doesn't enter l or m or s, then use the large one
|
# if user doesn't enter l or m or s, then use the large one
|
||||||
sticker = LIKES['l']
|
sticker = LIKES['l']
|
||||||
data["message_batch[0][sticker_id]"] = sticker
|
data["message_batch[0][sticker_id]"] = sticker
|
||||||
|
|
||||||
r = self._post(SendURL, data)
|
r = self._post(SendURL, data)
|
||||||
return r.ok
|
return r.ok
|
||||||
|
|
||||||
|
|
||||||
def getThreadInfo(self, userID, start, end=None):
|
def getThreadInfo(self, userID, start, end=None):
|
||||||
"""Get the info of one Thread
|
"""Get the info of one Thread
|
||||||
|
|
||||||
@@ -247,6 +251,7 @@ class Client(object):
|
|||||||
:param start: the start index of a thread
|
:param start: the start index of a thread
|
||||||
:param end: (optional) the last index of a thread
|
:param end: (optional) the last index of a thread
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not end: end = start + 20
|
if not end: end = start + 20
|
||||||
if end <= start: end = start + end
|
if end <= start: end = start + end
|
||||||
|
|
||||||
@@ -262,6 +267,7 @@ class Client(object):
|
|||||||
j = get_json(r.text)
|
j = get_json(r.text)
|
||||||
if not j['payload']:
|
if not j['payload']:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
messages = []
|
messages = []
|
||||||
for message in j['payload']['actions']:
|
for message in j['payload']['actions']:
|
||||||
messages.append(Message(**message))
|
messages.append(Message(**message))
|
||||||
@@ -274,6 +280,7 @@ class Client(object):
|
|||||||
:param start: the start index of a thread
|
:param start: the start index of a thread
|
||||||
:param end: (optional) the last index of a thread
|
:param end: (optional) the last index of a thread
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not end: end = start + 20
|
if not end: end = start + 20
|
||||||
if end <= start: end = start + end
|
if end <= start: end = start + end
|
||||||
|
|
||||||
@@ -320,6 +327,7 @@ class Client(object):
|
|||||||
'last_action_timestamp': now() - 60*1000
|
'last_action_timestamp': now() - 60*1000
|
||||||
#'last_action_timestamp': 0
|
#'last_action_timestamp': 0
|
||||||
}
|
}
|
||||||
|
|
||||||
r = self._post(ThreadSyncURL, form)
|
r = self._post(ThreadSyncURL, form)
|
||||||
if not r.ok or len(r.text) == 0:
|
if not r.ok or len(r.text) == 0:
|
||||||
return None
|
return None
|
||||||
@@ -327,7 +335,8 @@ class Client(object):
|
|||||||
j = get_json(r.text)
|
j = get_json(r.text)
|
||||||
result = {
|
result = {
|
||||||
"message_counts": j['payload']['message_counts'],
|
"message_counts": j['payload']['message_counts'],
|
||||||
"unseen_threads": j['payload']['unseen_thread_ids']}
|
"unseen_threads": j['payload']['unseen_thread_ids']
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def markAsDelivered(self, userID, threadID):
|
def markAsDelivered(self, userID, threadID):
|
||||||
@@ -339,11 +348,13 @@ class Client(object):
|
|||||||
def markAsRead(self, userID):
|
def markAsRead(self, userID):
|
||||||
data = {
|
data = {
|
||||||
"watermarkTimestamp": now(),
|
"watermarkTimestamp": now(),
|
||||||
"shouldSendReadReceipt": True}
|
"shouldSendReadReceipt": True
|
||||||
|
}
|
||||||
data["ids[%s]"%userID] = True
|
data["ids[%s]"%userID] = True
|
||||||
r = self._post(ReadStatusURL, data)
|
r = self._post(ReadStatusURL, data)
|
||||||
return r.ok
|
return r.ok
|
||||||
|
|
||||||
|
|
||||||
def markAsSeen(self):
|
def markAsSeen(self):
|
||||||
r = self._post(MarkSeenURL, {"seen_timestamp": 0})
|
r = self._post(MarkSeenURL, {"seen_timestamp": 0})
|
||||||
return r.ok
|
return r.ok
|
||||||
@@ -368,6 +379,7 @@ class Client(object):
|
|||||||
Call pull api to get sticky and pool parameter,
|
Call pull api to get sticky and pool parameter,
|
||||||
newer api needs these parameter to work.
|
newer api needs these parameter to work.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
data = {"msgs_recv": 0}
|
data = {"msgs_recv": 0}
|
||||||
|
|
||||||
r = self._get(StickyURL, data)
|
r = self._get(StickyURL, data)
|
||||||
@@ -385,6 +397,7 @@ class Client(object):
|
|||||||
'''
|
'''
|
||||||
Call pull api with seq value to get message data.
|
Call pull api with seq value to get message data.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"msgs_recv": 0,
|
"msgs_recv": 0,
|
||||||
"sticky_token": sticky,
|
"sticky_token": sticky,
|
||||||
@@ -403,8 +416,8 @@ class Client(object):
|
|||||||
Get message and author name from content.
|
Get message and author name from content.
|
||||||
May contains multiple messages in the content.
|
May contains multiple messages in the content.
|
||||||
'''
|
'''
|
||||||
if 'ms' not in content:
|
|
||||||
return
|
if 'ms' not in content: return
|
||||||
for m in content['ms']:
|
for m in content['ms']:
|
||||||
try:
|
try:
|
||||||
if m['type'] in ['m_messaging', 'messaging']:
|
if m['type'] in ['m_messaging', 'messaging']:
|
||||||
@@ -433,6 +446,7 @@ class Client(object):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.on_message_error(e, m)
|
self.on_message_error(e, m)
|
||||||
|
|
||||||
|
|
||||||
def listen(self, markAlive=True):
|
def listen(self, markAlive=True):
|
||||||
self.listening = True
|
self.listening = True
|
||||||
sticky, pool = self._getSticky()
|
sticky, pool = self._getSticky()
|
||||||
@@ -453,23 +467,29 @@ class Client(object):
|
|||||||
except requests.exceptions.Timeout:
|
except requests.exceptions.Timeout:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def on_message(self, mid, author_id, author_name, message, metadata):
|
def on_message(self, mid, author_id, author_name, message, metadata):
|
||||||
self.markAsDelivered(author_id, mid)
|
self.markAsDelivered(author_id, mid)
|
||||||
self.markAsRead(author_id)
|
self.markAsRead(author_id)
|
||||||
print("%s said: %s"%(author_name, message))
|
print("%s said: %s"%(author_name, message))
|
||||||
|
|
||||||
|
|
||||||
def on_typing(self, author_id):
|
def on_typing(self, author_id):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def on_read(self, author, reader, time):
|
def on_read(self, author, reader, time):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def on_inbox(self, viewer, unseen, unread, other_unseen, other_unread, timestamp):
|
def on_inbox(self, viewer, unseen, unread, other_unseen, other_unread, timestamp):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def on_message_error(self, exception, message):
|
def on_message_error(self, exception, message):
|
||||||
print("Exception: ")
|
print("Exception: ")
|
||||||
print(exception)
|
print(exception)
|
||||||
|
|
||||||
|
|
||||||
def on_qprimer(self, timestamp):
|
def on_qprimer(self, timestamp):
|
||||||
pass
|
pass
|
||||||
|
Reference in New Issue
Block a user