-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcreate_campaign.py
More file actions
75 lines (54 loc) · 1.96 KB
/
Copy pathcreate_campaign.py
File metadata and controls
75 lines (54 loc) · 1.96 KB
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
66
67
68
69
70
71
72
73
74
75
"""
Create Campaign Script
Creates an outbound campaign linking agent, audience, and phone numbers.
Usage:
python create_campaign.py
"""
import os
from dotenv import load_dotenv
from smallestai.atoms import Campaign, AtomsClient
load_dotenv()
def main():
"""Create an outbound campaign."""
# Get required IDs from environment
agent_id = os.getenv("AGENT_ID")
audience_id = os.getenv("AUDIENCE_ID")
if not agent_id:
print("Error: AGENT_ID not set. Create an agent first.")
return
if not audience_id:
print("Error: AUDIENCE_ID not set. Run create_audience.py first.")
return
# Get available phone numbers
client = AtomsClient()
phone_numbers = client.get_phone_numbers()
if not phone_numbers.get("data"):
print("Error: No phone numbers available. Acquire a number first.")
return
# Use the first available phone number
phone_id = phone_numbers["data"][0]["_id"]
phone_display = phone_numbers["data"][0]["attributes"]["phoneNumber"]
print(f"Using phone number: {phone_display}")
# Create campaign
campaign = Campaign()
print("Creating campaign...")
result = campaign.create(
name="Demo Outbound Campaign",
agent_id=agent_id,
audience_id=audience_id,
phone_ids=[phone_id],
description="Demo campaign for testing",
max_retries=3, # Retry up to 3 times if no answer
retry_delay=15 # Wait 15 minutes between retries
)
campaign_id = result["data"]["_id"]
print(f"✓ Campaign created: {campaign_id}")
# Save for later use
env_path = os.path.join(os.path.dirname(__file__), ".env")
with open(env_path, "a") as f:
f.write(f"CAMPAIGN_ID={campaign_id}\n")
print(f"✓ CAMPAIGN_ID saved to .env")
print(f"\nNext: Run start_campaign.py to start dialing")
return campaign_id
if __name__ == "__main__":
main()