Telegram: support the draft stop button (can_stop, keep_on_stop)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- typescript
- Domain
- api
Research direction
Start with nativeDraftStream and the Telegram update routing and types described in the issue; trace how draft IDs are created and how the stream reads textStream. Implement the first roadmap step: stop the matching in-process stream and save its partial text, then update the Telegram docs and add a changeset. The issue names no specific source or test files, and the later bot notification and cross-instance behavior remain open questions.
Written by the indexing model from the issue text.
Description
Problem Statement
When nativeStreaming: true is set, the Telegram adapter streams to private chats with sendRichMessageDraft (or sendMessageDraft as a fallback) and saves the result with sendRichMessage. Users have no way to stop a long answer while it streams.
Both draft methods accept can_stop, which shows the user a stop button. When the user presses it, Telegram sends the bot a stopped_message_generation update (MessageGenerationStopped, with chat, optional message_thread_id, and draft_id). keep_on_stop keeps the partial draft visible after the press, for a short time or until the bot sends a message.
The adapter doesn't send can_stop or keep_on_stop, and it doesn't handle stopped_message_generation, so the stream keeps running until the model finishes.
Proposed Solution
Add opt-in stop support to native draft streaming in @chat-adapter/telegram.
- Config: an option such as
streamStopButton: true, off by default. It applies only whennativeStreamingis on, because post-and-edit streams (the default) don't use drafts. - Sending:
nativeDraftStreampassescan_stop: trueandkeep_on_stop: truetosendRichMessageDraft, and tosendMessageDraftin the plain fallback. - Receiving: add
stopped_message_generationto the update types the adapter handles, and toTELEGRAM_DEFAULT_ALLOWED_UPDATES, which the adapter sends as an explicit list in business mode. - Stopping: match the update to the running stream by chat id,
message_thread_id, anddraft_id, then stop readingtextStream. - Saving: send the text received so far with
sendRichMessage, as when a stream ends normally, so the partial answer stays in the chat.keep_on_stopkeeps the draft visible until then, so the message doesn't flicker.
Open questions
- How does the bot learn about the stop? Stopping the adapter's read loop doesn't cancel the model request.
StreamOptions.signalalready lets the bot cancel a stream, but the adapter can't abort a signal the bot owns. Options:- The adapter aborts an
AbortSignalit exposes for the stream, which the bot passes tostreamText. - A new handler, such as
onStreamStop, receives the thread and the partial text.
- The adapter aborts an
- How does a stop reach the right process? On serverless deployments, the webhook with
stopped_message_generationcan arrive at a different instance from the one running the stream. One approach is to write a stop flag to the state adapter and check it on each draft flush. - Draft ids come from a per-process counter (
createDraftId), so two instances can use the samedraft_idin one chat. Should draft ids become random, or is matching on the chat plus the id enough?
Roadmap
- Stop button and update handling. Add the option, send
can_stopandkeep_on_stop, add theMessageGenerationStoppedtype totypes.ts, routestopped_message_generation, stop the read loop, and save the partial text. Cover a stop arriving in the same process. Update the Telegram docs page and add a changeset. - Bot notification and cross-instance stops. Implement the answers to open questions 1 and 2.
Alternatives Considered
- Handling
stopped_message_generationin bot code. The adapter doesn't route the update, so a bot would need to subclassTelegramAdapterand overrideprocessUpdate, and it couldn't reach the stream's draft id. - Stopping only the read loop, without telling the bot. The stream ends in the chat, but the model keeps generating tokens.
Use Case
import { Chat } from "chat";
import { createTelegramAdapter } from "@chat-adapter/telegram";
import { createMemoryState } from "@chat-adapter/state-memory";
import { streamText } from "ai";
import { model } from "./model"; // any AI SDK model
const bot = new Chat({
userName: "mybot",
adapters: {
telegram: createTelegramAdapter({
nativeStreaming: true,
// Proposed option
streamStopButton: true,
}),
},
state: createMemoryState(),
});
bot.onNewMention(async (thread, message) => {
const result = streamText({ model, prompt: message.text });
// Private chat: the draft shows a stop button. Pressing it ends the
// stream and keeps the text received so far.
await thread.post(result.fullStream);
});
Priority
Important
Contribution
- I am willing to help implement this feature
Additional Context
sendRichMessageDraftandsendMessageDraft:can_stopandkeep_on_stopMessageGenerationStopped- #822 made native draft streaming opt-in (
nativeStreaming) - #1138 proposes HTML widget cards for the same adapter
- Dominant language
- TypeScript
- Stars
- 2.5k
- Forks
- 355
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 42
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vercel/chat
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
X and Twitch: paragraphs inside a block quote are joined with no spacePossibly taken @abhiramshaji-cyber claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 58/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 1/5 1-3 hours Newbie friendliness 87/100
Maintainers usually reply within 1 day
-
🛠️ dette technique
Difficulty 2/5 1-3 hours Newbie friendliness 61/100
betagouv/mon-entreprise#4752 · 1 comment ·
Maintainers usually reply within 5 days
-
type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
franciscoBSalgueiro/en-croissant#1111 ·
Maintainers usually reply within 2 days
-
area/providers type/feature version/v2
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
anomalyco/opencode#64845 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day