Skip to content
This repository was archived by the owner on Apr 13, 2026. It is now read-only.

Commit a093a96

Browse files
committed
Update slack_bot.py
1 parent cb06190 commit a093a96

1 file changed

Lines changed: 56 additions & 56 deletions

File tree

installer/slackbot/slack_bot.py

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -317,69 +317,69 @@ def process_events(client: SocketModeClient, req: SocketModeRequest):
317317
if event.get("type") != "message" or event.get("subtype") is not None:
318318
return
319319

320-
# Get channel type - check if it's a DM or the default channel
321-
channel = event.get("channel")
322-
channel_type = event.get("channel_type")
323-
324-
# Allow messages from default channel or DMs (im = direct message)
325-
is_dm = channel_type == "im"
326-
is_default_channel = channel == DEFAULT_CHANNEL
327-
328-
if not (is_dm or is_default_channel):
329-
return
330-
331-
msg_ts = event.get("ts")
332-
if msg_ts in processed_messages:
333-
print(f"Skipping already processed message: {msg_ts}")
334-
return
320+
# Get channel type - check if it's a DM or the default channel
321+
channel = event.get("channel")
322+
channel_type = event.get("channel_type")
323+
324+
# Allow messages from default channel or DMs (im = direct message)
325+
is_dm = channel_type == "im"
326+
is_default_channel = channel == DEFAULT_CHANNEL
327+
328+
if not (is_dm or is_default_channel):
329+
return
335330

336-
processed_messages.add(msg_ts)
337-
if len(processed_messages) > 1000:
338-
oldest_ts = sorted(processed_messages)[0]
339-
processed_messages.remove(oldest_ts)
331+
msg_ts = event.get("ts")
332+
if msg_ts in processed_messages:
333+
print(f"Skipping already processed message: {msg_ts}")
334+
return
340335

341-
user = event.get("user")
342-
bot_user_id = os.environ.get("SLACK_BOT_USER_ID", "U08P8KS8K25")
343-
if user == bot_user_id:
344-
print(f"Skipping message from bot itself ({bot_user_id}).")
345-
return
336+
processed_messages.add(msg_ts)
337+
if len(processed_messages) > 1000:
338+
oldest_ts = sorted(processed_messages)[0]
339+
processed_messages.remove(oldest_ts)
346340

347-
text = event.get("text", "").strip()
348-
if not text.startswith("!"):
349-
return
341+
user = event.get("user")
342+
bot_user_id = os.environ.get("SLACK_BOT_USER_ID", "U08P8KS8K25")
343+
if user == bot_user_id:
344+
print(f"Skipping message from bot itself ({bot_user_id}).")
345+
return
350346

351-
command_full = text[1:]
352-
command_parts = command_full.split()
353-
main_command = command_parts[0] if command_parts else ""
347+
text = event.get("text", "").strip()
348+
if not text.startswith("!"):
349+
return
354350

355-
print(
356-
f"Received command: '{command_full}' from user {user} "
357-
f"in {'DM' if is_dm else f'channel {channel}'}"
358-
)
351+
command_full = text[1:]
352+
command_parts = command_full.split()
353+
main_command = command_parts[0] if command_parts else ""
359354

360-
# Get thread_ts - use the message timestamp to create/reply to thread
361-
# For DMs, thread_ts is the same as msg_ts
362-
thread_ts = event.get("thread_ts") or msg_ts
363-
364-
# For DM responses, use the DM channel; otherwise use DEFAULT_CHANNEL
365-
response_channel = channel if is_dm else DEFAULT_CHANNEL
366-
367-
if main_command == "location":
368-
handle_location(user, thread_ts, response_channel)
369-
elif main_command == "testimage":
370-
handle_testimage(user, thread_ts, response_channel)
371-
elif main_command == "agent":
372-
handle_agent(user, command_full, thread_ts, timeout=120, channel=response_channel)
373-
elif main_command == "agent-debug":
374-
handle_agent(user, command_full, thread_ts, timeout=1200, channel=response_channel)
375-
elif main_command == "help":
376-
handle_help(user, thread_ts, response_channel)
377-
else:
378-
send_slack_message(
379-
response_channel,
380-
text=f"❓ <@{user}> Unknown command: `{text}`. Try `!help`.",
381-
thread_ts=thread_ts,
355+
print(
356+
f"Received command: '{command_full}' from user {user} "
357+
f"in {'DM' if is_dm else f'channel {channel}'}"
382358
)
359+
360+
# Get thread_ts - use the message timestamp to create/reply to thread
361+
# For DMs, thread_ts is the same as msg_ts
362+
thread_ts = event.get("thread_ts") or msg_ts
363+
364+
# For DM responses, use the DM channel; otherwise use DEFAULT_CHANNEL
365+
response_channel = channel if is_dm else DEFAULT_CHANNEL
366+
367+
if main_command == "location":
368+
handle_location(user, thread_ts, response_channel)
369+
elif main_command == "testimage":
370+
handle_testimage(user, thread_ts, response_channel)
371+
elif main_command == "agent":
372+
handle_agent(user, command_full, thread_ts, timeout=120, channel=response_channel)
373+
elif main_command == "agent-debug":
374+
handle_agent(user, command_full, thread_ts, timeout=1200, channel=response_channel)
375+
elif main_command == "help":
376+
handle_help(user, thread_ts, response_channel)
377+
else:
378+
send_slack_message(
379+
response_channel,
380+
text=f"❓ <@{user}> Unknown command: `{text}`. Try `!help`.",
381+
thread_ts=thread_ts,
382+
)
383383
except Exception as e:
384384
import traceback
385385
print(f"❌ Error processing event: {e}")

0 commit comments

Comments
 (0)