Skip to content

InComingFishes

immmdreza edited this page Jul 3, 2021 · 5 revisions

If you want to receive updates from the bot like messages or when someone clicked some buttons and many others, you need InComingFishes!

InComingFishes are UpdateHandlers. Generally you have two ways to implement handler.

SimpleInComing<T>

  • Not recommended if you have many handlers

With this class you can create a quick handler for any type of incoming updates.

T is the update type that is suppose to be handled with this handler. It can be Message, CallbackQuery, InlineQuery and etc.

Therefor you Should use SimpleInComing<Message> if you want to handle some incoming messages of any type ( text, photo, video and ... ) for now.

Every handler has two important parts

  • Callback function ( Require )
  • Filter ( Optional )

Callback function

callback function is where you handler begin processed the way to decide

It can be a simple respond to user or ...

This function has a required parameter of type ICondiment<T> where T is update type the same as what you used in SimpleInComing<T> ( ICondiment<Message> for messages )

Condiments contain everything you need to handle an update: Read more

The return type of this function is a Task<bool> which indicates that other handler for this update should be handled or it's the end for this update!

So, you callback function should be like below for a message handler:

public static async Task<bool> Handle(ICondiment<Message> cdmt)
{
    // respond to user
}

Filter

filter helps you specify what exact update you want to handle here.

For example, a message can be filtered by its type ( text, photo, ... ) or even the text itself can be filtered by regex. you can check if a message is from an specified user or chat or if it's a command or not ant etc.

Combination

The advantage of filters is that they can combine as one filter. You can combine filters using bitwise operator: & ( and ), | ( or ) and ~ ( not )

For example:

var myFilter = new CommandFilter("start") & new PrivateFilter<Message>();

this means a message sent in private chat and its text is /start

If you don't pass filter to handler, it will handler of incomings of type T

Read more about filter

Finish up

Now complete you handler by passing callback func and filter to it.

var myHandler = new SimpleHandler<Message>(Handle, myFilter);

Every not-attributed handler should be passed to flamingo:

flamingo.AddInComing(myHandler);

What's next?

Receiving updates

Attributed handlers

Drived InComingHandlers for a high amount of handlers environment.

Flamingo Framework written in pure c#, install from Nuget

Clone this wiki locally