-
Notifications
You must be signed in to change notification settings - Fork 9
VAPI-3161: Add <Refer> BXML verb support #295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
9a134a9
cf272b1
882735a
47a9d68
e0d827a
a248043
e76dc6b
2052a03
bb89c32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,59 @@ | ||||||
| """ | ||||||
| refer.py | ||||||
|
|
||||||
| Bandwidth's Refer BXML verb | ||||||
|
|
||||||
| @copyright Bandwidth INC | ||||||
| """ | ||||||
| from ..nestable_verb import NestableVerb | ||||||
| from .sip_uri import SipUri | ||||||
|
|
||||||
|
|
||||||
| class Refer(NestableVerb): | ||||||
|
|
||||||
| def __init__( | ||||||
| self, sip_uri: SipUri, | ||||||
| refer_complete_url: str=None, refer_complete_method: str=None, | ||||||
| tag: str=None | ||||||
| ): | ||||||
| """Initialize a <Refer> verb | ||||||
|
|
||||||
| The <Refer> verb sends a SIP REFER to the remote endpoint, asking it | ||||||
| to redirect the call to a new SIP URI. Unlike <Transfer>, a successful | ||||||
| REFER terminates the call on Bandwidth's side: the remote endpoint | ||||||
| redirects away from Bandwidth entirely. This is a SIP protocol | ||||||
| property, not a Bandwidth design choice. As a result, BXML returned in | ||||||
| response to the referComplete callback is only meaningful for failure | ||||||
| handling - there is no live call to act on after success. | ||||||
|
|
||||||
| Args: | ||||||
| sip_uri (SipUri): The SIP URI to refer the call to. Required. | ||||||
| Exactly one <SipUri> child element is allowed. This is the | ||||||
| same SipUri model used by <Transfer>. | ||||||
| refer_complete_url (str, optional): URL to send the Refer Complete | ||||||
| event to when the REFER flow finishes (success or failure). | ||||||
| May be a relative URL. Defaults to None. | ||||||
| refer_complete_method (str, optional): The HTTP method to use for | ||||||
| the request to referCompleteUrl. GET or POST. Default value | ||||||
| is POST. Defaults to None. | ||||||
| tag (str, optional): A custom string that will be sent with this | ||||||
| and all future callbacks unless overwritten by a future tag | ||||||
| attribute or cleared. May be cleared by setting tag="". Max | ||||||
| length 256 characters. Defaults to None. | ||||||
| """ | ||||||
| self.sip_uri = sip_uri | ||||||
| self.refer_complete_url = refer_complete_url | ||||||
| self.refer_complete_method = refer_complete_method | ||||||
| self.tag = tag | ||||||
| super().__init__( | ||||||
| tag="Refer", | ||||||
| nested_verbs=[self.sip_uri] | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
to handle the uri being optional |
||||||
| ) | ||||||
|
|
||||||
| @property | ||||||
| def _attributes(self): | ||||||
| return { | ||||||
| "referCompleteUrl": self.refer_complete_url, | ||||||
| "referCompleteMethod": self.refer_complete_method, | ||||||
| "tag": self.tag | ||||||
| } | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should add something similar to ruby and node to allow the user to set the sip_uri after creation, we can't use |
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| """ | ||
| test_refer.py | ||
|
|
||
| Unit tests for the <Refer> BXML verb | ||
|
|
||
| @copyright Bandwidth Inc. | ||
| """ | ||
| import unittest | ||
|
|
||
| from bandwidth.models.bxml import Refer, SipUri, Verb, NestableVerb | ||
|
|
||
|
|
||
| class TestRefer(unittest.TestCase): | ||
|
|
||
| def setUp(self): | ||
| self.sip_uri = SipUri(uri="sip:alice@atlanta.example.com") | ||
| self.refer = Refer( | ||
| sip_uri=self.sip_uri, | ||
| refer_complete_url="https://example.com/handleRefer", | ||
| refer_complete_method="POST", | ||
| tag="test" | ||
| ) | ||
|
|
||
| def test_instance(self): | ||
| assert isinstance(self.refer, Refer) | ||
| assert isinstance(self.refer, NestableVerb) | ||
| assert isinstance(self.refer, Verb) | ||
|
|
||
| def test_to_bxml(self): | ||
| expected = '<Refer referCompleteUrl="https://example.com/handleRefer" referCompleteMethod="POST" tag="test"><SipUri>sip:alice@atlanta.example.com</SipUri></Refer>' | ||
| assert expected == self.refer.to_bxml() | ||
|
|
||
| def test_minimal(self): | ||
| minimal_refer = Refer(sip_uri=SipUri(uri="sip:bob@example.com")) | ||
| expected = '<Refer><SipUri>sip:bob@example.com</SipUri></Refer>' | ||
| assert expected == minimal_refer.to_bxml() | ||
|
|
||
| def test_shares_sip_uri_with_transfer(self): | ||
| """Refer uses the same SipUri model as Transfer, including its | ||
| transfer-flavored attributes if the caller sets them.""" | ||
| sip_uri = SipUri(uri="sip:alice@atlanta.example.com", uui="test") | ||
| refer = Refer(sip_uri=sip_uri) | ||
| expected = '<Refer><SipUri uui="test">sip:alice@atlanta.example.com</SipUri></Refer>' | ||
| assert expected == refer.to_bxml() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. both of these are unnecessary. we should add a test to test setting the |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be optional to match how the other verbs handle their nested verbs