Quick start¶
Simple template¶
At first you have to import all necessary modules
import logging
from pyAitu import Bot, Dispatcher, executor
from pyAitu.models import Message
Then you have to initialize bot and dispatcher instances. Bot token you can get from @MasterService
API_TOKEN = 'BOT_TOKEN_HERE'
#Configure logging
logging.basicConfig(level=logging.INFO)
#Initialize bot and dispatcher
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)
Next step: interaction with bot starts with start command. Register your first command handler:
@dp.message_handler(commands=['start'])
async def send_welcome(message: Message)
"""
This handler will be called when user sends `/start` command
"""
await bot.send_message(message.chat.id, "Hello world!")
If you want to handle all messages in the chat simply add handler without filters
Last step: run long polling.
if __name__ == '__main__':
executor.start_polling(dp)
Summary¶
"""
This is a echo bot
It echoes any incoming text messages
"""
import logging
from pyAitu import Bot, Dispatcher, executor
from pyAitu.models import Message
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()
async def echo(message: Message):
await bot.send_message(message.chat.id, message.text)
if __name__ == '__main__':
executor.start_polling(dp)