File size: 2,433 Bytes
b28ce06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
60
61
62
63
64
65
#!/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()