|
| 1 | +## Calls |
| 2 | +Initialize Calls API client: |
| 3 | +```python |
| 4 | + from infobip_api_client.api_client import ApiClient, Configuration |
| 5 | + from infobip_api_client.api import CallsApi |
| 6 | + |
| 7 | + client_config = Configuration( |
| 8 | + host="<YOUR_BASE_URL>", |
| 9 | + api_key={"APIKeyHeader": "<YOUR_API_KEY>"}, |
| 10 | + api_key_prefix={"APIKeyHeader": "<YOUR_API_PREFIX>"}, |
| 11 | + ) |
| 12 | + |
| 13 | + calls_client = ApiClient(client_config) |
| 14 | + api_instance = CallsApi(calls_client) |
| 15 | +``` |
| 16 | +Before starting a call or dialogue you need to set up the application. |
| 17 | + |
| 18 | +#### Start call |
| 19 | +After setting up the client you can start a call. |
| 20 | +```python |
| 21 | + from infobip_api_client.models import CallRequest, CallsPhoneEndpoint, CallEndpointType, CallState |
| 22 | + |
| 23 | + request = CallRequest( |
| 24 | + endpoint=CallsPhoneEndpoint(phone_number="<TO_PHONE_NUMBER>", type=CallEndpointType.PHONE), |
| 25 | + var_from="<FROM_PHONE_NUMBER>", |
| 26 | + calls_configuration_id="ORION", |
| 27 | + ) |
| 28 | + |
| 29 | + api_response = api_instance.create_call(call_request=request) |
| 30 | + |
| 31 | + call = api_instance.get_call(api_response.id) |
| 32 | + callId = call.id |
| 33 | + callState = call.state |
| 34 | + |
| 35 | + print("Waiting for CallState to be established...") |
| 36 | + while CallState.ESTABLISHED != callState: |
| 37 | + callState = api_instance.get_call(api_response.id).state |
| 38 | +``` |
| 39 | + |
| 40 | +#### Executing call with text |
| 41 | +After starting a call, you can execute text to be said. |
| 42 | +```python |
| 43 | + from infobip_api_client.models import CallsSayRequest, CallsLanguage |
| 44 | + |
| 45 | + call_say_request = CallsSayRequest( |
| 46 | + text="<TEXT_TO_SAY>", |
| 47 | + language=CallsLanguage.EN, |
| 48 | + ) |
| 49 | + |
| 50 | + api_response = api_instance.call_say_text(call_id=callId, |
| 51 | + calls_say_request=call_say_request) |
| 52 | + |
| 53 | +``` |
| 54 | + |
| 55 | +#### Start dialogue |
| 56 | +After starting a call, you can start a dialogue. |
| 57 | +```python |
| 58 | + import time |
| 59 | + from infobip_api_client.models import CallsDialogRequest, CallsDialogCallRequest, CallsWebRtcEndpoint, CallEndpointType |
| 60 | + |
| 61 | + call_dialog_request = CallsDialogRequest( |
| 62 | + parent_call_id=callId, |
| 63 | + child_call_request=CallsDialogCallRequest( |
| 64 | + endpoint=CallsWebRtcEndpoint(type=CallEndpointType.WEBRTC, identity="<YOUR_IDENTITY>"), |
| 65 | + var_from="<FROM>", |
| 66 | + ) |
| 67 | + ) |
| 68 | + |
| 69 | + api_response = api_instance.create_dialog(calls_dialog_request=call_dialog_request) |
| 70 | + |
| 71 | + time.sleep(5) |
| 72 | + |
| 73 | + api_instance.hangup_dialog(api_response.id) |
| 74 | + |
| 75 | +``` |
| 76 | + |
| 77 | +#### Starting a call for conference |
| 78 | +Before starting a conference you need to start a call. |
| 79 | +```python |
| 80 | + from infobip_api_client.models import CallRequest, CallsWebRtcEndpoint, CallEndpointType, CallState |
| 81 | + |
| 82 | + request = CallRequest( |
| 83 | + endpoint=CallsWebRtcEndpoint(identity="<YOUR_IDENTITY>", type=CallEndpointType.WEBRTC), |
| 84 | + var_from="<FROM>", |
| 85 | + calls_configuration_id="ORION", |
| 86 | + ) |
| 87 | + |
| 88 | + api_response = api_instance.create_call(call_request=request) |
| 89 | + |
| 90 | + call = api_instance.get_call(api_response.id) |
| 91 | + callId = call.id |
| 92 | + callState = call.state |
| 93 | + |
| 94 | + print("Waiting for CallState to be established...") |
| 95 | + while CallState.ESTABLISHED != callState: |
| 96 | + callState = api_instance.get_call(api_response.id).state |
| 97 | +``` |
| 98 | + |
| 99 | +#### Start conference |
| 100 | +After starting a call, you can add it to the conference. |
| 101 | +```python |
| 102 | + import time |
| 103 | + from infobip_api_client.models import CallsConferenceRequest, CallsAddExistingCallRequest |
| 104 | + |
| 105 | + conference_request = CallsConferenceRequest( |
| 106 | + name="<YOUR_CONFERENCE_NAME>", |
| 107 | + calls_configuration_id="ORION", |
| 108 | + ) |
| 109 | + |
| 110 | + api_response = api_instance.create_conference(calls_conference_request=conference_request) |
| 111 | + |
| 112 | + conferenceId = api_response.id |
| 113 | + |
| 114 | + add_existing_call_request = CallsAddExistingCallRequest() |
| 115 | + |
| 116 | + api_instance.add_existing_conference_call(conference_id=conferenceId, |
| 117 | + call_id=callId, |
| 118 | + calls_add_existing_call_request=add_existing_call_request) |
| 119 | + |
| 120 | + time.sleep(5) |
| 121 | + |
| 122 | + api_instance.hangup_conference(conferenceId) |
| 123 | +``` |
0 commit comments