Files
teams-sample-bot/handler.py
2025-11-18 15:24:36 +01:00

31 lines
1.0 KiB
Python

from botbuilder.core import TurnContext
from botbuilder.integration.aiohttp import CloudAdapter
from aiohttp.web import Request, Response, json_response
from bot import WebhookBot
from config import DefaultConfig
import sys
import traceback
class BotHandler:
def __init__(self, adapter: CloudAdapter, bot: WebhookBot, config: DefaultConfig) -> None:
self.adapter = adapter
self.bot = bot
async def messages(self, req: Request) -> Response:
response = await self.adapter.process(req, self.bot)
if response is not None:
return response
return json_response(status=204)
async def on_error(self, context: TurnContext, error: Exception) -> None:
print(f"\n [on_turn_error] unhandled error: {error}", file=sys.stderr)
traceback.print_exc()
await context.send_activity("The bot encountered an error or bug.")
await context.send_activity(
"To continue to run this bot, please fix the bot source code."
)
return