init: Initial commit
This commit is contained in:
22
handler.py
22
handler.py
@@ -15,29 +15,27 @@ class BotHandler:
|
||||
self.bot = bot
|
||||
|
||||
async def messages(self, req: Request) -> Response:
|
||||
try:
|
||||
# Log incoming request
|
||||
print(f"[Handler] Received request at /api/messages")
|
||||
print(f"[Handler] Request method: {req.method}")
|
||||
print(f"[Handler] Content-Type: {req.headers.get('Content-Type', 'None')}")
|
||||
print(f"[Handler] Content-Length: {req.headers.get('Content-Length', 'None')}")
|
||||
|
||||
try:
|
||||
# Process the request - adapter will read the body
|
||||
print(f"[Handler] Processing request with adapter...")
|
||||
response = await self.adapter.process(req, self.bot)
|
||||
if response is not None:
|
||||
print(f"[Handler] Adapter returned response: {response.status}")
|
||||
return response
|
||||
print(f"[Handler] Adapter returned None, sending 204")
|
||||
return json_response(status=204)
|
||||
except Exception as e:
|
||||
print(f"[Handler] Error processing request: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return json_response(status=500)
|
||||
|
||||
async def api_test(self, req: Request) -> Response:
|
||||
try:
|
||||
body = await req.json()
|
||||
# Send a message with the bot to the channel
|
||||
self.bot.send_message(body.get("channel_id", "00000000-0000-0000-0000-000000000000"), body.get("message", "Hello, world!"))
|
||||
return json_response(status=200, data={"message": "Message sent successfully"})
|
||||
except Exception as e:
|
||||
return json_response(status=500, data={"message": "Error sending message"})
|
||||
|
||||
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.")
|
||||
|
||||
Reference in New Issue
Block a user