Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Composer::boundary() #763

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

feat: add Composer::boundary() #763

wants to merge 8 commits into from

Conversation

KnorpelSenf
Copy link
Member

As suggested by @rayz1065

@rayz1065
Copy link
Member

Suppose I want to write a tree surrounding plugin, with regular middleware plugins I would simply be able to write:

type Options = { foo: string };
function myPlugin<C extends Context>(options?: Options): Middleware<C> {
    return (ctx, next) => {
        // ...
    };
}
bot.use(myPlugin({ foo: "bar" }));

It would be nice to be able to do something similar for a surrounding middleware:

export type SurroundingMiddlewareFn<C extends Context = Context> = (
    ctx: C,
    tree: () => Promise<{ nextCalled: boolean }>,
    next: NextFunction,
) => MaybePromise<unknown>;

function mySurroundingPlugin<C extends Context>(
    options?: Options,
): SurroundingMiddlewareFn<C> {
    return (ctx, tree, next) => {
        // ...
    };
}
const surrounded = bot.surround(mySurroundingPlugin({ foo: "baz" }));

@wojpawlik wojpawlik marked this pull request as draft February 23, 2025 20:01
@KnorpelSenf KnorpelSenf marked this pull request as ready for review February 23, 2025 20:37
@wojpawlik wojpawlik requested a review from rayz1065 February 24, 2025 18:05
@wojpawlik wojpawlik changed the title feat: add bot.surround feat: add Composer::boundary() Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants