{"id":15011534,"url":"https://github.com/tipalol/telegram.bot.framework","last_synced_at":"2025-04-12T03:43:41.441Z","repository":{"id":245289678,"uuid":"817797496","full_name":"tipalol/Telegram.Bot.Framework","owner":"tipalol","description":"This is a simple and lightweight framework that helps you create Telegram bots faster.","archived":false,"fork":false,"pushed_at":"2025-01-13T07:13:22.000Z","size":85,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T23:23:08.499Z","etag":null,"topics":["csharp","dotnet","dotnet8","nuget","nuget-package","telegram","telegram-bot","telegram-bot-api","telegrambot"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tipalol.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-20T13:10:39.000Z","updated_at":"2024-07-13T16:03:38.000Z","dependencies_parsed_at":"2024-07-05T16:00:18.845Z","dependency_job_id":"0684fa85-92e1-433d-8868-7310fe04e739","html_url":"https://github.com/tipalol/Telegram.Bot.Framework","commit_stats":{"total_commits":21,"total_committers":1,"mean_commits":21.0,"dds":0.0,"last_synced_commit":"885a36cbca9fac23f8bcff26c9e9488c565a3a7b"},"previous_names":["tipalol/telegram.bot.framework"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tipalol%2FTelegram.Bot.Framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tipalol%2FTelegram.Bot.Framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tipalol%2FTelegram.Bot.Framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tipalol%2FTelegram.Bot.Framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tipalol","download_url":"https://codeload.github.com/tipalol/Telegram.Bot.Framework/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248514213,"owners_count":21116899,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","dotnet8","nuget","nuget-package","telegram","telegram-bot","telegram-bot-api","telegrambot"],"created_at":"2024-09-24T19:41:13.089Z","updated_at":"2025-04-12T03:43:41.420Z","avatar_url":"https://github.com/tipalol.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Telegram Bot API Framework\n\nThis is a simple and lightweight framework that helps you create Telegram bots faster. It uses the [Telegram Bot API](https://core.telegram.org/bots)\n\n## Usage\n\nExample projects can be found at:\n- [Console Application example](https://github.com/tipalol/Telegram.Bot.Framework/tree/main/Telegram.Bot.Framework.TestClient)\n- [Web Application example](https://github.com/tipalol/Telegram.Bot.Framework/tree/main/Telegram.Bot.Framework.WebClient)\n\nHere's an example of how to use the framework to create a simple bot that replies the same text when a user sends a text message:\n\n```c#\n// Program.cs\n\nvar settings = new TelegramSettings\n{\n    Token = \"your_api_token\"\n};\n\nvar handlers = new PipelineBuilder()\n    .WithMiddleware\u003cSubscriptionMiddleware\u003e()\n    .WithMessageHandler\u003cStartHandler\u003e()\n    .WithMessageHandler\u003cTextHandler\u003e()\n    .Build();\n\n// initialize telegram client\nITelegramClient telegramClient = new TelegramClient(settings)\n    .ConfigureBasePipelines(handlers);\n\nawait telegramClient.Start();\n```\n\n```c#\n// TextHandler.cs.cs\n\n/// \u003csummary\u003e\n/// Handles all text messages\n/// \u003c/summary\u003e\npublic class TextHandler : MessageHandler\n{\n    public override bool CanHandle(Message message)\n    {\n        return true;\n    }\n\n    public override async Task HandleAsync(Message message, ITelegramBotClient botClient, CancellationToken cancellationToken)\n    {\n        await botClient.SendTextMessageAsync(message.ChatId, $\"You said: {message.Data}\",\n            cancellationToken: cancellationToken);\n    }\n}\n```\n\n### Chat commands\n\nYou can add more commands by adding new handlers like this one:\n\n```c#\n// StartHandler.cs\n\n/// \u003csummary\u003e\n/// Handles /start message\n/// \u003c/summary\u003e\npublic class StartHandler : MessageHandler\n{\n    /// \u003cinheritdoc/\u003e\n    public override bool CanHandle(Message message)\n    {\n        return message.Data is \"/start\";\n    }\n\n    public override async Task HandleAsync(Message message, ITelegramBotClient botClient, CancellationToken cancellationToken)\n    {\n        await botClient.SendTextMessageAsync(message.ChatId, \"Hello, I'm working!\", cancellationToken: cancellationToken);\n    }\n}\n```\n\n### Callback data\n\nCallback data is used to pass information between different functions in your bot. For example, you could have a `some_request` callback called and then handle it in another function like this:\n\n```c#\n// SomeCallbackHandler.cs\n\npublic class SomeCallbackHandler : MessageHandler\n{\n    public override bool CanHandle(Message message)\n    {\n        return message.Data is \"some_request\";\n    }\n\n    public override async Task HandleAsync(Message message, ITelegramBotClient botClient, CancellationToken cancellationToken)\n    {\n        await botClient.SendTextMessageAsync(message.ChatId, \"Alright, you?\", cancellationToken: cancellationToken);\n        \n        // we must say OK to Telegram API, so it knows callback is handled\n        await botClient.CallbackOk(message, cancellationToken);\n    }\n}\n```\n\n### Reply markups\n\nReply markups are used to provide additional options or buttons for users to interact with your bot. You can create as many reply markups as you need, and they will be displayed below the message you send.\n\n```c#\n//MenuHandler.cs\n\npublic class MenuHandler : MessageHandler\n{\n    /// \u003cinheritdoc/\u003e\n    public override bool CanHandle(Message message)\n    {\n        return message.Data is \"/menu\";\n    }\n\n    /// \u003cinheritdoc/\u003e\n    public override async Task HandleAsync(Message message, ITelegramBotClient botClient, CancellationToken cancellationToken)\n    {\n        await botClient.SendTextMessageAsync(message.ChatId, \"Main menu\", replyMarkup: MenuProvider.MainMenu,\n            cancellationToken: cancellationToken);\n    }\n}\n\n// MenuProvider.cs\n\npublic static class MenuProvider\n{\n    public static InlineKeyboardMarkup MainMenu { get; } = new InlineMenuBuilder()\n        .WithButton(\"What's up?\", \"some_request\")\n        .Build();\n}\n```\n\n### Middlewares\n\n```c#\n//SubscriptionMiddleware.cs\n\npublic class SubscriptionMiddleware(IServiceProvider serviceProvider) : Middleware\n{\n    /// \u003cinheritdoc /\u003e\n    public override bool CanHandle(Message message)\n    {\n        return message.Data is not \"/start\";\n    }\n\n    /// \u003cinheritdoc/\u003e\n    public override async Task HandleAsync(Message message, ITelegramBotClient botClient, CancellationToken cancellationToken)\n    {\n        var subscriptionService = serviceProvider.GetRequiredService\u003cISubscriptionService\u003e();\n        var subscribed = subscriptionService.CheckSubscription(message.ChatId);\n\n        if (subscribed)\n        {\n            Successful = true;\n            return;\n        }\n\n        await botClient.SendTextMessageAsync(message.ChatId, \n            \"We can't find your subscription. Access is denied\", cancellationToken: cancellationToken);\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftipalol%2Ftelegram.bot.framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftipalol%2Ftelegram.bot.framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftipalol%2Ftelegram.bot.framework/lists"}