Skip to content

filters

the codegen'd hasX presence filters (bot api 10.0). all are re-exported from the top-level filters namespace and carry kinds metadata for the dispatcher fast-path. for usage, combinators (.and() / .or() / .not()), handcrafted filters and defineFilter, see dispatch & filters

ts
import { filters } from 'puregram'

tg.onMessage(filters.hasText, (message) => {
  // message.text is narrowed to string
  return message.send(message.text)
})

presence filters

message-family in the kinds column means every message-shaped update kind (message, edited_message, channel_post, … and the service events that derive from a Message payload)

filternarrowskinds
filters.hasActorChatactorChat: Chatmessage_reaction
filters.hasAnimationanimation: Animationmessage-family
filters.hasAudioaudio: Audiomessage-family
filters.hasAuthorSignatureauthorSignature: stringmessage-family
filters.hasBiobio: stringchat_join_request
filters.hasBoostAddedboostAdded: ChatBoostAddedmessage-family
filters.hasBusinessConnectionIdbusinessConnectionId: stringmessage-family
filters.hasCaptioncaption: stringmessage-family
filters.hasCaptionEntitiescaptionEntities: MessageEntity[]message-family
filters.hasChannelChatCreatedchannelChatCreated: truemessage-family
filters.hasChatBackgroundSetchatBackgroundSet: ChatBackgroundmessage-family
filters.hasChatOwnerChangedchatOwnerChanged: ChatOwnerChangedmessage-family
filters.hasChatOwnerLeftchatOwnerLeft: ChatOwnerLeftmessage-family
filters.hasChatSharedchatShared: ChatSharedmessage-family
filters.hasChatTypechatType: sender | private | group | supergroup | channelinline_query
filters.hasChecklistchecklist: Checklistmessage-family
filters.hasChecklistTasksAddedchecklistTasksAdded: ChecklistTasksAddedmessage-family
filters.hasChecklistTasksDonechecklistTasksDone: ChecklistTasksDonemessage-family
filters.hasCloseDatecloseDate: integerpoll
filters.hasConnectedWebsiteconnectedWebsite: stringmessage-family
filters.hasContactcontact: Contactmessage-family
filters.hasCorrectOptionIdscorrectOptionIds: integer[]poll
filters.hasCountryCodescountryCodes: string[]poll
filters.hasDatadata: stringcallback_query
filters.hasDeleteChatPhotodeleteChatPhoto: truemessage-family
filters.hasDescriptiondescription: stringpoll
filters.hasDescriptionEntitiesdescriptionEntities: MessageEntity[]poll
filters.hasDicedice: Dicemessage-family
filters.hasDirectMessagePriceChangeddirectMessagePriceChanged: DirectMessagePriceChangedmessage-family
filters.hasDirectMessagesTopicdirectMessagesTopic: DirectMessagesTopicmessage-family
filters.hasDocumentdocument: Documentmessage-family
filters.hasEditDateeditDate: integermessage-family
filters.hasEffectIdeffectId: stringmessage-family
filters.hasEntitiesentities: MessageEntity[]message-family
filters.hasExplanationexplanation: stringpoll
filters.hasExplanationEntitiesexplanationEntities: MessageEntity[]poll
filters.hasExplanationMediaexplanationMedia: PollMediapoll
filters.hasExternalReplyexternalReply: ExternalReplyInfomessage-family
filters.hasForumTopicClosedforumTopicClosed: ForumTopicClosedmessage-family
filters.hasForumTopicCreatedforumTopicCreated: ForumTopicCreatedmessage-family
filters.hasForumTopicEditedforumTopicEdited: ForumTopicEditedmessage-family
filters.hasForumTopicReopenedforumTopicReopened: ForumTopicReopenedmessage-family
filters.hasForwardOriginforwardOrigin: MessageOriginmessage-family
filters.hasFromfrom: Usermessage-family
filters.hasGamegame: Gamemessage-family
filters.hasGameShortNamegameShortName: stringcallback_query
filters.hasGeneralForumTopicHiddengeneralForumTopicHidden: GeneralForumTopicHiddenmessage-family
filters.hasGeneralForumTopicUnhiddengeneralForumTopicUnhidden: GeneralForumTopicUnhiddenmessage-family
filters.hasGiftgift: GiftInfomessage-family
filters.hasGiftUpgradeSentgiftUpgradeSent: GiftInfomessage-family
filters.hasGiveawaygiveaway: Giveawaymessage-family
filters.hasGiveawayCompletedgiveawayCompleted: GiveawayCompletedmessage-family
filters.hasGiveawayCreatedgiveawayCreated: GiveawayCreatedmessage-family
filters.hasGiveawayWinnersgiveawayWinners: GiveawayWinnersmessage-family
filters.hasGroupChatCreatedgroupChatCreated: truemessage-family
filters.hasGuestBotCallerChatguestBotCallerChat: Chatmessage-family
filters.hasGuestBotCallerUserguestBotCallerUser: Usermessage-family
filters.hasGuestQueryIdguestQueryId: stringmessage-family
filters.hasInlineMessageIdinlineMessageId: stringchosen_inline_result, callback_query
filters.hasInviteLinkinviteLink: ChatInviteLinkmy_chat_member, chat_member, chat_join_request
filters.hasInvoiceinvoice: Invoicemessage-family
filters.hasLeftChatMemberleftChatMember: Usermessage-family
filters.hasLinkPreviewOptionslinkPreviewOptions: LinkPreviewOptionsmessage-family
filters.hasLivePhotolivePhoto: LivePhotomessage-family
filters.hasLocationlocation: Locationmessage, edited_message, channel_post, edited_channel_post, business_message, edited_business_message, guest_message, inline_query, chosen_inline_result, new_chat_members, left_chat_member, new_chat_title, new_chat_photo, delete_chat_photo, group_chat_created, pinned_message, invoice, successful_payment, users_shared, chat_shared, web_app_data, video_chat_scheduled, video_chat_started, video_chat_ended, video_chat_participants_invited, forum_topic_created, forum_topic_edited, forum_topic_closed, forum_topic_reopened, general_forum_topic_hidden, general_forum_topic_unhidden, giveaway_created, giveaway_completed, giveaway_winners, boost_added, message_auto_delete_timer_changed, migrate_to_chat_id, migrate_from_chat_id, passport_data, proximity_alert_triggered, write_access_allowed
filters.hasManagedBotCreatedmanagedBotCreated: ManagedBotCreatedmessage-family
filters.hasMediamedia: PollMediapoll
filters.hasMediaGroupIdmediaGroupId: stringmessage-family
filters.hasMessagemessage: MaybeInaccessibleMessagecallback_query
filters.hasMessageAutoDeleteTimerChangedmessageAutoDeleteTimerChanged: MessageAutoDeleteTimerChangedmessage-family
filters.hasMessageThreadIdmessageThreadId: integermessage-family
filters.hasMigrateFromChatIdmigrateFromChatId: integermessage-family
filters.hasMigrateToChatIdmigrateToChatId: integermessage-family
filters.hasNewChatMembersnewChatMembers: User[]message-family
filters.hasNewChatPhotonewChatPhoto: PhotoSize[]message-family
filters.hasNewChatTitlenewChatTitle: stringmessage-family
filters.hasOpenPeriodopenPeriod: integerpoll
filters.hasOrderInfoorderInfo: OrderInfopre_checkout_query
filters.hasPaidMediapaidMedia: PaidMediaInfomessage-family
filters.hasPaidMessagePriceChangedpaidMessagePriceChanged: PaidMessagePriceChangedmessage-family
filters.hasPaidStarCountpaidStarCount: integermessage-family
filters.hasPassportDatapassportData: PassportDatamessage-family
filters.hasPhotophoto: PhotoSize[]message-family
filters.hasPinnedMessagepinnedMessage: MaybeInaccessibleMessagemessage-family
filters.hasPollpoll: Pollmessage-family
filters.hasPollOptionAddedpollOptionAdded: PollOptionAddedmessage-family
filters.hasPollOptionDeletedpollOptionDeleted: PollOptionDeletedmessage-family
filters.hasProximityAlertTriggeredproximityAlertTriggered: ProximityAlertTriggeredmessage-family
filters.hasQuestionEntitiesquestionEntities: MessageEntity[]poll
filters.hasQuotequote: TextQuotemessage-family
filters.hasRefundedPaymentrefundedPayment: RefundedPaymentmessage-family
filters.hasReplyMarkupreplyMarkup: InlineKeyboardMarkupmessage-family
filters.hasReplyToChecklistTaskIdreplyToChecklistTaskId: integermessage-family
filters.hasReplyToPollOptionIdreplyToPollOptionId: stringmessage-family
filters.hasReplyToStoryreplyToStory: Storymessage-family
filters.hasRightsrights: BusinessBotRightsbusiness_connection
filters.hasSenderBoostCountsenderBoostCount: integermessage-family
filters.hasSenderBusinessBotsenderBusinessBot: Usermessage-family
filters.hasSenderChatsenderChat: Chatmessage-family
filters.hasSenderTagsenderTag: stringmessage-family
filters.hasShippingOptionIdshippingOptionId: stringpre_checkout_query
filters.hasShowCaptionAboveMediashowCaptionAboveMedia: truemessage-family
filters.hasStickersticker: Stickermessage-family
filters.hasStorystory: Storymessage-family
filters.hasSuccessfulPaymentsuccessfulPayment: SuccessfulPaymentmessage-family
filters.hasSuggestedPostApprovalFailedsuggestedPostApprovalFailed: SuggestedPostApprovalFailedmessage-family
filters.hasSuggestedPostApprovedsuggestedPostApproved: SuggestedPostApprovedmessage-family
filters.hasSuggestedPostDeclinedsuggestedPostDeclined: SuggestedPostDeclinedmessage-family
filters.hasSuggestedPostInfosuggestedPostInfo: SuggestedPostInfomessage-family
filters.hasSuggestedPostPaidsuggestedPostPaid: SuggestedPostPaidmessage-family
filters.hasSuggestedPostRefundedsuggestedPostRefunded: SuggestedPostRefundedmessage-family
filters.hasSupergroupChatCreatedsupergroupChatCreated: truemessage-family
filters.hasTexttext: stringmessage-family
filters.hasUniqueGiftuniqueGift: UniqueGiftInfomessage-family
filters.hasUseruser: Usermessage_reaction, poll_answer
filters.hasUsersSharedusersShared: UsersSharedmessage-family
filters.hasVenuevenue: Venuemessage-family
filters.hasViaBotviaBot: Usermessage-family
filters.hasViaChatFolderInviteLinkviaChatFolderInviteLink: booleanmy_chat_member, chat_member
filters.hasViaJoinRequestviaJoinRequest: booleanmy_chat_member, chat_member
filters.hasVideovideo: Videomessage-family
filters.hasVideoChatEndedvideoChatEnded: VideoChatEndedmessage-family
filters.hasVideoChatParticipantsInvitedvideoChatParticipantsInvited: VideoChatParticipantsInvitedmessage-family
filters.hasVideoChatScheduledvideoChatScheduled: VideoChatScheduledmessage-family
filters.hasVideoChatStartedvideoChatStarted: VideoChatStartedmessage-family
filters.hasVideoNotevideoNote: VideoNotemessage-family
filters.hasVoicevoice: Voicemessage-family
filters.hasVoterChatvoterChat: Chatpoll_answer
filters.hasWebAppDatawebAppData: WebAppDatamessage-family
filters.hasWriteAccessAllowedwriteAccessAllowed: WriteAccessAllowedmessage-family

kind filters

match a specific update kind. callable filters.kind(k) or a shorthand property like filters.kind.message / filters.kind.editedMessage. filters.action is the same restricted to service-event kinds. the per-kind <Kind>Filter types (one for every kind on the updates page) are the pre-bound shape these produce