-
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
Open
mramasubramanian-bw
wants to merge
8
commits into
main
Choose a base branch
from
VAPI-3161-add-refer-verb
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+108
−0
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9a134a9
VAPI-3161: Add <Refer> BXML verb
mramasubramanian-bw cf272b1
VAPI-3161 Add ReferCompleteCallback model and scenario tests
stampercasey 882735a
VAPI-3163 Replace Transfer SipUri with ReferSipUri in <Refer>
stampercasey 47a9d68
Merge branch 'main' into VAPI-3161-add-refer-verb
stampercasey e0d827a
VAPI-3435 Simplify Refer to reuse Transfer's SipUri
stampercasey a248043
Merge branch 'main' into VAPI-3161-add-refer-verb
stampercasey e76dc6b
Address review feedback: optional sip_uri, set_sip_uri setter
stampercasey 2052a03
Merge remote-tracking branch 'origin/VAPI-3161-add-refer-verb' into V…
stampercasey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| """ | ||
| 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=None, | ||
| 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=[sip_uri] if sip_uri is not None else [] | ||
| ) | ||
|
|
||
| @property | ||
| def _attributes(self): | ||
| return { | ||
| "referCompleteUrl": self.refer_complete_url, | ||
| "referCompleteMethod": self.refer_complete_method, | ||
| "tag": self.tag | ||
| } | ||
|
|
||
| def set_sip_uri(self, sip_uri: SipUri) -> None: | ||
| """Set the SIP URI destination for this <Refer> verb. | ||
|
|
||
| Args: | ||
| sip_uri (SipUri): The SIP URI to refer the call to. | ||
| """ | ||
| self.sip_uri = sip_uri | ||
| self._nested_verbs = [sip_uri] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| """ | ||
| 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_set_sip_uri(self): | ||
| refer = Refer() | ||
| refer.set_sip_uri(SipUri(uri="sip:bob@example.com")) | ||
| expected = '<Refer><SipUri>sip:bob@example.com</SipUri></Refer>' | ||
| assert expected == refer.to_bxml() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
we should add something similar to ruby and node to allow the user to set the sip_uri after creation, we can't use
add_verbbut can write a setter