Repository navigation
Expand file tree
/
Copy pathrest_manage_resources.py
More file actions
58 lines (46 loc) · 1.82 KB
/
Copy pathrest_manage_resources.py
File metadata and controls
58 lines (46 loc) · 1.82 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
"""Example: Create an AI agent, assign a phone number, and place a test call.
Set these env vars (or pass them directly to RestClient):
SIGNALWIRE_PROJECT_ID - your SignalWire project ID
SIGNALWIRE_API_TOKEN - your SignalWire API token
SIGNALWIRE_SPACE - your SignalWire space (e.g. example.signalwire.com)
For full HTTP debug output:
SIGNALWIRE_LOG_LEVEL=debug
"""
from signalwire.rest import RestClient, SignalWireRestError
client = RestClient()
def main():
# 1. Create an AI agent
print("Creating AI agent...")
agent = client.fabric.ai_agents.create(
name="Demo Support Bot",
prompt={"text": "You are a friendly support agent for Acme Corp."},
)
agent_id = agent["id"]
print(f" Created agent: {agent_id}")
# 2. List all AI agents
print("\nListing AI agents...")
agents = client.fabric.ai_agents.list()
for a in agents.get("data", []):
print(f" - {a['id']}: {a.get('name', 'unnamed')}")
# 3. Search for a phone number
print("\nSearching for available phone numbers...")
available = client.phone_numbers.search(areacode="512", max_results=3)
for num in available.get("data", []):
print(f" - {num.get('e164', num.get('number', 'unknown'))}")
# 4. Place a test call (requires valid numbers)
print("\nPlacing a test call...")
try:
result = client.calling.dial(
from_="+15559876543",
to="+15551234567",
url="https://example.com/call-handler",
)
print(f" Call initiated: {result}")
except SignalWireRestError as e:
print(f" Call failed (expected in demo): {e.status_code}")
# 5. Clean up: delete the agent
print(f"\nDeleting agent {agent_id}...")
client.fabric.ai_agents.delete(agent_id)
print(" Deleted.")
if __name__ == "__main__":
main()