The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Preserve Slack attachment names in thread history when text is missing (#82631)
Chris Truter883e944ccef0
diff --git a/src/metabase/slackbot/streaming.clj b/src/metabase/slackbot/streaming.cljindex baaac0519ba..f4615719982 100644--- a/src/metabase/slackbot/streaming.clj+++ b/src/metabase/slackbot/streaming.clj@@ -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)diff --git a/test/metabase/slackbot/streaming_test.clj b/test/metabase/slackbot/streaming_test.cljindex 0544129af6d..2f85fb43b96 100644--- a/test/metabase/slackbot/streaming_test.clj+++ b/test/metabase/slackbot/streaming_test.clj@@ -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 {})