|
2 | 2 |
|
3 | 3 | from pydantic import validate_call |
4 | 4 | from vonage_http_client.http_client import HttpClient |
| 5 | +from vonage_voice.models.ncco import NccoAction |
5 | 6 |
|
6 | 7 | from .models.requests import CreateCallRequest, ListCallsFilter |
7 | | -from .models.responses import CallInfo, CallList, CreateCallResponse |
| 8 | +from .models.responses import CallInfo, CallList, CallMessage, CreateCallResponse |
8 | 9 |
|
9 | 10 |
|
10 | 11 | class Voice: |
@@ -72,3 +73,87 @@ def get_call(self, call_id: str) -> CallInfo: |
72 | 73 | ) |
73 | 74 |
|
74 | 75 | return CallInfo(**response) |
| 76 | + |
| 77 | + @validate_call |
| 78 | + def transfer_call_ncco(self, uuid: str, ncco: List[NccoAction]) -> None: |
| 79 | + """Transfers a call to a new NCCO. |
| 80 | +
|
| 81 | + Args: |
| 82 | + uuid (str): The UUID of the call to transfer. |
| 83 | + ncco (List[NccoAction]): The new NCCO to transfer the call to. |
| 84 | + """ |
| 85 | + serializable_ncco = [ |
| 86 | + action.model_dump(by_alias=True, exclude_none=True) for action in ncco |
| 87 | + ] |
| 88 | + self._http_client.put( |
| 89 | + self._http_client.api_host, |
| 90 | + f'/v1/calls/{uuid}', |
| 91 | + { |
| 92 | + 'action': 'transfer', |
| 93 | + 'destination': {'type': 'ncco', 'ncco': serializable_ncco}, |
| 94 | + }, |
| 95 | + ) |
| 96 | + |
| 97 | + @validate_call |
| 98 | + def transfer_call_answer_url(self, uuid: str, answer_url: str) -> None: |
| 99 | + """Transfers a call to a new answer URL. |
| 100 | +
|
| 101 | + Args: |
| 102 | + uuid (str): The UUID of the call to transfer. |
| 103 | + answer_url (str): The new answer URL to transfer the call to. |
| 104 | + """ |
| 105 | + self._http_client.put( |
| 106 | + self._http_client.api_host, |
| 107 | + f'/v1/calls/{uuid}', |
| 108 | + {'action': 'transfer', 'destination': {'type': 'ncco', 'url': [answer_url]}}, |
| 109 | + ) |
| 110 | + |
| 111 | + def hangup(self, uuid: str) -> None: |
| 112 | + """Ends the call for the specified UUID, removing them from it. |
| 113 | +
|
| 114 | + Args: |
| 115 | + uuid (str): The UUID to end the call for. |
| 116 | + """ |
| 117 | + self._http_client.put( |
| 118 | + self._http_client.api_host, f'/v1/calls/{uuid}', {'action': 'hangup'} |
| 119 | + ) |
| 120 | + |
| 121 | + def mute(self, uuid: str) -> None: |
| 122 | + """Mutes a call for the specified UUID. |
| 123 | +
|
| 124 | + Args: |
| 125 | + uuid (str): The UUID to mute the call for. |
| 126 | + """ |
| 127 | + self._http_client.put( |
| 128 | + self._http_client.api_host, f'/v1/calls/{uuid}', {'action': 'mute'} |
| 129 | + ) |
| 130 | + |
| 131 | + def unmute(self, uuid: str) -> None: |
| 132 | + """Unmutes a call for the specified UUID. |
| 133 | +
|
| 134 | + Args: |
| 135 | + uuid (str): The UUID to unmute the call for. |
| 136 | + """ |
| 137 | + self._http_client.put( |
| 138 | + self._http_client.api_host, f'/v1/calls/{uuid}', {'action': 'unmute'} |
| 139 | + ) |
| 140 | + |
| 141 | + def earmuff(self, uuid: str) -> None: |
| 142 | + """Earmuffs a call for the specified UUID (prevents them from hearing audio). |
| 143 | +
|
| 144 | + Args: |
| 145 | + uuid (str): The UUID you want to prevent from hearing audio. |
| 146 | + """ |
| 147 | + self._http_client.put( |
| 148 | + self._http_client.api_host, f'/v1/calls/{uuid}', {'action': 'earmuff'} |
| 149 | + ) |
| 150 | + |
| 151 | + def unearmuff(self, uuid: str) -> None: |
| 152 | + """Allows the specified UUID to hear audio. |
| 153 | +
|
| 154 | + Args: |
| 155 | + uuid (str): The UUID you want to to allow to hear audio. |
| 156 | + """ |
| 157 | + self._http_client.put( |
| 158 | + self._http_client.api_host, f'/v1/calls/{uuid}', {'action': 'unearmuff'} |
| 159 | + ) |
0 commit comments