from botbuilder.core.integration import aiohttp_error_middleware from botbuilder.integration.aiohttp import CloudAdapter, ConfigurationBotFrameworkAuthentication from aiohttp import web from aiohttp.web import Application from bot import WebhookBot from handler import BotHandler from config import DefaultConfig from modules.database import DatabaseManager, SQLiteConnectionString from dotenv import load_dotenv load_dotenv() CONFIG = DefaultConfig() connection_string = SQLiteConnectionString(CONFIG.DB_PATH) DATABASE = DatabaseManager(connection_string) ADAPTER = CloudAdapter(ConfigurationBotFrameworkAuthentication(CONFIG)) # Register error handler async def on_error(context, error): import traceback traceback.print_exc() await context.send_activity("An error occurred processing your request.") ADAPTER.on_turn_error = on_error BOT = WebhookBot(CONFIG, DATABASE) BOT_HANDLER = BotHandler(ADAPTER, BOT, CONFIG) APP = Application() APP.router.add_post("/api/messages", BOT_HANDLER.messages) web.run_app(APP, host=CONFIG.HOST, port=CONFIG.PORT)