This repository has been archived by the owner on Dec 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Fedorus edited this page Jul 14, 2021
·
3 revisions
Welcome to the TgBotFramework wiki!
Please, read all pages of this wiki BEFORE you start writing code and study examples. That will save you a lot of time later.
Main idea of this framework - create pipeline to process updates.
As you can see all process from receiving update to the end of processing is splitted to few stages:
- Receiving there is 2 ways you can receive updates Webhook (asp.net core controller) or Longpolling. And we need a way to unify it so we are using System.Threading.Channels.
- Processor - 1st and main part of the library. It builds single pipeline (on start) and then starts receiving updates from channel. Each update pushed into that pipeline.
- Middleware - usually each update object processing has steps that required for any type of update. For example: set up exception handling, logging update, populate some fields of context, etc.
- States/Stages - Sometimes you need to handle some user`s updates in different way. For example you need from user to fill some forms. Yeah, you can send them to fill some google form, but it might be better to use bot. To achieve that we need to handle some user inputs in different way. For that we using stage concept. Lets say we need First name from user and then his last name (As separate inputs). We sending him message "enter your First name" and we put him on a stage "Waiting for imput". At this step we checking at which stage he is now. If it is something other then "default" we searching for corresponding handler and adding it to pipeline. And if its "default" user proceeds to next stage.
- Commands - bot commands are special entities that starts with / and can be processed in pipeline(if some requirements are met) or they can be found by the framework and processed automatically if marked by CommandAttibute.
- UpdatePipeline - user-defined part, same as in Telegram.Bot.Framework.
Now lets talk little bit about pipeline and handlers in it. all pipeline consist with methods that has 3 paramethers:
- Context - object that has info about user state, botClient to communicate with telegram API, and some other fields (you can inherit it and extend with fields that you need.
- link to next pipeline handler. Thats the way for you to control pipeline behavior. You can stop flow at any handler. So you should be careful about it. to call next pipeline handler just call await next(context, cancellationToken);
- CancelationToken - ... no description, its obvious.