Support batching events for same thread/channel
Nobody has claimed this yet.
- 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
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.
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