-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrunks.py
More file actions
64 lines (54 loc) · 2.08 KB
/
Copy pathtrunks.py
File metadata and controls
64 lines (54 loc) · 2.08 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
import uuid
from client_factory import create_client
from didww.enums import Codec, ReroutingDisconnectCode, TransportProtocol
from didww.resources.voice_in_trunk import VoiceInTrunk
from didww.resources.configuration.sip import SipConfiguration
from didww.resources.configuration.pstn import PstnConfiguration
from didww.exceptions import DidwwApiError
client = create_client()
suffix = uuid.uuid4().hex[:8]
# --- Create SIP trunk ---
sip = SipConfiguration()
sip.username = "username"
sip.host = "203.0.113.110"
sip.port = 5060
sip.codec_ids = [Codec.PCMU, Codec.PCMA]
sip.transport_protocol_id = TransportProtocol.UDP
sip.rerouting_disconnect_code_ids = [
ReroutingDisconnectCode.SIP_480_TEMPORARILY_UNAVAILABLE,
ReroutingDisconnectCode.SIP_503_SERVICE_UNAVAILABLE,
]
trunk = VoiceInTrunk()
trunk.name = f"My New SIP Trunk {suffix}"
trunk.configuration = sip
trunk.ringing_timeout = 30
try:
created = client.voice_in_trunks().create(trunk).data
print(f"Created SIP trunk: {created.id}")
print(f" Name: {created.name}")
print(f" Config type: {created.configuration._type}")
print(f" Created at: {created.created_at}")
print(f" Ringing timeout: {created.ringing_timeout}")
client.voice_in_trunks().delete(created.id)
print(f" Deleted trunk {created.id}")
except DidwwApiError as e:
print(f"API error (HTTP {e.status_code}): {e}")
# --- Create PSTN trunk ---
pstn = PstnConfiguration()
pstn.dst = "12125551234"
trunk = VoiceInTrunk()
trunk.name = f"My New PSTN Trunk {suffix}"
trunk.configuration = pstn
trunk.ringing_timeout = 30
try:
created = client.voice_in_trunks().create(trunk).data
print(f"\nCreated PSTN trunk: {created.id}")
print(f" Name: {created.name}")
print(f" Config type: {created.configuration._type}")
print(f" DST: {created.configuration.dst}")
print(f" Created at: {created.created_at}")
print(f" Ringing timeout: {created.ringing_timeout}")
client.voice_in_trunks().delete(created.id)
print(f" Deleted trunk {created.id}")
except DidwwApiError as e:
print(f"API error (HTTP {e.status_code}): {e}")