Preserve Slack attachment names in thread history when text is missing (#82631)

This commit is contained in:
Chris Truter
2026-09-18 22:48:34 -04:00
committed by GitHub
parent 9d1c919f6b
commit 883e944cce
2 changed files with 13 additions and 2 deletions

View File

@@ -71,7 +71,7 @@
A message with no other text names its attachments instead, or contributes nothing."
[{:keys [text files]} bot-user-id]
;; The model rejects an empty user message, and a file shared on its own arrives with empty text.
(let [content (slackbot.events/strip-bot-mention text bot-user-id)]
(let [content (slackbot.events/strip-bot-mention (or text "") bot-user-id)]
(if-not (str/blank? content)
content
(when-let [names (seq (keep :name files))]
@@ -95,7 +95,6 @@
msg-history (slackbot.persistence/message-history conversation-id bot-msg-ids)
deleted-ids (slackbot.persistence/deleted-message-ids conversation-id bot-msg-ids)]
(->> (:messages thread)
(filter :text)
(remove ignore-msg?)
(remove (fn [{:keys [ts] :as msg}]
(and (slackbot.events/bot-message? msg)

View File

@@ -98,6 +98,18 @@
{:role :user :content "chart it"}]
result))))))
(deftest thread->history-messages-without-text-test
(testing "A message with no text key still names its attachments, and is otherwise excluded"
(mt/with-dynamic-fn-redefs [slackbot.persistence/message-history (constantly {})]
(let [thread {:messages [{:ts "1709567890.000001" :user "U123" :files [{:name "data.csv"}]}
{:ts "1709567890.000002" :user "U123"}
{:ts "1709567890.000003" :bot_id "B123"}
{:ts "1709567890.000004" :text "chart it" :user "U123"}]}
result (#'slackbot.streaming/thread->history thread "UBOT123" "conv-123")]
(is (= [{:role :user :content "Attached files: data.csv"}
{:role :user :content "chart it"}]
result))))))
(deftest thread->history-excludes-soft-deleted-bot-messages-test
(testing "thread->history excludes bot messages that have been soft-deleted"
(mt/with-dynamic-fn-redefs [slackbot.persistence/message-history (constantly {})