|
| 1 | +from bandwidth.model.bxml.response import Response |
| 2 | +from bandwidth.model.bxml.verbs import * |
| 3 | + |
| 4 | + |
| 5 | +def _generate_transfer_model(device_token: str, voice_call_id: str, sip_uri: str = 'sip:sipx.webrtc.bandwidth.com:5060') -> Transfer: |
| 6 | + """Generate a Transfer object for a WebRTC Session |
| 7 | +
|
| 8 | + Args: |
| 9 | + device_token (str): The device token. |
| 10 | + voice_call_id (str): The Bandwidth voice Call ID. |
| 11 | + sip_uri (str, optional): The SIP URI to transfer the call to. Defaults to 'sip:sipx.webrtc.bandwidth.com:5060'. |
| 12 | +
|
| 13 | + Returns: |
| 14 | + Transfer: Returns a Transfer BXML Verb Object |
| 15 | + """ |
| 16 | + uui = "".join(voice_call_id.split("-")[1::]) |
| 17 | + sip_uri = SipUri( |
| 18 | + uui=f"{uui};encoding=base64,{device_token};encoding=jwt", |
| 19 | + uri=sip_uri |
| 20 | + ) |
| 21 | + transfer = Transfer( |
| 22 | + sip_uris=[sip_uri] |
| 23 | + ) |
| 24 | + return transfer |
| 25 | + |
| 26 | + |
| 27 | +def generate_transfer_bxml_verb(device_token: str, voice_call_id: str, sip_uri: str = 'sip:sipx.webrtc.bandwidth.com:5060') -> str: |
| 28 | + """Returns the Transfer verb to perform the SIP transfer without the Response wrapper |
| 29 | +
|
| 30 | + Args: |
| 31 | + device_token (str): The device token. |
| 32 | + voice_call_id (str): The Bandwidth voice Call ID. |
| 33 | + sip_uri (str, optional): The SIP URI to transfer the call to. Defaults to 'sip:sipx.webrtc.bandwidth.com:5060'. |
| 34 | +
|
| 35 | + Returns: |
| 36 | + str: <Transfer> BXML Verb |
| 37 | + """ |
| 38 | + return _generate_transfer_model(device_token, voice_call_id, sip_uri).to_bxml() |
| 39 | + |
| 40 | + |
| 41 | +def generate_transfer_bxml(device_token: str, voice_call_id: str, sip_uri: str = 'sip:sipx.webrtc.bandwidth.com:5060') -> str: |
| 42 | + """Generate BXML document with WebRTC a device token to perform a SIP transfer |
| 43 | +
|
| 44 | + Args: |
| 45 | + device_token (str): The device token. |
| 46 | + voice_call_id (str): The Bandwidth voice Call ID. |
| 47 | + sip_uri (str, optional): The SIP URI to transfer the call to. Defaults to 'sip:sipx.webrtc.bandwidth.com:5060'. |
| 48 | +
|
| 49 | + Returns: |
| 50 | + str: BXML document with transfer BXML |
| 51 | + """ |
| 52 | + response = Response() |
| 53 | + response.add_verb(_generate_transfer_model(device_token, voice_call_id, sip_uri)) |
| 54 | + return response.to_bxml() |
0 commit comments