mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
feat: add example of usage
This commit is contained in:
parent
bcd2c96bb0
commit
aad8ac8464
1 changed files with 30 additions and 0 deletions
|
|
@ -0,0 +1,30 @@
|
|||
"""
|
||||
This is an example with usage of ChatTypesFilter
|
||||
It filters incoming object based on type of its chat type
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from aiogram import Bot, Dispatcher, executor, types
|
||||
from aiogram.types import ChatType
|
||||
|
||||
API_TOKEN = 'BOT TOKEN HERE'
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
# Initialize bot and dispatcher
|
||||
bot = Bot(token=API_TOKEN)
|
||||
dp = Dispatcher(bot)
|
||||
|
||||
|
||||
@dp.message_handler(chat_types=[ChatType.PRIVATE, ChatType.CHANNEL])
|
||||
async def send_welcome(message: types.Message):
|
||||
"""
|
||||
This handler will be called when user sends `/start` or `/help` command
|
||||
"""
|
||||
await message.reply("Hi!\nI'm hearing your messages in private chats and channels")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
executor.start_polling(dp, skip_updates=True)
|
||||
Loading…
Add table
Add a link
Reference in a new issue