fix(slack): upload-file silently drops a caption (#121047)

The Slack `upload-file` action accepts `media` as an alias for `filePath`, so
a caller can reach it with the same vocabulary used for a media `send`. That
vocabulary carries its accompanying text in `caption`, but the upload path
read only `initialComment` and `message`, so the text was dropped and the file
arrived in the channel with no comment at all.

Accept `caption` as the lowest-precedence alias. Explicit `initialComment`
still wins, `message` still comes next, and an explicitly empty
higher-precedence value stays empty.
This commit is contained in:
Ilya Kuprov
2026-08-15 08:58:55 +01:00
committed by GitHub
parent cf57cbf39a
commit f21d34d71d
2 changed files with 30 additions and 0 deletions
@@ -738,6 +738,32 @@ describe("handleSlackMessageAction", () => {
initialComment: "path alias",
},
},
{
name: "maps an upload-file caption to the upload's initial comment",
params: {
channelId: "C1",
media: "/tmp/chart.png",
caption: "chart attached",
},
expected: {
filePath: "/tmp/chart.png",
initialComment: "chart attached",
},
},
{
name: "prefers an explicit upload-file initial comment over message and caption",
params: {
channelId: "C1",
media: "/tmp/chart.png",
initialComment: "",
message: "message text",
caption: "caption text",
},
expected: {
filePath: "/tmp/chart.png",
initialComment: "",
},
},
])("$name", async ({ params, expected }) => {
const invoke = createInvokeSpy();
const cfg = slackConfig();
@@ -358,6 +358,10 @@ export async function handleSlackMessageAction(params: {
initialComment:
readStringParam(actionParams, "initialComment", { allowEmpty: true }) ??
readStringParam(actionParams, "message", { allowEmpty: true }) ??
// `media` is accepted as an alias for the file, so a send-shaped call
// arrives with its text in `caption`; without this alias that text is
// silently dropped instead of becoming the upload's first comment.
readStringParam(actionParams, "caption", { allowEmpty: true }) ??
"",
filename: readStringParam(actionParams, "filename"),
title: readStringParam(actionParams, "title"),