Python SDK can listen to messages dynamically with def listen_messages. Under the hood the function listens for messages.new. Would it be possible to make a new message["event"] property that has the chats as a dict with the chat ID the key? The current implementation of chats is a list and you have to loop through every single message. Example from Agent Demo:
for message in status_toolkit.account.listen_messages():
content = None
for chat in message["event"]["chats"]:
latest_message: dict = chat.get("lastMessage", {})
if not latest_message:
continue
from_public_key = latest_message.get("from")
if from_public_key != PUBLIC_KEY:
continue
content = chat["lastMessage"]["text"]
Python for loops are notoriously slow. I have seen this pattern implemented in other RPC calls.
Related to:
Python SDK can listen to messages dynamically with
def listen_messages. Under the hood the function listens formessages.new. Would it be possible to make a newmessage["event"]property that has thechatsas adictwith the chat ID the key? The current implementation ofchatsis alistand you have to loop through every single message. Example from Agent Demo:Python
forloops are notoriously slow. I have seen this pattern implemented in other RPC calls.Related to: