Upd examples.

This commit is contained in:
Alex Root Junior 2017-11-19 01:05:50 +02:00
parent 7d75813f21
commit 801ca1558e
4 changed files with 14 additions and 25 deletions

View file

@ -8,6 +8,7 @@ import logging
from aiogram import Bot, types from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher from aiogram.dispatcher import Dispatcher
from aiogram.types import ParseMode from aiogram.types import ParseMode
from aiogram.utils.executor import start_pooling
from aiogram.utils.markdown import * from aiogram.utils.markdown import *
API_TOKEN = 'BOT TOKEN HERE' API_TOKEN = 'BOT TOKEN HERE'
@ -39,7 +40,4 @@ async def main():
if __name__ == '__main__': if __name__ == '__main__':
try: start_pooling(dp, loop=loop, skip_updates=True)
loop.run_until_complete(main())
except KeyboardInterrupt:
loop.stop()

View file

@ -3,6 +3,7 @@ import logging
from aiogram import Bot, types from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher from aiogram.dispatcher import Dispatcher
from aiogram.utils.executor import start_pooling
API_TOKEN = 'BOT TOKEN HERE' API_TOKEN = 'BOT TOKEN HERE'
@ -30,18 +31,11 @@ async def echo(message: types.Message):
await bot.send_message(message.chat.id, message.text) await bot.send_message(message.chat.id, message.text)
async def main():
count = await dp.skip_updates()
print(f"Skipped {count} updates.")
await dp.start_pooling()
if __name__ == '__main__': if __name__ == '__main__':
try: start_pooling(dp, loop=loop, skip_updates=True)
loop.run_until_complete(main())
except KeyboardInterrupt:
loop.stop()
# Also you can use another execution method # Also you can use another execution method
# >>> from aiogram.utils.executor import start_pooling # >>> try:
# >>> start_pooling(dp, loop=loop, on_startup=main, on_shutdown=shutdown) # >>> loop.run_until_complete(main())
# >>> except KeyboardInterrupt:
# >>> loop.stop()

View file

@ -3,6 +3,7 @@ import logging
from aiogram import Bot, types from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher from aiogram.dispatcher import Dispatcher
from aiogram.utils.executor import start_pooling
API_TOKEN = 'BOT TOKEN HERE' API_TOKEN = 'BOT TOKEN HERE'
@ -15,12 +16,10 @@ dp = Dispatcher(bot)
@dp.inline_handler() @dp.inline_handler()
async def inline_echo(inline_query: types.InlineQuery): async def inline_echo(inline_query: types.InlineQuery):
item = types.InlineQueryResultArticle('1', 'echo', types.InputTextMessageContent(inline_query.query)) item = types.InlineQueryResultArticle(id='1', title='echo',
input_message_content=types.InputTextMessageContent(inline_query.query))
await bot.answer_inline_query(inline_query.id, results=[item], cache_time=1) await bot.answer_inline_query(inline_query.id, results=[item], cache_time=1)
if __name__ == '__main__': if __name__ == '__main__':
try: start_pooling(dp, loop=loop, skip_updates=True)
loop.run_until_complete(dp.start_pooling())
except KeyboardInterrupt:
loop.stop()

View file

@ -7,6 +7,7 @@ from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher from aiogram.dispatcher import Dispatcher
from aiogram.types import ParseMode from aiogram.types import ParseMode
from aiogram.utils.emoji import emojize from aiogram.utils.emoji import emojize
from aiogram.utils.executor import start_pooling
from aiogram.utils.markdown import text, bold, italic, code from aiogram.utils.markdown import text, bold, italic, code
# Configure bot here # Configure bot here
@ -66,7 +67,4 @@ async def main():
if __name__ == '__main__': if __name__ == '__main__':
try: start_pooling(dp, loop=loop, skip_updates=True)
loop.run_until_complete(main())
except KeyboardInterrupt:
loop.stop()