vercel / vercel/chat

Support batching events for same thread/channel

Open
#449 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
2.4k
Forks
314
Avg merge
1d 18h
Merged PRs (30d)
63

Description

Problem Statement

Imagine a scenario where you set up a whatsapp bot and you use buttons of approve/reject tool calls.

Say that the user sent a message and clicks approve/reject right away - I'd like to be able to handle the button click first while queuing the message.

Complex case is when user just sends multiple messages + multiple reactions + multiple actions in same few seconds. As the developer I would like to be able to handle it in the order I want.

Proposed Solution

A lock for all kinds of events for same thread/channel that also groups the events.
Could be configured by concurrency: 'batch-debounce'.
Bot subscribes to batches, not to single event type, via bot.onBatch(<handler>).
Handler gets an array of all the events or an object like { messages, actions, reactions, etc...}, or similar.
That way the developer can decide how to handle these cases mentioned above.

Alternatives Considered

No response

Use Case
import { Chat } from "chat";

const bot = new Chat({
	userName: "botName",
	adapters: {
		telegram: createTelegramAdapter(),
		whatsapp: createWhatsAppAdapter(),
	},
	state: createPostgresState({ client: pool }),
	fallbackStreamingPlaceholderText: null,
        concurrency: "batch-debounce"
});

bot.onBatch(handleEvents)
Priority

Important

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

No response

Contributor guide

Open the contributing guide

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.

Research direction

Start by tracing the Chat configuration's concurrency handling and the event dispatch path behind bot.onBatch. Define the batching, ordering, locking, and debounce behavior for events sharing a thread or channel, then verify that handlers receive the documented grouped event shape.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.