I read messages to a bot in python using:
messages = client.rtm_read()
for message in messages:
print(message)
But how do I know if this was a DM to the bot, or a message in a group chat that the bot belongs to? Right now, the above always prints dict of the format:
{'type': 'message', 'channel': 'XXX', 'user': 'YYY', 'text': 'some-message', 'ts': '1485331695.000024', 'team': 'XXX'}
That's for both DM or group chat.
Try this?
import time
while True:
messages = client.rtm_read()
if len(messages):
...
time.sleep(<seconds you prefer>)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.