Skip to content

Commit 1f89d5e

Browse files
committed
docs: Update documentation for new dial/create_call API
- Updated __init__.py docstring with simple and advanced examples - Updated README.md Quick Start and Call section - Updated examples/README.md with advanced_call.py documentation
1 parent 289bec3 commit 1f89d5e

3 files changed

Lines changed: 79 additions & 11 deletions

File tree

PySIP/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
A modern, asyncio-based SIP/VoIP library for Python.
55
6-
Example (with context manager):
6+
Example (simple - context manager):
77
from PySIP import SIPClient
88
99
async with SIPClient(
@@ -13,13 +13,14 @@
1313
) as client:
1414
await client.register()
1515
16+
# dial() returns a Call that auto-connects and auto-hangups
1617
async with client.dial("sip:bob@example.com") as call:
1718
await call.say("Hello!")
1819
result = await call.gather(max_digits=4, timeout=10)
1920
print(f"Got digits: {result.digits}")
2021
# Auto-hangup when exiting
2122
22-
Example (manual control):
23+
Example (advanced - configure before connecting):
2324
from PySIP import SIPClient
2425
2526
async with SIPClient(
@@ -29,8 +30,15 @@
2930
) as client:
3031
await client.register()
3132
32-
call = client.dial("sip:bob@example.com")
33-
await call.dial() # Start the call
33+
# create_call() returns unconfigured Call for advanced setup
34+
call = client.create_call("sip:bob@example.com")
35+
call.set_caller_id("sip:support@company.com")
36+
call.set_display_name("Support Line")
37+
call.add_header("X-Campaign-ID", "promo123")
38+
call.set_codecs(["pcmu", "pcma"])
39+
call.on("ringing", lambda: print("Ringing..."))
40+
41+
await call.connect() # Now connect
3442
await call.say("Hello!")
3543
await call.hangup()
3644
"""

README.md

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ async def main():
9292
asyncio.run(main())
9393
```
9494

95-
### Manual Call Control
95+
### Advanced Call Configuration
9696

9797
```python
9898
import asyncio
@@ -106,10 +106,26 @@ async def main():
106106
) as client:
107107
await client.register()
108108

109-
# Create and dial manually
110-
call = client.dial("1234567890")
111-
await call.dial() # Start the call
109+
# Create call and configure before connecting
110+
call = client.create_call("1234567890")
112111

112+
# Configure call identity
113+
call.set_caller_id("sip:support@company.com")
114+
call.set_display_name("Support Line")
115+
116+
# Add custom SIP headers
117+
call.add_header("X-Campaign-ID", "promo123")
118+
call.add_header("X-Account-ID", "12345")
119+
120+
# Set codec preferences
121+
call.set_codecs(["pcmu", "pcma"])
122+
123+
# Set up event handlers
124+
call.on("ringing", lambda: print("Ringing..."))
125+
call.on("answered", lambda: print("Connected!"))
126+
127+
# Now connect
128+
await call.connect()
113129
await call.say("Hello!")
114130
await call.hangup()
115131

@@ -247,9 +263,15 @@ async with client.dial("destination") as call:
247263
await call.say("Hello!")
248264
# Auto-hangup on exit
249265

250-
# Or manual control
251-
call = client.dial("destination")
252-
await call.dial(timeout=60)
266+
# Advanced: Configure before connecting
267+
call = client.create_call("destination")
268+
call.set_caller_id("sip:support@company.com") # Override From URI
269+
call.set_display_name("Support Line") # Caller display name
270+
call.add_header("X-Campaign", "promo") # Custom SIP headers
271+
call.set_codecs(["pcmu", "pcma"]) # Codec preference
272+
call.set_timeout(30) # Connection timeout
273+
call.on("ringing", on_ring_handler) # Event callbacks
274+
await call.connect()
253275

254276
# Media operations
255277
await call.say("Hello!") # TTS
@@ -260,13 +282,16 @@ await call.send_dtmf("1234") # Send DTMF
260282
# Call control
261283
await call.hold() # Put on hold
262284
await call.unhold() # Resume
285+
await call.mute() # Mute microphone
286+
await call.unmute() # Unmute
263287
await call.hangup()
264288
await call.transfer("other@example.com")
265289

266290
# Properties
267291
call.state # CallState enum
268292
call.call_id # SIP Call-ID
269293
call.duration # Call duration in seconds
294+
call.is_active # True if call is active
270295
```
271296

272297
### Error Handling

examples/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ python examples/basic_call.py --help
5656
| Script | Description |
5757
|--------|-------------|
5858
| `basic_call.py` | Simple outbound call with TTS greeting |
59+
| `advanced_call.py` | Advanced call with custom headers, caller ID, codecs |
5960
| `ivr_menu.py` | Incoming call handler with IVR menu |
6061
| `gather_pin.py` | DTMF collection and PIN validation |
6162
| `record_call.py` | Call recording to WAV file |
@@ -78,6 +79,40 @@ python examples/basic_call.py --to 1234567890 --message "Hello from PySIP!"
7879
python examples/basic_call.py --help
7980
```
8081

82+
### advanced_call.py - Advanced Call Configuration
83+
84+
Demonstrates power-user features:
85+
- Custom caller ID and display name
86+
- Custom SIP headers
87+
- Codec preferences
88+
- Event callbacks (ringing, answered, hangup)
89+
90+
```bash
91+
# With custom caller ID and display name
92+
python examples/advanced_call.py --to 123 \
93+
--caller-id "sip:sales@company.com" \
94+
--display-name "Sales Team"
95+
96+
# With custom SIP headers
97+
python examples/advanced_call.py --to 123 \
98+
--header "X-Campaign-ID:promo2024" \
99+
--header "X-Account-ID:12345"
100+
101+
# With codec preferences and timeout
102+
python examples/advanced_call.py --to 123 \
103+
--codecs "pcmu,pcma" \
104+
--timeout 45
105+
106+
# Full example with all options
107+
python examples/advanced_call.py --to 123 \
108+
--caller-id "sip:support@company.com" \
109+
--display-name "Support Line" \
110+
--header "X-Priority:high" \
111+
--codecs "pcmu" \
112+
--timeout 30 \
113+
--user-agent "MyApp/1.0"
114+
```
115+
81116
### ivr_menu.py - IVR Menu Server
82117

83118
Registers with the SIP server and handles incoming calls with an interactive menu:

0 commit comments

Comments
 (0)