-
Notifications
You must be signed in to change notification settings - Fork 0
AttributedHandlers
MohammadReza edited this page Jul 2, 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
Here is an example of creating a custom filter
[AttributeUsage(AttributeTargets.Method)]
public abstract class MyCustomFilter : Attribute, IFilterAttribute<Message>
{
public FilterBase<ICondiment<Message>> Filter => // Put your filter here ( new IsEditedFilter() )
}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?");
}