Skip to content

Commit

Permalink
Merge pull request #4 from nalbam/main
Browse files Browse the repository at this point in the history
check bot_id
  • Loading branch information
nalbam authored Jun 5, 2024
2 parents 3938733 + ea92fe2 commit 34517e0
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
ANTHROPIC_TOKENS = int(os.environ.get("ANTHROPIC_TOKENS", 1024))

# Set up the allowed channel ID
ALLOWED_CHANNEL_IDS = os.environ.get("ALLOWED_CHANNEL_IDS", "AAA,CCC,EEE,GGG")
ALLOWED_CHANNEL_IDS = os.environ.get("ALLOWED_CHANNEL_IDS", "None")

ENABLE_IMAGE = os.environ.get("ENABLE_IMAGE", "False")

Expand Down Expand Up @@ -333,6 +333,8 @@ def conversation(say: Say, thread_ts, content, channel, user, client_msg_id):
except Exception as e:
print("conversation: Error: {}".format(e))

chat_update(channel, latest_ts, f"```{e}```")


# Get image from URL
def get_image_from_url(image_url, token=None):
Expand Down Expand Up @@ -399,15 +401,17 @@ def handle_mention(body: dict, say: Say):

event = body["event"]

if "bot_id" in event: # Ignore messages from the bot itself
if "bot_id" in event and event["bot_id"] == bot_id:
# Ignore messages from the bot itself
return

channel = event["channel"]

allowed_channel_ids = ALLOWED_CHANNEL_IDS.split(",")
if channel not in allowed_channel_ids:
# say("Sorry, I'm not allowed to respond in this channel.")
return
if ALLOWED_CHANNEL_IDS != "None":
allowed_channel_ids = ALLOWED_CHANNEL_IDS.split(",")
if channel not in allowed_channel_ids:
# say("Sorry, I'm not allowed to respond in this channel.")
return

thread_ts = event["thread_ts"] if "thread_ts" in event else event["ts"]
user = event["user"]
Expand All @@ -427,7 +431,8 @@ def handle_message(body: dict, say: Say):

event = body["event"]

if "bot_id" in event: # Ignore messages from the bot itself
if "bot_id" in event:
# Ignore messages from the bot itself
return

channel = event["channel"]
Expand Down

0 comments on commit 34517e0

Please sign in to comment.