GithubHelp home page GithubHelp logo

undrcrxwn / radzinsky Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 1.0 295 KB

That one single Telegram bot to replace all the others

Home Page: https://t.me/radzinsky_bot

C# 99.22% Dockerfile 0.78%
bot bots chat-manager telegram telegram-api telegram-bot telegram-bot-api telegram-bots asp-net-core dotnet web-api

radzinsky's Introduction

  Radzinsky

That one single Telegram bot to replace all the others.

Solution structure

  • 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.

Flow

  1. The Framework's discovery services scan the Endpoints assembly, collecting IEndpoint implementations with specific attributes.
  2. Telegram update comes from Telegram through the Host's WebhookController or in response to a long polling request.
  3. It reaches the Framework's UpdateHandler and then gets challenged by the Framework's routers.
  4. Each router tries to classify the update using its discovery service and then form a Route based on it.
  5. When a matching endpoint is finally found, it gets called. If there is no such endpoint, the update is ignored.
  6. Endpoint implementation handles the update in a separate DI scope, given both the Update and the Route.
  7. If needed, route type is specified (for example, into RegExRoute) and routing details (such as command's alias and parameters) are obtained.

When running locally

  • 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.

When deploying to production

  • 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.

Configuration

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.

Useful links

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.