Skip to content

Commit

Permalink
Enable dming haly (#163)
Browse files Browse the repository at this point in the history
* Enable dming haly

* refact

* another refact
  • Loading branch information
fedeq authored Nov 9, 2023
1 parent 72fc99e commit 78225f3
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/services/slack_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def no_bot_messages(message) -> bool:
def no_message_changed(event) -> bool:
return event.get("subtype") != "message_changed" and event.get("edited") is None

def is_direct_message(event) -> bool:
return event.get("channel_type") == "im"


#########################################
# Event Handlers
Expand All @@ -109,7 +112,7 @@ def handle_tokens_revoked(body, logger):
return

@slack_app.event(event={"type": re.compile("(app_mention)"), "subtype": None}, matchers=[no_bot_messages, no_message_changed])
def handle_app_mention(event, say):
def handle_message_to_bot(event, say):
channel = event.get("channel")
text = event.get("text")
thread_ts = event.get("thread_ts")
Expand Down Expand Up @@ -350,8 +353,12 @@ def handle_some_action(ack, body, logger):
logger.debug(body)

@slack_app.event("message")
def hande_message_events(body, logger):
threading.Thread(target=handle_semantic_search_update, args=[body]).start()
def hande_message_events(body, event, say, logger):
# DM's to haly
if is_direct_message(event) and no_message_changed(event):
return handle_message_to_bot(event, say)
else:
threading.Thread(target=handle_semantic_search_update, args=[body]).start()
logger.debug(body)

def handle_semantic_search_update(body):
Expand Down

0 comments on commit 78225f3

Please sign in to comment.