Skip to content

Commit

Permalink
add aiogram example (#1858)
Browse files Browse the repository at this point in the history
* add aiogram example

* add highlighting lines

* add types-aiofiles in types optional dependencies

* run pre-commit
  • Loading branch information
IvanKirpichnikov authored Oct 18, 2024
1 parent 8524b7f commit e9580ba
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/en/public_api
Empty file.
Original file line number Diff line number Diff line change
@@ -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())
7 changes: 7 additions & 0 deletions docs/includes/getting_started/integrations/http/1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 !}
```
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ types = [
"types-redis",
"types-Pygments",
"types-docutils",
"types-aiofiles",
"confluent-kafka-stubs; python_version >= '3.11'",
]

Expand Down

0 comments on commit e9580ba

Please sign in to comment.