Skip to content

Commit

Permalink
Upm 251 fix haly DMs and token revoked event handler (#168)
Browse files Browse the repository at this point in the history
* Fix haly dms

* Fix token revoked event handler
  • Loading branch information
fedeq authored Nov 17, 2023
1 parent dcef0be commit 8d238e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/services/api_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def revoke_token(team_id):
url = f"{BASE_URL}/api/slack/revoke_token"
headers = {"X-Shared-Secret": os.environ["API_SHARED_SECRET"]}
# make post request with team id and token as data
print("revoking tokens for team: " + str(team_id))
logging.debug("revoking tokens for team: " + str(team_id))
response = requests.post(
url=url,
headers=headers,
Expand Down
11 changes: 6 additions & 5 deletions src/services/slack_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ def is_direct_message(event) -> bool:
@slack_app.event("tokens_revoked")
def handle_tokens_revoked(body, logger):
team_id = body.get("team_id")
try:
revoke_token(team_id)
except Exception as error:
print(error)
if len(body.get("event").get("tokens").get("bot")) > 0:
try:
revoke_token(team_id)
except Exception as error:
logging.error(error, exc_info=True)
return

@slack_app.event(event={"type": re.compile("(app_mention)"), "subtype": None}, matchers=[no_bot_messages, no_message_changed])
Expand Down Expand Up @@ -355,7 +356,7 @@ def handle_some_action(ack, body, logger):
@slack_app.event("message")
def hande_message_events(body, event, say, logger):
# DM's to haly
if is_direct_message(event) and no_message_changed(event):
if is_direct_message(event) and no_message_changed(event) and event.get("bot_id") is None:
return handle_message_to_bot(event, say)
else:
threading.Thread(target=handle_semantic_search_update, args=[body]).start()
Expand Down

0 comments on commit 8d238e6

Please sign in to comment.