Commit graph

154 commits

Author SHA1 Message Date
Alex Root Junior
11efa8e186
Added full support of Bot API 7.6 (#1533)
* Added full support of Bot API 7.6

* Fixed imports

* fix tests (#1534)

* Fixed coverage

* Override InputPaidMedia media type to `str | InputFile`

* Added shortcut

* Fixed PaidMediaType enum

* Added changelog

---------

Co-authored-by: Oleg A <t0rr@mail.ru>
2024-07-06 20:31:49 +03:00
Alex Root Junior
1f7bbeb355
Added full support of Bot API 7.5 (#1518)
* Added full support of Bot API 7.5

* Added changelog

* Update date type in RevenueWithdrawalStateSucceeded

* Added example
2024-06-19 00:54:22 +03:00
Rishat-F
1df3adaba1
Fail redis and mongo tests if incorrect URI provided + some storages tests refactoring (#1510)
* Smaller timeout for MongoStorage connection

By default serverSelectionTimeoutMS=30000. This is too much

* Correct ConnectionError for RedisStorage in tests

* Remove unused import in conftest.py

* Refactor skipping redis and mongo tests

* Fail redis and mongo tests if incorrect URI

If incorrect URIs provided to "--redis" and/or "--mongo" options
tests should fail with ERRORs instead of skipping.
Otherwise the next scenario is possible:
  1) developer breaks RedisStorage and/or MongoStorage code
  2) tests are run with incorrect redis and/or mongo URIs
     provided by "--redis" and "--mongo" options.
     For example, wrong port specified.
  3) tests pass because skipping doesn't fail tests run
  4) developer or reviewer doesn't notice
     that redis and/or mongo tests were skipped
  5) broken code gets in codebase

* Remove unused fixtures passing in storages tests

* Define create_storage_key fixture in conftest.py

* Linters formatting

* Changes description

* Revert "Smaller timeout for MongoStorage connection"

This reverts commit d88b7ec612.

* Smaller timeout for MongoStorage connection in tests

The default 30s timeout is too long

* Add test for MongoStorage for 100% coverage

* Linters formatting

* Move skipping redis/mongo tests in earlier fixtures

* Replace vars with constants in conftest.py

* Linters formatting
2024-06-17 00:55:59 +03:00
Oleg A
7760ab1d0d
Bump dev dependencies (#1512)
* Bump dev dependencies

* Pre-commit py3.8 support

* Pre-commit py3.8 support (v3.5+)

* Mute mypy python version bug
2024-06-14 20:11:08 +03:00
Oleg A
0df95a0276
Apply isort (#1508) 2024-06-11 03:08:08 +03:00
sdmway
e3dc7d576b
misc: code consistency and bot instance creation (#1482)
* misc: code consistency and bot instance creation

* Changelog for aiogram#1482

* misc: consistency of comments and dispatcher instance creation

* misc: removed routers example

* Update CHANGES/1482.misc.rst

---------

Co-authored-by: Alex Root Junior <jroot.junior@gmail.com>
2024-05-31 20:11:21 +03:00
Alex Root Junior
4729978c60
Add context manager support for bot client (#1468)
* Add context manager support for bot client

The bot client now supports the context manager protocol, providing automatic resource management. This enhancement helps to automatically close the session when leaving the context, which cleans up resources better. The documentation and tests have been updated accordingly to illustrate this new feature. Moreover, an example of usage without a dispatcher has been provided to clarify its use in simple cases.

* Added changelog
2024-04-22 23:42:47 +03:00
Yana Malenko
b49939aaff
add default bot properties and clean imports (#1447) 2024-04-09 01:27:29 +03:00
Alex Root Junior
3d63bf3b99
PoC Scenes (#1280)
* Base implementation

* Small refactoring + added possibility to specify post-action on handlers

* Move scene properties to config object

* Revise aiogram/scenes with wizard-based design pattern

Modified files in aiogram/scenes to incorporate the Wizard design pattern. Files affected are _marker.py, _registry.py, _wizard.py and __init__.py. The changes introduced a SceneWizard Class and ScenesManager, both of which aid in controlling navigation between different scenes or states. This helps clarifying the codebase, streamline scene transitions and offer more control over the app flow.

* Added example

* Small optimizations

* Replace ValueError with SceneException in scenes. Added error safety in scene resolver.

* str

* Added possibility to reset context on scene entered and to handle callback query in any state

* Remove inline markup in example

* Small changes

* Docs + example

* Small refactoring

* Remove scene inclusion methods from router

The methods for including scenes as sub-routers have been removed from the router.py file. Instead, the SceneRegistry class is now set to register scenes by default upon initializing. This streamlines the scene management process by removing redundant routers and making registration automatic.

* Init tests

* Small fix in tests

* Add support for State instance in the scene

The aiogram FSM scene now allows the use of State instance as an argument, enabling more customization. Modified the 'as_handler' method to receive **kwargs arguments, allowing passing of attributes to the handler. An additional type check has been also added to ensure the 'scene' is either a subclass of Scene or a string.

* Fixed test

* Expand test coverage for test_fsm module

The commit enhances tests for the test_fsm module to improve code reliability. It includes additional unit tests for the ObserverDecorator and ActionContainer classes and introduces new tests for the SceneHandlerWrapper class. This ensures the correct functionality of the decorator methods, the action container execution, and the handler wrapper.

* Reformat code

* Fixed long line in the example

* Skip some tests on PyPy

* Change mock return_value

* Compatibility...

* Compatibility...

* Compatibility...

* Added base changes description

* Scenes Tests (#1369)

* ADD tests for `SceneRegistry`

* ADD tests for `ScenesManager`

* ADD Changelog

* Revert "ADD Changelog"

This reverts commit 6dd9301252.

* Remove `@pytest.mark.asyncio`, Reformat code

* Scenes Tests. Part 2 (#1371)

* ADD tests for `SceneWizard`

* ADD tests for `Scene`

* Refactor ObserverDecorator to use on.message syntax in test_scene.py
Cover `Scene::__init_subclass__::if isinstance(value, ObserverDecorator):`

* Refactor `HistoryManager` in `aiogram/fsm/scene.py`
Removed condition that checked if 'history' is empty before calling 'update_data' in 'Scene'.

* ADD tests for `HistoryManager`

* Small changes in the documentation

* Small changes in the documentation

* Small changes in the documentation

---------

Co-authored-by: Andrew <11490628+andrew000@users.noreply.github.com>
2023-11-23 00:41:21 +02:00
Alex Root Junior
fec138977d
Telegram Bot API 6.9 (#1319)
* Added support for Bot API 6.9

* Bump API

* Added changelog
2023-09-22 17:46:57 +03:00
Oleg A
490381b57f
chore: apply lint&reformat (#1307) 2023-09-19 17:43:43 +03:00
Alex Root Junior
b94123de3d
Remove commands= from examples 2023-09-06 00:50:46 +03:00
Alex Root Junior
2cf224da49
Reformat code 2023-08-26 22:34:30 +03:00
Alex Root Junior
b7be9c2b81
Small cleanup in examples 2023-08-21 01:13:19 +03:00
Danipulok
16649ec896
Add error handling example (#1099)
* Add error handling example

* Add `ExceptionMessageFilter` usage

* Add `CHANGES`

* Update CHANGES/1099.doc.rst

---------

Co-authored-by: Alex Root Junior <jroot.junior@gmail.com>
2023-08-14 23:43:44 +03:00
Alex Root Junior
8ff992bf1d
Content from global filters (#1267)
* Move global filters check placement into router to add chance to pass context from global filters into handlers in the same way as it possible in other places

* Added changelog
2023-08-14 22:18:11 +03:00
Kostiantyn Kriuchkov
fac0a533b0
Examples/dev 3x multi file (#1254)
* Add multi-file bot example

This commit adds a multi-file bot example to the repository. .

* Refactor: Clean up code formatting for consistency

* add Changelog

* Refactor bot code, fix changelog version
2023-08-13 18:00:59 +03:00
nullmatawasoradesu
f87deea4fb
Added a section on Dependency Injection technology in documentation (#1253)
* Added a section on Dependency Injection technology in documentation

* Added changelog

* Edited comments & titles
2023-08-13 17:59:38 +03:00
Alex Root Junior
020db29e6d
Fixed line length 2023-08-13 17:01:21 +03:00
Kostiantyn Kriuchkov
c516ea9d6a
Refactor and improve bot examples (#1256)
* Refactor and improve bot messages

Refactored bot code to use aiogram enumerations and enhanced chat messages with markdown beautifications for a more user-friendly display.

CommandStart() is now used instead of Command('start') for readability.

Furthermore, the bot's 'stop' command was improved, ensuring it executes appropriately during KeyboardInterrupt or SystemExit.

Additionally, the bot's logging was adjusted to output to sys.stdout for better logs' readability.

* Added Changelog

* Add guidance comments on obtaining bot tokens from environment variables

* Remove hardcoded tokens, opt for environment variable

* Remove unnecessary spaces and reorganize imports

* Fix error, switch default storage from Redis to Memory, and add logging to multibot example
2023-08-10 22:10:30 +03:00
Alex Root Junior
b311d59fce
Webhook docs (#1248)
* Added documentation for polling/webhook modes

* Added changelog

* Added changelog
2023-08-06 16:59:29 +03:00
Andrey
2dd019d486
Fix typo (#1164) 2023-04-17 00:31:33 +03:00
Alex Root Junior
46218b8696
Towncrier build 2023-02-19 18:10:11 +02:00
Alex Root Junior
a332e88bc3
Fixed lines in FSM example 2023-02-13 00:55:53 +02:00
Alex Root Junior
f4ce4431f9
Migrate to hatchling (#1095)
* Migrate to hatchling instead of poetry, ruff instead of flake8

* Migrate to hatchling instead of poetry, ruff instead of flake8

* Update tests suite

* venv?

* -m venv?

* Change dependencies

* Remove venv

* Change mypy config

* Added changelog

* Mark uvloop incompatible with pypy

* Update release script

* Use internal caching for dependencies

* Re-disable cov branches

* Added contributing guide
2023-01-12 02:49:58 +02:00
Alex Root Junior
f4251382e8
Remove filters factory, introduce docs translation (#978)
* Rewrite filters

* Update README.rst

* Fixed tests

* Small optimization of the Text filter (TY to @bomzheg)

* Remove dataclass slots argument in due to the only Python 3.10 has an slots argument

* Fixed mypy

* Update tests

* Disable Python 3.11

* Fixed #1013: Empty mention should be None instead of empty string.

* Added #990 to the changelog

* Added #942 to the changelog

* Fixed coverage

* Update poetry and dependencies

* Fixed mypy

* Remove deprecated code

* Added more tests, update pyproject.toml

* Partial update docs

* Added initial Docs translation files

* Added more changes

* Added log message when connection is established in polling process

* Fixed action

* Disable lint for PyPy

* Added changelog for docs translation
2022-10-02 00:04:31 +03:00
Alex Root Junior
0e0dbe7e59
Deprecate filters factory (#976)
* Deprecate filters factory

* Added changelog

* Update filters usage in docs and examples
2022-08-14 18:40:41 +03:00
Alex Root Junior
4315ecf1a2
Dev 3.x flat package (#961)
* Move packages

* Added changelog

* Update examples/echo_bot.py

Co-authored-by: Oleg A. <t0rr@mail.ru>

* Rename `handler` -> `handlers`

* Update __init__.py

Co-authored-by: Oleg A. <t0rr@mail.ru>
2022-08-14 01:07:52 +03:00
Alex Root Junior
497436595d
[3.x] Bot API 6.0 (#890)
* Base implementation

* Bump license

* Revert re-generated tests

* Fix tests, improved docs

* Remove TODO

* Removed unreachable code

* Changed type of `last_synchronization_error_date`

* Fixed wrongly cleaned code
2022-04-19 22:03:24 +03:00
Alex Root Junior
286cf39c8a
Beta 3 (#884)
* Rework middlewares, separate management to `MiddlewareManager` class

* Rework middlewares

* Added changes description for redis

* Added changes description for redis

* Fixed tests with Redis // aioredis replacement

* Changed msg.<html/md>_text attributes behaviour

* Added changelog for spoilers

* Added possibility to get command magic result as handler arguments
2022-04-16 19:07:32 +03:00
Gabben
a37bbba38c
Fix docs and examples (#864)
* Update magic_data Allowed handlers

* Fix ChatMemberUpdated example

* Fix examples with `.in_(...)` and delete with `@`

* Fix commands in examples

* Change List to Set
2022-03-26 17:30:46 +02:00
Alex Root Junior
1634dc1162 Bump version, small changes in docs 2021-12-12 18:59:57 +02:00
Alex Root Junior
1c2c7fd88c
Webhook integration in 3.0 (#737)
* Added base webhook implementation and example
* Added example
* Enable on_startup callback
* Correctly handle response into webhook (silent call)
* Fixed State filter
2021-11-08 23:20:12 +02:00
Alex Root Junior
f97367b3ee More docs 2021-10-12 01:11:53 +03:00
Alex Root Junior
cfd2a9968e
Reworked handlers in use (#682)
* Reworked handlers in use util

* Added patch-notes
2021-09-07 01:04:33 +03:00
Alex Root Junior
e356ede5de
Updated pre-commit hook (#681)
* Updated pre-commit config and reformat code

* Added changelog
2021-09-07 00:32:43 +03:00
Forevka
125fc22ff9
Added ability to specify which update bot need to receive and process while using polling mode (#617)
* provide allowed_updates in polling mode
2021-07-05 01:41:27 +03:00
Alex Root Junior
79f21416c8 Added lost files 2021-05-25 01:00:58 +03:00
Alex Root Junior
f022b4441c Added more aliases, refactor CallbackData factory, added base exceptions classification mechanism 2021-05-25 00:56:44 +03:00
Alex Root Junior
4008a3114d
Upgrade architecture + 5.0 Bot API (#469)
Upgrade architecture + 5.0 Bot API (#469)
* Moved `methods`, `types` and `client` to root package
* Removed update handler from routers to dispatcher
* Reworked events propagation mechanism to handlers
* Reworked inner middlewares logic (very small change)
* Updated to Bot API 5.0
* Initial migration from MkDocs to Sphinx + config for readthedocs
2021-01-26 21:20:52 +02:00
jrootjunior
65815e509f Clean obsolete code and change configs 2019-11-15 12:44:24 +02:00
Alex Root Junior
87393f2475 Merge remote-tracking branch 'origin/dev-3.x' into dev-3.x
# Conflicts:
#	README.md
#	README.rst
#	aiogram/__init__.py
#	aiogram/bot/bot.py
#	aiogram/contrib/fsm_storage/redis.py
#	aiogram/contrib/middlewares/logging.py
#	aiogram/dispatcher/dispatcher.py
#	aiogram/dispatcher/filters/__init__.py
#	aiogram/dispatcher/filters/builtin.py
#	aiogram/dispatcher/filters/filters.py
#	aiogram/dispatcher/filters/state.py
#	aiogram/dispatcher/handler.py
#	aiogram/dispatcher/webhook.py
#	aiogram/types/base.py
#	aiogram/types/chat.py
#	aiogram/types/chat_member.py
#	aiogram/types/input_media.py
#	aiogram/types/message.py
#	aiogram/utils/callback_data.py
#	aiogram/utils/deprecated.py
#	aiogram/utils/exceptions.py
#	aiogram/utils/executor.py
#	aiogram/utils/helper.py
#	aiogram/utils/json.py
#	aiogram/utils/mixins.py
#	aiogram/utils/payload.py
#	dev_requirements.txt
#	docs/source/index.rst
#	examples/callback_data_factory.py
#	examples/check_user_language.py
#	examples/echo_bot.py
#	examples/finite_state_machine_example.py
#	examples/i18n_example.py
#	examples/inline_bot.py
#	examples/media_group.py
#	examples/middleware_and_antiflood.py
#	examples/payments.py
#	examples/proxy_and_emojize.py
#	examples/regexp_commands_filter_example.py
#	examples/throtling_example.py
#	examples/webhook_example.py
#	examples/webhook_example_2.py
#	setup.py
#	tests/test_bot.py
#	tests/test_token.py
#	tests/types/dataset.py
2019-11-03 22:19:44 +02:00
JR Minnaar
1cdfa3e3c2 Fix all occurrences of adwanced in text 2019-09-12 10:33:24 +02:00
Rossouw Minnaar
a74efa311e Fix spelling 2019-09-09 11:13:42 +02:00
birdi
ed0d4796e7 Merge branch 'dev-2.x' into add-new-ways-throttle
# Conflicts:
#	examples/throtling_example.py
2019-08-15 17:06:10 +03:00
Alex Root Junior
23ceb1445e
Merge branch 'dev-2.x' into dev-2.x 2019-08-15 16:52:51 +03:00
Suren Khorenyan
58a5da925a Refactor examples/webhook_example.py 2019-08-11 22:52:54 +03:00
Suren Khorenyan
251760a032 Rename webhook example 2019-08-11 22:51:50 +03:00
Suren Khorenyan
fdf3c44860 Rename old webhook example 2019-08-11 22:50:58 +03:00
Suren Khorenyan
94811c57e1 Minor refactor examples/text_filter_example.py and examples/throtling_example.py 2019-08-11 22:02:36 +03:00