Skip to content

VAPI-3161: Add <Refer> BXML verb support - #295

Open
mramasubramanian-bw wants to merge 8 commits into
mainfrom
VAPI-3161-add-refer-verb
Open

VAPI-3161: Add <Refer> BXML verb support#295
mramasubramanian-bw wants to merge 8 commits into
mainfrom
VAPI-3161-add-refer-verb

Conversation

@mramasubramanian-bw

@mramasubramanian-bw mramasubramanian-bw commented May 9, 2026

Copy link
Copy Markdown

Adds the <Refer> BXML verb.

  • bandwidth/models/bxml/verbs/refer.py: new Refer verb (referCompleteUrl, referCompleteMethod, tag attributes, one required SipUri child).
  • Reuses the existing SipUri type (bandwidth/models/bxml/verbs/sip_uri.py) for the child element instead of a separate ReferSipUri - no cross-field validation restricting which SipUri attributes are legal per verb (matches csharp-sdk#201, which dropped this as over-engineering).
  • ReferCompleteCallback model is out of scope here - lands separately once VAPI-3440 merges.
  • Tests in test/unit/models/bxml/test_refer.py.

Tests: pytest test/unit/models/ - 276/276 pass.

VAPI-3435

Adds support for the SIP REFER BXML verb to the python-sdk, mirroring
the <Transfer> pattern but with the SIP-protocol-mandated success
semantics: a successful REFER terminates the call on Bandwidth's side.

Scope: BXML verb + unit tests only. The referCompleteCallback model
will be regenerated from the OpenAPI spec once api-specs#2142 merges.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@bwappsec

bwappsec commented May 9, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Unblocked by api-specs#2142 merging. Hand-written to match the
OpenAPI generator output pattern (mirrors TransferCompleteCallback).

Fields: standard call fields + referCallStatus, referSipResponseCode,
notifySipResponseCode. Excludes cause/errorMessage/errorId (not in spec)
and enqueuedTime (inbound SIP URI calls only).

Adds scenario tests for all four referComplete outcomes:
- Success (202 REFER, 200 NOTIFY)
- Failure: REFER rejected (e.g. 405, no NOTIFY)
- Failure: destination unreachable (202 REFER, 4xx NOTIFY)
- Failure: NOTIFY timeout (202 REFER, no NOTIFY)

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@stampercasey
stampercasey marked this pull request as ready for review June 18, 2026 19:58
@stampercasey
stampercasey requested review from a team as code owners June 18, 2026 19:58
stampercasey and others added 2 commits June 18, 2026 16:04
The Transfer SipUri carries ~12 Transfer-specific params (transfer_answer_url,
uui, auth, fallback URLs) that are invalid in a REFER context. A user passing
any of those would silently produce malformed BXML.

ReferSipUri accepts only uri — matching the spec and the C# SDK's nested
Refer.SipUri class design.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@stampercasey
stampercasey enabled auto-merge June 18, 2026 20:26
stampercasey
stampercasey previously approved these changes Jun 19, 2026
Remove ReferCompleteCallback (will land later via a separate api-specs-driven
PR once VAPI-3440 merges) and delete the distinct ReferSipUri type. Refer now
takes the existing Transfer-flavored SipUri directly, matching the plain,
validation-free style of the other BXML verb models in this SDK.
Comment thread bandwidth/models/bxml/verbs/refer.py Outdated
class Refer(NestableVerb):

def __init__(
self, sip_uri: SipUri,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self, sip_uri: SipUri,
self, sip_uri: SipUri=None,

this can be optional to match how the other verbs handle their nested verbs

Comment thread bandwidth/models/bxml/verbs/refer.py Outdated
self.tag = tag
super().__init__(
tag="Refer",
nested_verbs=[self.sip_uri]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
nested_verbs=[self.sip_uri]
nested_verbs=[sip_uri] if sip_uri else []

to handle the uri being optional

"referCompleteUrl": self.refer_complete_url,
"referCompleteMethod": self.refer_complete_method,
"tag": self.tag
}

Copy link
Copy Markdown
Contributor

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_verb but can write a setter

Comment thread test/unit/models/bxml/test_refer.py Outdated
Comment on lines +33 to +44
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()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 sip_uri though

Make sip_uri optional (default None) to match how other verbs handle
their nested verbs, guard nested_verbs construction against None, and
add a set_sip_uri() setter so callers can attach the SipUri after
construction (mirrors the ruby/node Refer pattern). Replaced
test_minimal/test_shares_sip_uri_with_transfer with a test covering
the new setter.
@stampercasey
stampercasey requested a review from ckoegel August 4, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants