Skip to content

Commit

Permalink
add aiogram example
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanKirpichnikov committed Oct 18, 2024
1 parent 8524b7f commit bc891fd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
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
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"
{!> docs_src/integrations/no_http_frameworks_integrations/aiogram.py !}
```

0 comments on commit bc891fd

Please sign in to comment.