{"id":17652224,"url":"https://github.com/impworks/botrunner","last_synced_at":"2025-07-31T23:05:59.269Z","repository":{"id":148748740,"uuid":"205125388","full_name":"impworks/botrunner","owner":"impworks","description":"Tiny framework for programming Telegram Bots","archived":false,"fork":false,"pushed_at":"2019-08-29T10:43:32.000Z","size":12,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T08:02:14.813Z","etag":null,"topics":["telegram","telegram-bot","telegram-bot-framework"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/impworks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2019-08-29T09:12:55.000Z","updated_at":"2021-01-29T14:18:12.000Z","dependencies_parsed_at":"2023-05-28T20:00:17.942Z","dependency_job_id":null,"html_url":"https://github.com/impworks/botrunner","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/impworks%2Fbotrunner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/impworks%2Fbotrunner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/impworks%2Fbotrunner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/impworks%2Fbotrunner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/impworks","download_url":"https://codeload.github.com/impworks/botrunner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252839277,"owners_count":21812085,"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":["telegram","telegram-bot","telegram-bot-framework"],"created_at":"2024-10-23T11:46:14.479Z","updated_at":"2025-05-07T08:02:21.181Z","avatar_url":"https://github.com/impworks.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BotRunner\nTiny framework for programming Telegram Bots\n\n### What is it?\nThis is a framework for scripting bot dialogs in Telegram based on \u003ca href=\"https://github.com/TelegramBots/telegram.bot\"\u003eTelegram.Bot library\u003c/a\u003e.\nIt is based on a state machine: the dialog consists of steps, which can be executed sequentially or in a custom order.\nEach dialog with a user can have a custom \"state\" which stores data between steps.\n\n### Usage\nPretty straightforward.\n\n```csharp\nnamespace MyBot\n{\n    // Step 1: define the state\n    public class MyState: StateBase\n    {\n        public string Name { get; set; }\n    }\n\n    // Step 2: define the dialog steps\n    public static class RunnerDefinition\n    {\n        public static Runner\u003cMyState\u003e Create()\n        {\n            return new RunnerBuilder\u003cMyState\u003e()\n                .Step(async s =\u003e { await s.Reply(\"Please enter your name\"); })\n                .Step(async s =\u003e\n                {\n                    s.State.Name = s.Message.Text;\n                    await s.Reply(\"Nice to meet you, \" + s.State.Name);\n                })\n                .Build();\n        }\n    }\n    \n    // Step 3: run the bot\n    class Program\n    {\n        private const string Token = \"...\";\n\n        static async Task Main(string[] args)\n        {\n            var runner = RunnerDefinition.Create();\n            var client = new TelegramBotClient(Token); // you may need to add a proxy\n\n            client.OnMessage += async (s, e) =\u003e await runner.HandleAsync(client, e.Message);\n            client.StartReceiving();\n\n            Thread.Sleep(int.MaxValue);\n        }\n    }\n}\n```\n\n### API\n\nWhen declaring a step, you need to provide the handler in a form of `Func\u003cIExecutionContext\u003cTState\u003e, Task\u003e`.\n\nThe `IExecutionContext\u003cTState\u003e` is defined as follows:\n\n```csharp\npublic interface IExecutionContext\u003cout T\u003e where T: StateBase\n{\n    /// \u003csummary\u003e\n    /// Marks the specified step as next for execution.\n    /// \u003c/summary\u003e\n    void Goto(string stepId);\n\n    /// \u003csummary\u003e\n    /// Bot client instance.\n    /// \u003c/summary\u003e\n    ITelegramBotClient Bot { get; }\n\n    /// \u003csummary\u003e\n    /// User session.\n    /// \u003c/summary\u003e\n    T State { get; }\n\n    /// \u003csummary\u003e\n    /// Current message from the user.\n    /// \u003c/summary\u003e\n    Message Message { get; }\n}\n```\n\nAll available Telegram.Bot APIs are available, but you can create shorthand extension methods to make code more conscise. A `Reply` helper is already provided:\n\n```csharp\npublic static class ExecutionContextExtensions\n{\n    /// \u003csummary\u003e\n    /// Sends a text reply to the current message.\n    /// \u003c/summary\u003e\n    public static async Task Reply\u003cT\u003e(this IExecutionContext\u003cT\u003e ctx, string text)\n        where T: StateBase\n    {\n        await ctx.Bot.SendTextMessageAsync(ctx.Message.Chat.Id, text);\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimpworks%2Fbotrunner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimpworks%2Fbotrunner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimpworks%2Fbotrunner/lists"}