Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Slack Deleted Message logged
from slackclient import SlackClient
from datetime import datetime
import time
slack_token = 'xoxb-token-goes-here'
sc = SlackClient(slack_token)
if sc.rtm_connect():
while True:
try:
events = sc.rtm_read()
for event in events:
if event['type'] == 'message' and 'subtype' in event and event['subtype'] == 'message_deleted':
prev_msg = event['previous_message']
user_info = sc.api_call("users.info", user=prev_msg['user'])
username = user_info['user']['name']
with open('/home/joe/www/slack/deleted.html', 'a') as lf:
lf.write("<p><b>{}</b> ({}) (deleted at <i>{}</i>): {}</p>\n".format(user_info['user']['real_name'], user_info['user']['name'], datetime.now(), prev_msg['text']))
time.sleep(0.05)
except Exception:
print("error occured, having a nap and then marching on")
time.sleep(1)
else:
print("Connection Failed")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.