Spaces:
Runtime error
Runtime error
feat: remove reactions from messages of slack thread.
Browse files
app.py
CHANGED
|
@@ -4,6 +4,9 @@ import re
|
|
| 4 |
from slack_sdk import WebClient
|
| 5 |
from slack_sdk.errors import SlackApiError
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def remove_urls(text):
|
| 9 |
url_pattern = re.compile(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+')
|
|
@@ -19,7 +22,7 @@ def fetch_text_from_slack_thread(bot_token, thread_link):
|
|
| 19 |
response = client.conversations_replies(channel=channel_id, ts=thread_ts)
|
| 20 |
|
| 21 |
messages = response["messages"]
|
| 22 |
-
thread_text = " ".join([remove_urls(message["text"]) for message in messages])
|
| 23 |
|
| 24 |
return thread_text
|
| 25 |
except SlackApiError as e:
|
|
|
|
| 4 |
from slack_sdk import WebClient
|
| 5 |
from slack_sdk.errors import SlackApiError
|
| 6 |
|
| 7 |
+
def remove_reactions(text):
|
| 8 |
+
reaction_pattern = re.compile(r':\w+:')
|
| 9 |
+
return reaction_pattern.sub('', text)
|
| 10 |
|
| 11 |
def remove_urls(text):
|
| 12 |
url_pattern = re.compile(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+')
|
|
|
|
| 22 |
response = client.conversations_replies(channel=channel_id, ts=thread_ts)
|
| 23 |
|
| 24 |
messages = response["messages"]
|
| 25 |
+
thread_text = " ".join([remove_urls(remove_reactions(message["text"])) for message in messages])
|
| 26 |
|
| 27 |
return thread_text
|
| 28 |
except SlackApiError as e:
|