-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.py
More file actions
589 lines (477 loc) · 18.8 KB
/
Copy pathclient.py
File metadata and controls
589 lines (477 loc) · 18.8 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
# This file was auto-generated by Fern from our API Definition.
import typing
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from .raw_client import AsyncRawPhoneNumbersClient, RawPhoneNumbersClient
from .types.add_phone_numbers_request_inbound_config import AddPhoneNumbersRequestInboundConfig
from .types.add_phone_numbers_request_outbound_config import AddPhoneNumbersRequestOutboundConfig
from .types.add_phone_numbers_request_provider import AddPhoneNumbersRequestProvider
from .types.add_phone_numbers_response import AddPhoneNumbersResponse
from .types.get_phone_numbers_response import GetPhoneNumbersResponse
from .types.list_phone_numbers_response_item import ListPhoneNumbersResponseItem
from .types.update_phone_numbers_request_inbound_config import UpdatePhoneNumbersRequestInboundConfig
from .types.update_phone_numbers_request_outbound_config import UpdatePhoneNumbersRequestOutboundConfig
from .types.update_phone_numbers_response import UpdatePhoneNumbersResponse
# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)
class PhoneNumbersClient:
def __init__(self, *, client_wrapper: SyncClientWrapper):
self._raw_client = RawPhoneNumbersClient(client_wrapper=client_wrapper)
@property
def with_raw_response(self) -> RawPhoneNumbersClient:
"""
Retrieves a raw implementation of this client that returns raw responses.
Returns
-------
RawPhoneNumbersClient
"""
return self._raw_client
def list(
self, *, request_options: typing.Optional[RequestOptions] = None
) -> typing.List[ListPhoneNumbersResponseItem]:
"""
Retrieve a list of all imported phone numbers under the current account.
Parameters
----------
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
typing.List[ListPhoneNumbersResponseItem]
Request was successful. The response body contains a JSON array of phone number configurations.
Examples
--------
from agora_agent import Agora
client = Agora(
authorization="YOUR_AUTHORIZATION",
username="YOUR_USERNAME",
password="YOUR_PASSWORD",
)
client.phone_numbers.list()
"""
_response = self._raw_client.list(request_options=request_options)
return _response.data
def add(
self,
*,
provider: AddPhoneNumbersRequestProvider,
phone_number: str,
label: str,
inbound_config: AddPhoneNumbersRequestInboundConfig,
outbound_config: AddPhoneNumbersRequestOutboundConfig,
inbound: typing.Optional[bool] = OMIT,
outbound: typing.Optional[bool] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> AddPhoneNumbersResponse:
"""
Import a pre-configured phone number that can be used for inbound or outbound calls.
Parameters
----------
provider : AddPhoneNumbersRequestProvider
Number provider:
- `byo`: BYO (Bring Your Own)
- `twilio`: Twilio
phone_number : str
Telephone number in E.164 format.
label : str
A label used to identify the number.
inbound_config : AddPhoneNumbersRequestInboundConfig
SIP inbound call configuration.
outbound_config : AddPhoneNumbersRequestOutboundConfig
SIP outbound call configuration.
inbound : typing.Optional[bool]
Whether the number supports inbound calls.
outbound : typing.Optional[bool]
Whether the number supports outbound calls.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AddPhoneNumbersResponse
Request was successful. The response body contains the result of the request.
Examples
--------
from agora_agent import Agora
from agora_agent.phone_numbers import (
AddPhoneNumbersRequestInboundConfig,
AddPhoneNumbersRequestOutboundConfig,
)
client = Agora(
authorization="YOUR_AUTHORIZATION",
username="YOUR_USERNAME",
password="YOUR_PASSWORD",
)
client.phone_numbers.add(
provider="byo",
phone_number="+19876543210",
label="Sales Hotline",
inbound=True,
outbound=True,
inbound_config=AddPhoneNumbersRequestInboundConfig(
allowed_addresses=["112.126.15.64/27"],
),
outbound_config=AddPhoneNumbersRequestOutboundConfig(
address="xxx:xxx@sip.example.com",
transport="tls",
),
)
"""
_response = self._raw_client.add(
provider=provider,
phone_number=phone_number,
label=label,
inbound_config=inbound_config,
outbound_config=outbound_config,
inbound=inbound,
outbound=outbound,
request_options=request_options,
)
return _response.data
def get(
self, phone_number: str, *, request_options: typing.Optional[RequestOptions] = None
) -> GetPhoneNumbersResponse:
"""
Retrieve detailed information for a specific phone number.
Parameters
----------
phone_number : str
Telephone number in E.164 format. For example, +11234567890.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
GetPhoneNumbersResponse
Request was successful. The response body contains the result of the request.
Examples
--------
from agora_agent import Agora
client = Agora(
authorization="YOUR_AUTHORIZATION",
username="YOUR_USERNAME",
password="YOUR_PASSWORD",
)
client.phone_numbers.get(
phone_number="phone_number",
)
"""
_response = self._raw_client.get(phone_number, request_options=request_options)
return _response.data
def delete(self, phone_number: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
"""
Remove an imported phone number from the system.
After calling this endpoint, the number stops receiving calls routed through this system. To delete the number from the service provider, remove it in the service provider's console.
> This operation only removes the number configuration from the Agora system; the number stored with the phone service provider is not deleted.
Parameters
----------
phone_number : str
Telephone number in E.164 format. For example, +11234567890.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
None
Examples
--------
from agora_agent import Agora
client = Agora(
authorization="YOUR_AUTHORIZATION",
username="YOUR_USERNAME",
password="YOUR_PASSWORD",
)
client.phone_numbers.delete(
phone_number="phone_number",
)
"""
_response = self._raw_client.delete(phone_number, request_options=request_options)
return _response.data
def update(
self,
phone_number: str,
*,
inbound_config: typing.Optional[UpdatePhoneNumbersRequestInboundConfig] = OMIT,
outbound_config: typing.Optional[UpdatePhoneNumbersRequestOutboundConfig] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> UpdatePhoneNumbersResponse:
"""
Update the configuration for a phone number.
Parameters
----------
phone_number : str
Telephone number in E.164 format. For example, +11234567890.
inbound_config : typing.Optional[UpdatePhoneNumbersRequestInboundConfig]
Update inbound call configuration. Passing `null` will clear the configuration.
outbound_config : typing.Optional[UpdatePhoneNumbersRequestOutboundConfig]
Update outbound call configuration. Passing `null` will clear the configuration.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
UpdatePhoneNumbersResponse
Request was successful. The response body contains the result of the request.
Examples
--------
from agora_agent import Agora
from agora_agent.phone_numbers import (
UpdatePhoneNumbersRequestInboundConfig,
UpdatePhoneNumbersRequestOutboundConfig,
)
client = Agora(
authorization="YOUR_AUTHORIZATION",
username="YOUR_USERNAME",
password="YOUR_PASSWORD",
)
client.phone_numbers.update(
phone_number="phone_number",
inbound_config=UpdatePhoneNumbersRequestInboundConfig(
pipeline_id="xxxxx",
),
outbound_config=UpdatePhoneNumbersRequestOutboundConfig(
pipeline_id="xxxxx",
),
)
"""
_response = self._raw_client.update(
phone_number,
inbound_config=inbound_config,
outbound_config=outbound_config,
request_options=request_options,
)
return _response.data
class AsyncPhoneNumbersClient:
def __init__(self, *, client_wrapper: AsyncClientWrapper):
self._raw_client = AsyncRawPhoneNumbersClient(client_wrapper=client_wrapper)
@property
def with_raw_response(self) -> AsyncRawPhoneNumbersClient:
"""
Retrieves a raw implementation of this client that returns raw responses.
Returns
-------
AsyncRawPhoneNumbersClient
"""
return self._raw_client
async def list(
self, *, request_options: typing.Optional[RequestOptions] = None
) -> typing.List[ListPhoneNumbersResponseItem]:
"""
Retrieve a list of all imported phone numbers under the current account.
Parameters
----------
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
typing.List[ListPhoneNumbersResponseItem]
Request was successful. The response body contains a JSON array of phone number configurations.
Examples
--------
import asyncio
from agora_agent import AsyncAgora
client = AsyncAgora(
authorization="YOUR_AUTHORIZATION",
username="YOUR_USERNAME",
password="YOUR_PASSWORD",
)
async def main() -> None:
await client.phone_numbers.list()
asyncio.run(main())
"""
_response = await self._raw_client.list(request_options=request_options)
return _response.data
async def add(
self,
*,
provider: AddPhoneNumbersRequestProvider,
phone_number: str,
label: str,
inbound_config: AddPhoneNumbersRequestInboundConfig,
outbound_config: AddPhoneNumbersRequestOutboundConfig,
inbound: typing.Optional[bool] = OMIT,
outbound: typing.Optional[bool] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> AddPhoneNumbersResponse:
"""
Import a pre-configured phone number that can be used for inbound or outbound calls.
Parameters
----------
provider : AddPhoneNumbersRequestProvider
Number provider:
- `byo`: BYO (Bring Your Own)
- `twilio`: Twilio
phone_number : str
Telephone number in E.164 format.
label : str
A label used to identify the number.
inbound_config : AddPhoneNumbersRequestInboundConfig
SIP inbound call configuration.
outbound_config : AddPhoneNumbersRequestOutboundConfig
SIP outbound call configuration.
inbound : typing.Optional[bool]
Whether the number supports inbound calls.
outbound : typing.Optional[bool]
Whether the number supports outbound calls.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AddPhoneNumbersResponse
Request was successful. The response body contains the result of the request.
Examples
--------
import asyncio
from agora_agent import AsyncAgora
from agora_agent.phone_numbers import (
AddPhoneNumbersRequestInboundConfig,
AddPhoneNumbersRequestOutboundConfig,
)
client = AsyncAgora(
authorization="YOUR_AUTHORIZATION",
username="YOUR_USERNAME",
password="YOUR_PASSWORD",
)
async def main() -> None:
await client.phone_numbers.add(
provider="byo",
phone_number="+19876543210",
label="Sales Hotline",
inbound=True,
outbound=True,
inbound_config=AddPhoneNumbersRequestInboundConfig(
allowed_addresses=["112.126.15.64/27"],
),
outbound_config=AddPhoneNumbersRequestOutboundConfig(
address="xxx:xxx@sip.example.com",
transport="tls",
),
)
asyncio.run(main())
"""
_response = await self._raw_client.add(
provider=provider,
phone_number=phone_number,
label=label,
inbound_config=inbound_config,
outbound_config=outbound_config,
inbound=inbound,
outbound=outbound,
request_options=request_options,
)
return _response.data
async def get(
self, phone_number: str, *, request_options: typing.Optional[RequestOptions] = None
) -> GetPhoneNumbersResponse:
"""
Retrieve detailed information for a specific phone number.
Parameters
----------
phone_number : str
Telephone number in E.164 format. For example, +11234567890.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
GetPhoneNumbersResponse
Request was successful. The response body contains the result of the request.
Examples
--------
import asyncio
from agora_agent import AsyncAgora
client = AsyncAgora(
authorization="YOUR_AUTHORIZATION",
username="YOUR_USERNAME",
password="YOUR_PASSWORD",
)
async def main() -> None:
await client.phone_numbers.get(
phone_number="phone_number",
)
asyncio.run(main())
"""
_response = await self._raw_client.get(phone_number, request_options=request_options)
return _response.data
async def delete(self, phone_number: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
"""
Remove an imported phone number from the system.
After calling this endpoint, the number stops receiving calls routed through this system. To delete the number from the service provider, remove it in the service provider's console.
> This operation only removes the number configuration from the Agora system; the number stored with the phone service provider is not deleted.
Parameters
----------
phone_number : str
Telephone number in E.164 format. For example, +11234567890.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
None
Examples
--------
import asyncio
from agora_agent import AsyncAgora
client = AsyncAgora(
authorization="YOUR_AUTHORIZATION",
username="YOUR_USERNAME",
password="YOUR_PASSWORD",
)
async def main() -> None:
await client.phone_numbers.delete(
phone_number="phone_number",
)
asyncio.run(main())
"""
_response = await self._raw_client.delete(phone_number, request_options=request_options)
return _response.data
async def update(
self,
phone_number: str,
*,
inbound_config: typing.Optional[UpdatePhoneNumbersRequestInboundConfig] = OMIT,
outbound_config: typing.Optional[UpdatePhoneNumbersRequestOutboundConfig] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> UpdatePhoneNumbersResponse:
"""
Update the configuration for a phone number.
Parameters
----------
phone_number : str
Telephone number in E.164 format. For example, +11234567890.
inbound_config : typing.Optional[UpdatePhoneNumbersRequestInboundConfig]
Update inbound call configuration. Passing `null` will clear the configuration.
outbound_config : typing.Optional[UpdatePhoneNumbersRequestOutboundConfig]
Update outbound call configuration. Passing `null` will clear the configuration.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
UpdatePhoneNumbersResponse
Request was successful. The response body contains the result of the request.
Examples
--------
import asyncio
from agora_agent import AsyncAgora
from agora_agent.phone_numbers import (
UpdatePhoneNumbersRequestInboundConfig,
UpdatePhoneNumbersRequestOutboundConfig,
)
client = AsyncAgora(
authorization="YOUR_AUTHORIZATION",
username="YOUR_USERNAME",
password="YOUR_PASSWORD",
)
async def main() -> None:
await client.phone_numbers.update(
phone_number="phone_number",
inbound_config=UpdatePhoneNumbersRequestInboundConfig(
pipeline_id="xxxxx",
),
outbound_config=UpdatePhoneNumbersRequestOutboundConfig(
pipeline_id="xxxxx",
),
)
asyncio.run(main())
"""
_response = await self._raw_client.update(
phone_number,
inbound_config=inbound_config,
outbound_config=outbound_config,
request_options=request_options,
)
return _response.data