-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_bot.py
More file actions
54 lines (36 loc) · 1.18 KB
/
basic_bot.py
File metadata and controls
54 lines (36 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Basic example: existing aiogram bot + aiogram-mcp running side by side."""
from __future__ import annotations
import asyncio
import logging
import os
from aiogram import Bot, Dispatcher, F
from aiogram.filters import CommandStart
from aiogram.types import Message
from aiogram_mcp import AiogramMCP, EventManager, MCPMiddleware
logging.basicConfig(level=logging.INFO)
BOT_TOKEN = os.environ["BOT_TOKEN"]
bot = Bot(token=BOT_TOKEN)
dp = Dispatcher()
event_manager = EventManager()
mcp_middleware = MCPMiddleware(event_manager=event_manager)
dp.message.middleware(mcp_middleware)
dp.callback_query.middleware(mcp_middleware)
@dp.message(CommandStart())
async def cmd_start(message: Message) -> None:
await message.answer(
"Hello! This bot is running normally, and it is also exposed over MCP."
)
@dp.message(F.text)
async def echo(message: Message) -> None:
await message.answer(f"You said: {message.text}")
mcp = AiogramMCP(
bot=bot,
dp=dp,
name="my-telegram-bot",
middleware=mcp_middleware,
event_manager=event_manager,
)
async def main() -> None:
await mcp.run_alongside_bot(transport="stdio")
if __name__ == "__main__":
asyncio.run(main())