|
| 1 | +""" |
| 2 | +refer.py |
| 3 | +
|
| 4 | +Bandwidth's Refer BXML verb |
| 5 | +
|
| 6 | +@copyright Bandwidth INC |
| 7 | +""" |
| 8 | +from ..nestable_verb import NestableVerb |
| 9 | +from .sip_uri import SipUri |
| 10 | + |
| 11 | + |
| 12 | +class Refer(NestableVerb): |
| 13 | + |
| 14 | + def __init__( |
| 15 | + self, sip_uri: SipUri=None, |
| 16 | + refer_complete_url: str=None, refer_complete_method: str=None, |
| 17 | + tag: str=None |
| 18 | + ): |
| 19 | + """Initialize a <Refer> verb |
| 20 | +
|
| 21 | + The <Refer> verb sends a SIP REFER to the remote endpoint, asking it |
| 22 | + to redirect the call to a new SIP URI. Unlike <Transfer>, a successful |
| 23 | + REFER terminates the call on Bandwidth's side: the remote endpoint |
| 24 | + redirects away from Bandwidth entirely. This is a SIP protocol |
| 25 | + property, not a Bandwidth design choice. As a result, BXML returned in |
| 26 | + response to the referComplete callback is only meaningful for failure |
| 27 | + handling - there is no live call to act on after success. |
| 28 | +
|
| 29 | + Args: |
| 30 | + sip_uri (SipUri): The SIP URI to refer the call to. Required. |
| 31 | + Exactly one <SipUri> child element is allowed. This is the |
| 32 | + same SipUri model used by <Transfer>. |
| 33 | + refer_complete_url (str, optional): URL to send the Refer Complete |
| 34 | + event to when the REFER flow finishes (success or failure). |
| 35 | + May be a relative URL. Defaults to None. |
| 36 | + refer_complete_method (str, optional): The HTTP method to use for |
| 37 | + the request to referCompleteUrl. GET or POST. Default value |
| 38 | + is POST. Defaults to None. |
| 39 | + tag (str, optional): A custom string that will be sent with this |
| 40 | + and all future callbacks unless overwritten by a future tag |
| 41 | + attribute or cleared. May be cleared by setting tag="". Max |
| 42 | + length 256 characters. Defaults to None. |
| 43 | + """ |
| 44 | + self.sip_uri = sip_uri |
| 45 | + self.refer_complete_url = refer_complete_url |
| 46 | + self.refer_complete_method = refer_complete_method |
| 47 | + self.tag = tag |
| 48 | + super().__init__( |
| 49 | + tag="Refer", |
| 50 | + nested_verbs=[sip_uri] if sip_uri is not None else [] |
| 51 | + ) |
| 52 | + |
| 53 | + @property |
| 54 | + def _attributes(self): |
| 55 | + return { |
| 56 | + "referCompleteUrl": self.refer_complete_url, |
| 57 | + "referCompleteMethod": self.refer_complete_method, |
| 58 | + "tag": self.tag |
| 59 | + } |
| 60 | + |
| 61 | + def set_sip_uri(self, sip_uri: SipUri) -> None: |
| 62 | + """Set the SIP URI destination for this <Refer> verb. |
| 63 | +
|
| 64 | + Args: |
| 65 | + sip_uri (SipUri): The SIP URI to refer the call to. |
| 66 | + """ |
| 67 | + self.sip_uri = sip_uri |
| 68 | + self._nested_verbs = [sip_uri] |
0 commit comments