Skip to content

Commit 59d9f97

Browse files
committed
rename confusing variable. fix slash message response in DMs
1 parent fcbe0a5 commit 59d9f97

File tree

7 files changed

+27
-25
lines changed

7 files changed

+27
-25
lines changed

backend/ee/onyx/onyxbot/slack/handlers/handle_standard_answers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def _handle_standard_answers(
206206

207207
restate_question_blocks = get_restate_blocks(
208208
msg=query_msg.message,
209-
is_bot_msg=message_info.is_bot_msg,
209+
is_slash_command=message_info.is_slash_command,
210210
)
211211

212212
answer_blocks = build_standard_answer_blocks(

backend/onyx/onyxbot/slack/blocks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def _build_ephemeral_publication_block(
151151
email=message_info.email,
152152
sender_id=message_info.sender_id,
153153
thread_messages=[],
154-
is_bot_msg=message_info.is_bot_msg,
154+
is_slash_command=message_info.is_slash_command,
155155
is_bot_dm=message_info.is_bot_dm,
156156
thread_to_respond=respond_ts,
157157
)
@@ -225,10 +225,10 @@ def _build_doc_feedback_block(
225225

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

234234
return [
@@ -576,7 +576,7 @@ def build_slack_response_blocks(
576576
# If called with the OnyxBot slash command, the question is lost so we have to reshow it
577577
if not skip_restated_question:
578578
restate_question_block = get_restate_blocks(
579-
message_info.thread_messages[-1].message, message_info.is_bot_msg
579+
message_info.thread_messages[-1].message, message_info.is_slash_command
580580
)
581581
else:
582582
restate_question_block = []

backend/onyx/onyxbot/slack/handlers/handle_buttons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def handle_generate_answer_button(
177177
sender_id=user_id or None,
178178
email=email or None,
179179
bypass_filters=True,
180-
is_bot_msg=False,
180+
is_slash_command=False,
181181
is_bot_dm=False,
182182
),
183183
slack_channel_config=slack_channel_config,

backend/onyx/onyxbot/slack/handlers/handle_message.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929

3030
def send_msg_ack_to_user(details: SlackMessageInfo, client: WebClient) -> None:
31-
if details.is_bot_msg and details.sender_id:
31+
if details.is_slash_command and details.sender_id:
3232
respond_in_thread_or_channel(
3333
client=client,
3434
channel=details.channel_to_respond,
@@ -124,11 +124,11 @@ def handle_message(
124124
messages = message_info.thread_messages
125125
sender_id = message_info.sender_id
126126
bypass_filters = message_info.bypass_filters
127-
is_bot_msg = message_info.is_bot_msg
127+
is_slash_command = message_info.is_slash_command
128128
is_bot_dm = message_info.is_bot_dm
129129

130130
action = "slack_message"
131-
if is_bot_msg:
131+
if is_slash_command:
132132
action = "slack_slash_message"
133133
elif bypass_filters:
134134
action = "slack_tag_message"
@@ -197,7 +197,7 @@ def handle_message(
197197

198198
# If configured to respond to team members only, then cannot be used with a /OnyxBot command
199199
# which would just respond to the sender
200-
if send_to and is_bot_msg:
200+
if send_to and is_slash_command:
201201
if sender_id:
202202
respond_in_thread_or_channel(
203203
client=client,

backend/onyx/onyxbot/slack/handlers/handle_regular_answer.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ def handle_regular_answer(
8181
messages = message_info.thread_messages
8282

8383
message_ts_to_respond_to = message_info.msg_to_respond
84-
is_bot_msg = message_info.is_bot_msg
84+
is_slash_command = message_info.is_slash_command
8585

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

9494
# If the channel mis configured to respond with an ephemeral message,
@@ -164,7 +164,7 @@ def handle_regular_answer(
164164
# in an attached document set were available to all users in the channel.)
165165
bypass_acl = False
166166

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

318318
# Got an answer at this point, can remove reaction and give results
319-
update_emote_react(
320-
emoji=DANSWER_REACT_EMOJI,
321-
channel=message_info.channel_to_respond,
322-
message_ts=message_info.msg_to_respond,
323-
remove=True,
324-
client=client,
325-
)
319+
if not is_slash_command: # Slash commands don't have reactions
320+
update_emote_react(
321+
emoji=DANSWER_REACT_EMOJI,
322+
channel=message_info.channel_to_respond,
323+
message_ts=message_info.msg_to_respond,
324+
remove=True,
325+
client=client,
326+
)
326327

327328
if answer.answer_valid is False:
328329
logger.notice(

backend/onyx/onyxbot/slack/listener.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -876,12 +876,13 @@ def build_request_details(
876876
sender_id=sender_id,
877877
email=email,
878878
bypass_filters=tagged,
879-
is_bot_msg=False,
879+
is_slash_command=False,
880880
is_bot_dm=event.get("channel_type") == "im",
881881
)
882882

883883
elif req.type == "slash_commands":
884884
channel = req.payload["channel_id"]
885+
channel_name = req.payload["channel_name"]
885886
msg = req.payload["text"]
886887
sender = req.payload["user_id"]
887888
expert_info = expert_info_from_slack_id(
@@ -899,8 +900,8 @@ def build_request_details(
899900
sender_id=sender,
900901
email=email,
901902
bypass_filters=True,
902-
is_bot_msg=True,
903-
is_bot_dm=False,
903+
is_slash_command=True,
904+
is_bot_dm=channel_name == "directmessage",
904905
)
905906

906907
raise RuntimeError("Programming fault, this should never happen.")

backend/onyx/onyxbot/slack/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class SlackMessageInfo(BaseModel):
1313
sender_id: str | None
1414
email: str | None
1515
bypass_filters: bool # User has tagged @OnyxBot
16-
is_bot_msg: bool # User is using /OnyxBot
16+
is_slash_command: bool # User is using /OnyxBot
1717
is_bot_dm: bool # User is direct messaging to OnyxBot
1818

1919

@@ -25,7 +25,7 @@ class ActionValuesEphemeralMessageMessageInfo(BaseModel):
2525
email: str | None
2626
sender_id: str | None
2727
thread_messages: list[ThreadMessage] | None
28-
is_bot_msg: bool | None
28+
is_slash_command: bool | None
2929
is_bot_dm: bool | None
3030
thread_to_respond: str | None
3131

0 commit comments

Comments
 (0)