Skip to content

AttributedHandlers

immmdreza edited this page Jul 3, 2021 · 4 revisions

Setup your handlers simply using attributes.

There are two type of attributes in this library:

  • InComingHandler attributes
  • Filter attributes

Attributes can only be set on public static callback functions, if you don't know how is a callback function please read here

For each incoming update type there is an attribute:

  • [InComingMessageAttribute] -> Message
  • [InComingCallbackQueryAttribute] -> CallbackQuery
  • [InComingInlineQueryAttribute] -> InlineQuery
  • [InComingChosenInlineResultAttribute] -> ChosenInlineResult
  • [InComingChatMemberAttribute] -> ChatMemberUpdated
  • [InComingPollAttribute] -> Poll
  • [InComingPollAnswerAttribute] -> PollAnswer
  • [InComingShippingQueryAttribute] -> ShippingQuery
  • [InComingPreCheckoutQueryAttribute] -> PreCheckoutQuery

By adding one these on a suitable function it become a callback function for specified update type

After this it's time to add filter attributes.

At the moment there are some filters for messages.

[ChatTypeFilter] [CommandFilter] [RegexFilter]

Don't forget you can always build your custom filter using IFilterAttribute<T> where T is update type like Message

Read more about filter attributes

An attributed handler should be like this:

[InComingMessage(Group = 1)]
[RegexFilter("^/setname")]
[ChatTypeFilter(FlamingoChatType.Private)]
public static async Task<bool> MyAttributedCallback(ICondiment<Message> cdmt)
{
    await cdmt.ReplyText("OK what is your name?");
}

Flamingo Framework written in pure c#, install from Nuget

Clone this wiki locally