That one single Telegram bot to replace all the others.
- Radzinsy.Host — ASP.NET Core web application that hosts a Telegram webhook or performs long polling.
- Radzinsy.Endpoints — crystal clean business logic; endpoint here basically means a use case.
- Radzinsy.Framework — boilerplate that makes business logic look crystal clean.
- Radzinsy.Persistence — database contexts, entities, migration, and all that.
- The Framework's discovery services scan the Endpoints assembly, collecting IEndpoint implementations with specific attributes.
- Telegram update comes from Telegram through the Host's WebhookController or in response to a long polling request.
- It reaches the Framework's UpdateHandler and then gets challenged by the Framework's routers.
- Each router tries to classify the update using its discovery service and then form a Route based on it.
- When a matching endpoint is finally found, it gets called. If there is no such endpoint, the update is ignored.
- Endpoint implementation handles the update in a separate DI scope, given both the Update and the Route.
- If needed, route type is specified (for example, into RegExRoute) and routing details (such as command's alias and parameters) are obtained.
- Be humble and prefer dotnet run over Docker Compose to save time.
- Prefer using long polling over webhook. Otherwise, suffer with ngrok or localtunnel.
- If using ngrok, consider signing in via auth token to get unlimited lifetime for your tunnel.
- To use long polling, just leave the Telegram:WebhookHost configuration null.
- Use .NET user secrets to keep your configuration safe and JSON.
- Give this repo a star.
- Don't use ngrok or localtunnel. Get a VPS.
- If using ngrok, consider signing in via auth token to get unlimited lifetime for your tunnel.
- Copy .env.example into .env (which is Git-ignored already), then modify the latter. Now run Docker Compose.
- Prefer webhook over long polling by setting TELEGRAM__WEBHOOKHOST.
- Give this repo a star.
Using double underscores in the environment variable names makes it possible to use both JSON configuration providers (for example, appsettings.Production.json or .NET user secrets) and environment variables seamlessly. What makes it work this way is Microsoft.Extensions.Configuration, that treats TELEGRAM__TOKEN and Telegram:Token as equivalent keys.
Telegram:Token
— Telegram Bot API token, issued at BotFather.Telegram:WebhookHost
— null if you want to use long polling, otherwise the hostname of your webhook server; the final webhook URL is built by the following template: {Telegram:WebhookHost}/bot/{Telegram:Token}.Google:Token
— API key of your Google CSE, see the tutorial.Google:Cx
— Programmable Search Engine ID, get one from the control panel.
If using .env, see .env.example.
- Radzinsky — its majesty.
- Степной ишак — the one writing all this.