#!/usr/bin/env python3 """ Test script to verify the FastAPI Telegram Bot deployment """ import httpx import sys def test_health_endpoint(): """Test the health check endpoint""" try: response = httpx.get('http://localhost:7860/health', timeout=10) if response.status_code == 200: data = response.json() print("✅ Health Check: PASSED") print(f" Status: {data.get('status')}") print(f" Message: {data.get('message')}") return True else: print(f"❌ Health Check: FAILED (Status: {response.status_code})") return False except Exception as e: print(f"❌ Health Check: FAILED (Error: {e})") return False def test_sendmessage_endpoint(): """Test the sendmessage endpoint (will fail with invalid chat ID, but shows it's working)""" try: response = httpx.get('http://localhost:7860/sendmessage?log=123456789&msg=Test', timeout=10) if response.status_code == 500 and "PEER_ID_INVALID" in response.text: print("✅ SendMessage Endpoint: WORKING (Expected error with invalid chat ID)") return True elif response.status_code == 200: print("✅ SendMessage Endpoint: WORKING (Message sent successfully)") return True else: print(f"❌ SendMessage Endpoint: UNEXPECTED RESPONSE (Status: {response.status_code})") print(f" Response: {response.text}") return False except Exception as e: print(f"❌ SendMessage Endpoint: FAILED (Error: {e})") return False def main(): print("🚀 Testing FastAPI Telegram Bot Deployment") print("=" * 50) health_ok = test_health_endpoint() sendmsg_ok = test_sendmessage_endpoint() print("\n" + "=" * 50) if health_ok and sendmsg_ok: print("🎉 DEPLOYMENT TEST: ALL PASSED") print("\nYour FastAPI Telegram Bot is ready for production!") print("\nNext steps:") print("1. Test your bot by sending /start to it on Telegram") print("2. Use the /sendmessage API with real chat IDs") print("3. Monitor logs with: docker-compose logs -f") sys.exit(0) else: print("❌ DEPLOYMENT TEST: SOME TESTS FAILED") sys.exit(1) if __name__ == "__main__": main()