|
1 | 1 | import os |
| 2 | +import subprocess |
| 3 | +import sys |
2 | 4 |
|
3 | 5 | from devo_global_comms_python import DevoClient, DevoException |
4 | 6 |
|
5 | 7 |
|
6 | 8 | def main(): |
7 | | - # Initialize the client with your API key |
8 | | - # You can get your API key from the Devo dashboard |
| 9 | + print("🚀 Devo Global Communications SDK") |
| 10 | + print("=" * 60) |
| 11 | + |
| 12 | + # Check if API key is set |
9 | 13 | api_key = os.getenv("DEVO_API_KEY") |
10 | 14 | if not api_key: |
11 | | - print("Please set DEVO_API_KEY environment variable") |
| 15 | + print("❌ Please set DEVO_API_KEY environment variable") |
| 16 | + print(" You can get your API key from the Devo dashboard") |
| 17 | + return |
| 18 | + |
| 19 | + # Initialize the client |
| 20 | + try: |
| 21 | + client = DevoClient(api_key=api_key) |
| 22 | + print("✅ Devo SDK Client initialized successfully") |
| 23 | + except Exception as e: |
| 24 | + print(f"❌ Failed to initialize client: {e}") |
12 | 25 | return |
13 | 26 |
|
14 | | - client = DevoClient(api_key=api_key) |
| 27 | + print("\n📋 Available Resources:") |
| 28 | + print("-" * 30) |
| 29 | + |
| 30 | + # Check available resources |
| 31 | + resources = [] |
| 32 | + if hasattr(client, "sms"): |
| 33 | + resources.append(("📱 SMS", "Implemented", "sms_example.py")) |
| 34 | + if hasattr(client, "email"): |
| 35 | + resources.append(("📧 Email", "Placeholder", "email_example.py")) |
| 36 | + if hasattr(client, "whatsapp"): |
| 37 | + resources.append(("💬 WhatsApp", "Placeholder", "whatsapp_example.py")) |
| 38 | + if hasattr(client, "contacts"): |
| 39 | + resources.append(("👥 Contacts", "Placeholder", "contacts_example.py")) |
| 40 | + if hasattr(client, "rcs"): |
| 41 | + resources.append(("🎴 RCS", "Placeholder", "rcs_example.py")) |
| 42 | + |
| 43 | + for resource, status, example_file in resources: |
| 44 | + print(f" {resource:<12} - {status:<12} -> {example_file}") |
| 45 | + |
| 46 | + # Quick SMS test if available |
| 47 | + if hasattr(client, "sms"): |
| 48 | + print("\n🧪 Quick SMS Test:") |
| 49 | + print("-" * 30) |
| 50 | + try: |
| 51 | + # Try to get senders as a connectivity test |
| 52 | + senders = client.sms.get_senders() |
| 53 | + print(f"✅ SMS connection successful - {len(senders.senders)} senders available") |
| 54 | + |
| 55 | + if senders.senders: |
| 56 | + print(" Sample senders:") |
| 57 | + for i, sender in enumerate(senders.senders[:3], 1): |
| 58 | + print(f" {i}. {sender.phone_number} ({sender.type})") |
| 59 | + if len(senders.senders) > 3: |
| 60 | + print(f" ... and {len(senders.senders) - 3} more") |
| 61 | + |
| 62 | + except DevoException as e: |
| 63 | + print(f"⚠️ SMS connection test failed: {e}") |
| 64 | + |
| 65 | + # Show example usage |
| 66 | + print("\n💡 Getting Started:") |
| 67 | + print("-" * 30) |
| 68 | + print("1. Run individual resource examples:") |
| 69 | + print(" python examples/sms_example.py # Complete SMS functionality") |
| 70 | + print(" python examples/email_example.py # Email examples (placeholder)") |
| 71 | + print(" python examples/whatsapp_example.py # WhatsApp examples (placeholder)") |
| 72 | + print(" python examples/contacts_example.py # Contact management (placeholder)") |
| 73 | + print(" python examples/rcs_example.py # RCS examples (placeholder)") |
| 74 | + print() |
| 75 | + print("2. Quick SMS example:") |
| 76 | + print(" from devo_global_comms_python import DevoClient") |
| 77 | + print(" client = DevoClient(api_key='your_api_key')") |
| 78 | + print(" response = client.sms.send_sms(") |
| 79 | + print(" recipient='+1234567890',") |
| 80 | + print(" message='Hello from Devo!',") |
| 81 | + print(" sender='your_sender_id'") |
| 82 | + print(" )") |
| 83 | + |
| 84 | + # Interactive menu |
| 85 | + print("\n🎯 Interactive Examples:") |
| 86 | + print("-" * 30) |
| 87 | + print("Would you like to run a specific example?") |
| 88 | + print("1. SMS Example (full functionality)") |
| 89 | + print("2. Email Example (placeholder)") |
| 90 | + print("3. WhatsApp Example (placeholder)") |
| 91 | + print("4. Contacts Example (placeholder)") |
| 92 | + print("5. RCS Example (placeholder)") |
| 93 | + print("0. Exit") |
15 | 94 |
|
16 | 95 | try: |
17 | | - # Example 1: Send an SMS |
18 | | - print("Sending SMS...") |
19 | | - sms = client.sms.send( |
20 | | - to="+1234567890", # Replace with actual phone number |
21 | | - body="Hello from Devo SDK! This is a test SMS message.", |
22 | | - ) |
23 | | - print(f"SMS sent successfully! Message SID: {sms.sid}") |
24 | | - print(f"Status: {sms.status}") |
25 | | - |
26 | | - # Example 2: Send an email |
27 | | - print("\nSending email...") |
28 | | - email = client.email.send( |
29 | | - to="recipient@example.com", # Replace with actual email |
30 | | - subject="Test Email from Devo SDK", |
31 | | - body="This is a test email sent using the Devo Global Communications SDK.", |
32 | | - html_body="<h1>Test Email</h1><p>This is a <strong>test email</strong> sent using the Devo SDK.</p>", |
33 | | - ) |
34 | | - print(f"Email sent successfully! Message ID: {email.id}") |
35 | | - print(f"Status: {email.status}") |
36 | | - |
37 | | - # Example 3: Send a WhatsApp message |
38 | | - print("\nSending WhatsApp message...") |
39 | | - whatsapp = client.whatsapp.send_text( |
40 | | - to="+1234567890", # Replace with actual WhatsApp number |
41 | | - text="Hello from Devo SDK! This is a WhatsApp message.", |
42 | | - ) |
43 | | - print(f"WhatsApp message sent successfully! Message ID: {whatsapp.id}") |
44 | | - print(f"Status: {whatsapp.status}") |
45 | | - |
46 | | - # Example 4: Create a contact |
47 | | - print("\nCreating contact...") |
48 | | - contact = client.contacts.create( |
49 | | - phone_number="+1234567890", |
50 | | - email="contact@example.com", |
51 | | - first_name="John", |
52 | | - last_name="Doe", |
53 | | - company="Example Corp", |
54 | | - metadata={"source": "sdk_example"}, |
55 | | - ) |
56 | | - print(f"Contact created successfully! Contact ID: {contact.id}") |
57 | | - print(f"Name: {contact.first_name} {contact.last_name}") |
58 | | - |
59 | | - # Example 5: List recent messages |
60 | | - print("\nListing recent messages...") |
61 | | - messages = client.messages.list(limit=5, date_sent_after="2024-01-01") |
62 | | - print(f"Found {len(messages)} recent messages:") |
63 | | - for message in messages: |
64 | | - print(f" - {message.channel}: {message.id} ({message.status})") |
65 | | - |
66 | | - except DevoException as e: |
67 | | - print(f"Error: {e}") |
| 96 | + choice = input("\nEnter your choice (0-5): ").strip() |
| 97 | + example_files = { |
| 98 | + "1": "sms_example.py", |
| 99 | + "2": "email_example.py", |
| 100 | + "3": "whatsapp_example.py", |
| 101 | + "4": "contacts_example.py", |
| 102 | + "5": "rcs_example.py", |
| 103 | + } |
| 104 | + |
| 105 | + if choice in example_files: |
| 106 | + example_file = example_files[choice] |
| 107 | + example_path = os.path.join(os.path.dirname(__file__), example_file) |
| 108 | + |
| 109 | + if os.path.exists(example_path): |
| 110 | + print(f"\n🚀 Running {example_file}...") |
| 111 | + print("=" * 60) |
| 112 | + subprocess.run([sys.executable, example_path], check=True) |
| 113 | + else: |
| 114 | + print(f"❌ Example file {example_file} not found") |
| 115 | + elif choice == "0": |
| 116 | + print("👋 Goodbye!") |
| 117 | + else: |
| 118 | + print("❌ Invalid choice") |
| 119 | + |
| 120 | + except KeyboardInterrupt: |
| 121 | + print("\n👋 Goodbye!") |
| 122 | + except Exception as e: |
| 123 | + print(f"❌ Error running example: {e}") |
68 | 124 |
|
69 | 125 |
|
70 | 126 | if __name__ == "__main__": |
|
0 commit comments