Skip to content

Support batching events for same thread/channel #449

@LiranYoffe

Description

@LiranYoffe

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions