Skip to content

Commit

Permalink
Add onPendingMessage (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastGimbus authored and madsmtm committed Jan 20, 2020
1 parent 9c81806 commit 12bbc00
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion fbchat/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2271,7 +2271,17 @@ def getThreadIdAndThreadType(msg_metadata):
elif delta_class == "ForcedFetch":
mid = delta.get("messageId")
if mid is None:
self.onUnknownMesssageType(msg=delta)
if delta["threadKey"] is not None:
# Looks like the whole delta is metadata in this case
thread_id, thread_type = getThreadIdAndThreadType(delta)
self.onPendingMessage(
thread_id=thread_id,
thread_type=thread_type,
metadata=delta,
msg=delta,
)
else:
self.onUnknownMesssageType(msg=delta)
else:
thread_id = str(delta["threadKey"]["threadFbId"])
fetch_info = self._forcedFetch(thread_id, mid)
Expand Down Expand Up @@ -2727,6 +2737,14 @@ def getThreadIdAndThreadType(msg_metadata):
msg=delta,
)

# New pending message
elif delta_class == "ThreadFolder" and delta.get("folder") == "FOLDER_PENDING":
# Looks like the whole delta is metadata in this case
thread_id, thread_type = getThreadIdAndThreadType(delta)
self.onPendingMessage(
thread_id=thread_id, thread_type=thread_type, metadata=delta, msg=delta
)

# Unknown message type
else:
self.onUnknownMesssageType(msg=delta)
Expand Down Expand Up @@ -2949,6 +2967,21 @@ def onMessage(
"""
log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name))

def onPendingMessage(
self, thread_id=None, thread_type=None, metadata=None, msg=None
):
"""Called when the client is listening, and somebody that isn't
connected with you on either Facebook or Messenger sends a message.
After that, you need to use fetchThreadList to actually read the message.
Args:
thread_id: Thread ID that the message was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the message was sent to. See :ref:`intro_threads`
metadata: Extra metadata about the message
msg: A full set of the data received
"""
log.info("New pending message from {}".format(thread_id))

def onColorChange(
self,
mid=None,
Expand Down

0 comments on commit 12bbc00

Please sign in to comment.