Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def _handle_standard_answers(

restate_question_blocks = get_restate_blocks(
msg=query_msg.message,
is_bot_msg=message_info.is_bot_msg,
is_slash_command=message_info.is_slash_command,
)

answer_blocks = build_standard_answer_blocks(
Expand Down
8 changes: 4 additions & 4 deletions backend/onyx/onyxbot/slack/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _build_ephemeral_publication_block(
email=message_info.email,
sender_id=message_info.sender_id,
thread_messages=[],
is_bot_msg=message_info.is_bot_msg,
is_slash_command=message_info.is_slash_command,
is_bot_dm=message_info.is_bot_dm,
thread_to_respond=respond_ts,
)
Expand Down Expand Up @@ -225,10 +225,10 @@ def _build_doc_feedback_block(

def get_restate_blocks(
msg: str,
is_bot_msg: bool,
is_slash_command: bool,
) -> list[Block]:
# Only the slash command needs this context because the user doesn't see their own input
if not is_bot_msg:
if not is_slash_command:
return []

return [
Expand Down Expand Up @@ -576,7 +576,7 @@ def build_slack_response_blocks(
# If called with the OnyxBot slash command, the question is lost so we have to reshow it
if not skip_restated_question:
restate_question_block = get_restate_blocks(
message_info.thread_messages[-1].message, message_info.is_bot_msg
message_info.thread_messages[-1].message, message_info.is_slash_command
)
else:
restate_question_block = []
Expand Down
2 changes: 1 addition & 1 deletion backend/onyx/onyxbot/slack/handlers/handle_buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def handle_generate_answer_button(
sender_id=user_id or None,
email=email or None,
bypass_filters=True,
is_bot_msg=False,
is_slash_command=False,
is_bot_dm=False,
),
slack_channel_config=slack_channel_config,
Expand Down
8 changes: 4 additions & 4 deletions backend/onyx/onyxbot/slack/handlers/handle_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


def send_msg_ack_to_user(details: SlackMessageInfo, client: WebClient) -> None:
if details.is_bot_msg and details.sender_id:
if details.is_slash_command and details.sender_id:
respond_in_thread_or_channel(
client=client,
channel=details.channel_to_respond,
Expand Down Expand Up @@ -124,11 +124,11 @@ def handle_message(
messages = message_info.thread_messages
sender_id = message_info.sender_id
bypass_filters = message_info.bypass_filters
is_bot_msg = message_info.is_bot_msg
is_slash_command = message_info.is_slash_command
is_bot_dm = message_info.is_bot_dm

action = "slack_message"
if is_bot_msg:
if is_slash_command:
action = "slack_slash_message"
elif bypass_filters:
action = "slack_tag_message"
Expand Down Expand Up @@ -197,7 +197,7 @@ def handle_message(

# If configured to respond to team members only, then cannot be used with a /OnyxBot command
# which would just respond to the sender
if send_to and is_bot_msg:
if send_to and is_slash_command:
if sender_id:
respond_in_thread_or_channel(
client=client,
Expand Down
23 changes: 12 additions & 11 deletions backend/onyx/onyxbot/slack/handlers/handle_regular_answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ def handle_regular_answer(
messages = message_info.thread_messages

message_ts_to_respond_to = message_info.msg_to_respond
is_bot_msg = message_info.is_bot_msg
is_slash_command = message_info.is_slash_command

# Capture whether response mode for channel is ephemeral. Even if the channel is set
# to respond with an ephemeral message, we still send as non-ephemeral if
# the message is a dm with the Onyx bot.
send_as_ephemeral = (
slack_channel_config.channel_config.get("is_ephemeral", False)
and not message_info.is_bot_dm
)
or message_info.is_slash_command
) and not message_info.is_bot_dm

# If the channel mis configured to respond with an ephemeral message,
# or the message is a dm to the Onyx bot, we should use the proper onyx user from the email.
Expand Down Expand Up @@ -164,7 +164,7 @@ def handle_regular_answer(
# in an attached document set were available to all users in the channel.)
bypass_acl = False

if not message_ts_to_respond_to and not is_bot_msg:
if not message_ts_to_respond_to and not is_slash_command:
# if the message is not "/onyx" command, then it should have a message ts to respond to
raise RuntimeError(
"No message timestamp to respond to in `handle_message`. This should never happen."
Expand Down Expand Up @@ -316,13 +316,14 @@ def _get_slack_answer(
return True

# Got an answer at this point, can remove reaction and give results
update_emote_react(
emoji=DANSWER_REACT_EMOJI,
channel=message_info.channel_to_respond,
message_ts=message_info.msg_to_respond,
remove=True,
client=client,
)
if not is_slash_command: # Slash commands don't have reactions
update_emote_react(
emoji=DANSWER_REACT_EMOJI,
channel=message_info.channel_to_respond,
message_ts=message_info.msg_to_respond,
remove=True,
client=client,
)

if answer.answer_valid is False:
logger.notice(
Expand Down
7 changes: 4 additions & 3 deletions backend/onyx/onyxbot/slack/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,12 +876,13 @@ def build_request_details(
sender_id=sender_id,
email=email,
bypass_filters=tagged,
is_bot_msg=False,
is_slash_command=False,
is_bot_dm=event.get("channel_type") == "im",
)

elif req.type == "slash_commands":
channel = req.payload["channel_id"]
channel_name = req.payload["channel_name"]
msg = req.payload["text"]
sender = req.payload["user_id"]
expert_info = expert_info_from_slack_id(
Expand All @@ -899,8 +900,8 @@ def build_request_details(
sender_id=sender,
email=email,
bypass_filters=True,
is_bot_msg=True,
is_bot_dm=False,
is_slash_command=True,
is_bot_dm=channel_name == "directmessage",
)

raise RuntimeError("Programming fault, this should never happen.")
Expand Down
4 changes: 2 additions & 2 deletions backend/onyx/onyxbot/slack/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SlackMessageInfo(BaseModel):
sender_id: str | None
email: str | None
bypass_filters: bool # User has tagged @OnyxBot
is_bot_msg: bool # User is using /OnyxBot
is_slash_command: bool # User is using /OnyxBot
is_bot_dm: bool # User is direct messaging to OnyxBot


Expand All @@ -25,7 +25,7 @@ class ActionValuesEphemeralMessageMessageInfo(BaseModel):
email: str | None
sender_id: str | None
thread_messages: list[ThreadMessage] | None
is_bot_msg: bool | None
is_slash_command: bool | None
is_bot_dm: bool | None
thread_to_respond: str | None

Expand Down