diff --git a/docs/docs/en/getting-started/integrations/frameworks/index.md b/docs/docs/en/getting-started/integrations/frameworks/index.md index fcb09ce7f2..d6fe094465 100644 --- a/docs/docs/en/getting-started/integrations/frameworks/index.md +++ b/docs/docs/en/getting-started/integrations/frameworks/index.md @@ -9,6 +9,7 @@ search: # template variables fastapi_plugin: If you want to use **FastStream** in conjunction with **FastAPI**, perhaps you should use a special [plugin](../fastapi/index.md){.internal-link} no_hook: However, even if such a hook is not provided, you can do it yourself. +and_not_only_http: And not only HTTP frameworks. --- # INTEGRATIONS diff --git a/docs/docs/en/public_api b/docs/docs/en/public_api index b14a93fe9e..2c417d1ba5 120000 --- a/docs/docs/en/public_api +++ b/docs/docs/en/public_api @@ -1 +1 @@ -./api/ \ No newline at end of file +./api/ diff --git a/docs/docs_src/integrations/no_http_frameworks_integrations/__init__.py b/docs/docs_src/integrations/no_http_frameworks_integrations/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/docs_src/integrations/no_http_frameworks_integrations/aiogram.py b/docs/docs_src/integrations/no_http_frameworks_integrations/aiogram.py new file mode 100644 index 0000000000..94d8cc7aae --- /dev/null +++ b/docs/docs_src/integrations/no_http_frameworks_integrations/aiogram.py @@ -0,0 +1,34 @@ +import asyncio + +from aiogram import Bot, Dispatcher +from aiogram.types import Message + +from faststream.nats import NatsBroker + +bot = Bot("") +dispatcher = Dispatcher() +broker = NatsBroker() + +@broker.subscriber("echo") +async def echo_faststream_handler(data: dict[str, str]) -> None: + await bot.copy_message(**data) + + +@dispatcher.message() +async def echo_aiogram_handler(event: Message) -> None: + await broker.publish( + subject="echo", + message={ + "chat_id": event.chat.id, + "message_id": event.message_id, + "from_chat_id": event.chat.id, + }, + ) + + +async def main() -> None: + async with broker: + await broker.start() + await dispatcher.start_polling(bot) + +asyncio.run(main()) diff --git a/docs/includes/getting_started/integrations/http/1.md b/docs/includes/getting_started/integrations/http/1.md index 6c6d58e0c0..d124345ce4 100644 --- a/docs/includes/getting_started/integrations/http/1.md +++ b/docs/includes/getting_started/integrations/http/1.md @@ -42,3 +42,10 @@ ```python linenums="1" hl_lines="5 7 10-12 32-36" {!> docs_src/integrations/http_frameworks_integrations/tornado.py !} ``` + +{{ and_not_only_http }} + +=== "Aiogram" + ```python linenums="1" hl_lines="6 10 12-14 30-31" + {!> docs_src/integrations/no_http_frameworks_integrations/aiogram.py !} + ``` diff --git a/pyproject.toml b/pyproject.toml index ab16c4da01..7867cfc450 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -115,6 +115,7 @@ types = [ "types-redis", "types-Pygments", "types-docutils", + "types-aiofiles", "confluent-kafka-stubs; python_version >= '3.11'", ]