Skip to content

Implement Middleware-based message loop#49

Merged
MajMcCloud merged 14 commits intoMajMcCloud:developmentfrom
mottaghipour:development
Apr 20, 2025
Merged

Implement Middleware-based message loop#49
MajMcCloud merged 14 commits intoMajMcCloud:developmentfrom
mottaghipour:development

Conversation

@mottaghipour
Copy link
Copy Markdown
Contributor

Please check example project :)

@gitguardian
Copy link
Copy Markdown

gitguardian bot commented Nov 1, 2023

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

Since your pull request originates from a forked repository, GitGuardian is not able to associate the secrets uncovered with secret incidents on your GitGuardian dashboard.
Skipping this check run and merging your pull request will create secret incidents on your GitGuardian dashboard.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
- - Telegram Bot Token 12c3e66 Examples/MiddlewareBaseBot/Program.cs View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@MajMcCloud
Copy link
Copy Markdown
Owner

MajMcCloud commented Dec 10, 2023

@mottaghipour
Please write a more detailed description of features and functions for the ReadMe.

Thank you

@MajMcCloud
Copy link
Copy Markdown
Owner

@mottaghipour
Hey!

may you please take a look :-) ? So we can add it soon to the dev package first.
If you need some help , please let me know.

Thanks!

@mottaghipour
Copy link
Copy Markdown
Contributor Author

mottaghipour commented Mar 9, 2025

Hi, I apologize, I haven't been active for a while.

So, this pull request :)

I remember wanting to use inline queries, but the forms didn't support it, so I customized this mechanism for myself, which is the main method I'm using in the usage examples here:

/// <summary>
///     Creates a bot with middleware message loop for handle inline queries
/// </summary>
private static BotBase GetInlineQueryBot()
{
    var bot = BotBaseBuilder
                .Create()
                .WithAPIKey("6989687640:AAFGnjKCa9OOpVyVAYuSpt-axjCHKWpA0sI")
                .MiddlewareMessageLoop(
                    messageLoop =>
                        messageLoop
                            .UseValidUpdateTypes(UpdateType.InlineQuery)
                            .Use(async (container, next) =>
                            {
                                var query = container.UpdateResult.RawData.InlineQuery.Query;

                                if (!string.IsNullOrWhiteSpace(query))
                                {
                                    // logic

                                    await next();
                                }

                                return;
                            }))
                .WithStartForm<StartForm>()
                .NoProxy()
                .DefaultCommands()
                .NoSerialization()
                .UsePersian()
                .Build();

    return bot;
}

Meanwhile, if the user wants to have a lightweight message loop, they can choose exactly what middleware to use, which is much more practical than your old message loops.

Regards

@mottaghipour
Copy link
Copy Markdown
Contributor Author

Or sometimes we need an authentication middleware and with this mechanism you can implement your own custom authentication and block messages from unauthorized users.

@MajMcCloud
Copy link
Copy Markdown
Owner

Hey @mottaghipour

thanks for getting back. I will have a look at it the next days and add it to the development branch, so it can become a preview soon. Not sure if you wrote some example project or readme on how to use it.
Will check later then and get back if anything is needed.

Cheers
Florian

Copy link
Copy Markdown
Owner

@MajMcCloud MajMcCloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems legit.

@MajMcCloud MajMcCloud merged commit c57e357 into MajMcCloud:development Apr 20, 2025
1 check passed
@MajMcCloud
Copy link
Copy Markdown
Owner

MajMcCloud commented Apr 20, 2025

Welcome to the family @mottaghipour
And thank you so much for your contribution!

@mottaghipour
Copy link
Copy Markdown
Contributor Author

Hi :)
I'm glad it helped the project.

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.

2 participants