-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add aiogram example * add highlighting lines * add types-aiofiles in types optional dependencies * run pre-commit
- Loading branch information
1 parent
8524b7f
commit e9580ba
Showing
6 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
./api/ | ||
./api/ |
Empty file.
34 changes: 34 additions & 0 deletions
34
docs/docs_src/integrations/no_http_frameworks_integrations/aiogram.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters