Slack: post text and image files as one message instead of a file message followed by a text message

Open
#1,015 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript
Domain
backend

Research direction

Start in the Slack adapter's postMessage and its uploadFiles helper, which currently call files.completeUploadExternal with a channel and thread, then chat.postMessage for the text. The change moves image files into one chat.postMessage call with blocks (a markdown block plus image blocks using slack_file), with a bounded retry on invalid_blocks. Done means one thread message per post, correct ordering, and the long-text fallback still working; the issue leaves the non-image file case and opt-in behaviour open, so settle those with maintainers first.

Written by the indexing model from the issue text.

Description

enhancement
Problem Statement

On Slack, thread.post({ markdown, files }) produces two messages. The adapter's postMessage first calls uploadFiles, which runs files.completeUploadExternal with channel_id and thread_ts, so Slack posts the files as their own thread message; it then posts the text with chat.postMessage. In a thread the reader sees two bubbles per post, the text below the images it belongs to.

Slack also posts the file message asynchronously: completeUploadExternal returns before the file message is visible. When an app posts two messages in a row, each with text and images, the thread can end up ordered text, text, image, image.

Proposed Solution

When a Slack post carries image files, upload them privately and reference them from the text message's blocks, so one chat.postMessage carries both:

  1. files.completeUploadExternal with no channel_id. The files stay private to the bot and Slack posts nothing for them.
  2. chat.postMessage with blocks: a markdown block holding the text, followed by one image block per file using slack_file: { id }.

The post is synchronous, so thread order follows call order, and the markdown rendering of the text is kept. SentMessage.id becomes the real ts of the one message, so callers no longer get the synthetic file-{timestamp} id for a files-only post.

One Slack behaviour the adapter would need to absorb: for a short window after completeUploadExternal returns (about 500 ms in our runs), chat.postMessage rejects the reference with invalid_blocks and an error entry naming slack_file. A short bounded retry on that specific error addresses this.

The markdown block has the same 12,000-character cap as markdown_text, cumulative across the markdown blocks of one payload, so the existing fallback for long text still applies. Non-image files cannot go in an image block, so a post that carries them would keep the current path, or the behaviour could be opt-in through a post option.

Alternatives Considered

Calling the Slack Web API directly from our app: this is what we do today for this one path, which means bypassing the adapter's postMessage and reimplementing its token handling for one message type.

Use Case
import { Chat } from "chat";

// Today this is two Slack messages (files, then text); the request is
// for one message with the text above the images.
await bot.thread(threadId).post({
  markdown: noteText,
  files: [
    { data: screenshotA, filename: "before.png", mimeType: "image/png" },
    { data: screenshotB, filename: "after.png", mimeType: "image/png" },
  ],
});
Priority

Nice to have

Contribution
  • I am willing to help implement this feature
Additional Context

No response

Dominant language
TypeScript
Stars
2.5k
Forks
355
Avg merge
2d 15h
Merged PRs (30d)
42

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vercel/chat

All issues in vercel/chat

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.