-
Notifications
You must be signed in to change notification settings - Fork 0
VAPI-3165 Add Refer BXML verb support #118
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
base: main
Are you sure you want to change the base?
Changes from all commits
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,38 @@ | ||
| import { NestableVerb } from '../NestableVerb'; | ||
| import { SipUri } from './SipUri'; | ||
|
|
||
| export interface ReferAttributes { | ||
| referCompleteUrl?: string; | ||
| referCompleteMethod?: string; | ||
| tag?: string; | ||
| } | ||
|
|
||
| /** | ||
| * @export | ||
| * @class Refer | ||
| * @extends {NestableVerb} | ||
| * Represents a Refer BXML verb. | ||
| * NOTE: On success the call is terminated — the remote SIP endpoint redirects away from Bandwidth. | ||
| * Recovery BXML in referCompleteUrl only makes sense for failure handling. | ||
| */ | ||
| export class Refer extends NestableVerb { | ||
| attributes: ReferAttributes; | ||
|
|
||
| /** | ||
| * Creates an instance of Refer | ||
| * @param {ReferAttributes} attributes The attributes to add to the element | ||
| * @param {SipUri} sipUri The SipUri child element (required for a valid Refer) | ||
| */ | ||
| constructor(attributes?: ReferAttributes, sipUri?: SipUri) { | ||
|
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. [MINOR] The spec mandates exactly one Python makes constructor(sipUri: SipUri, attributes?: ReferAttributes) {
super('Refer', undefined, attributes, [sipUri]);
}If keeping optional for API flexibility, add a runtime guard: if (!sipUri) throw new Error('Refer requires a SipUri child element'); |
||
| super('Refer', undefined, attributes, sipUri ? [sipUri] : undefined); | ||
| } | ||
|
|
||
| /** | ||
| * Set the SipUri for this Refer verb | ||
| * @param {SipUri} sipUri The SipUri to refer to | ||
| */ | ||
| setSipUri(sipUri: SipUri): void { | ||
| this.nestedVerbs = [sipUri]; | ||
|
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. [MINOR] This works correctly today since // Replaces the single required SipUri child — <Refer> allows exactly one.
this.nestedVerbs = [sipUri]; |
||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { Refer, ReferAttributes } from '../../../../../models/bxml/verbs/Refer'; | ||
| import { SipUri } from '../../../../../models/bxml/verbs/SipUri'; | ||
|
|
||
| describe('Refer', () => { | ||
| test('should generate Refer XML with SipUri and all attributes', () => { | ||
| const attributes: ReferAttributes = { | ||
| referCompleteUrl: 'https://example.com/handleRefer', | ||
| referCompleteMethod: 'POST', | ||
| tag: 'my-tag', | ||
| }; | ||
| const sipUri = new SipUri('sip:alice@atlanta.example.com'); | ||
| const refer = new Refer(attributes, sipUri); | ||
|
|
||
| const xml = refer.toBxml(); | ||
| expect(xml).toContain('<Refer'); | ||
| expect(xml).toContain('referCompleteUrl="https://example.com/handleRefer"'); | ||
| expect(xml).toContain('referCompleteMethod="POST"'); | ||
| expect(xml).toContain('tag="my-tag"'); | ||
| expect(xml).toContain('<SipUri>sip:alice@atlanta.example.com</SipUri>'); | ||
| expect(xml).toContain('</Refer>'); | ||
| }); | ||
|
|
||
| test('should generate Refer XML with no attributes', () => { | ||
| const sipUri = new SipUri('sip:bob@biloxi.example.com'); | ||
| const refer = new Refer(undefined, sipUri); | ||
|
|
||
| const xml = refer.toBxml(); | ||
| expect(xml).toContain('<Refer>'); | ||
| expect(xml).toContain('<SipUri>sip:bob@biloxi.example.com</SipUri>'); | ||
| }); | ||
|
|
||
| test('setSipUri should replace the nested SipUri', () => { | ||
| const sipUri1 = new SipUri('sip:alice@atlanta.example.com'); | ||
| const sipUri2 = new SipUri('sip:bob@biloxi.example.com'); | ||
| const refer = new Refer({}, sipUri1); | ||
|
|
||
| refer.setSipUri(sipUri2); | ||
| const xml = refer.toBxml(); | ||
| expect(xml).not.toContain('alice'); | ||
| expect(xml).toContain('sip:bob@biloxi.example.com'); | ||
| }); | ||
| }); | ||
|
|
||
|
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. [MINOR] No test for Since test('should throw when SipUri is missing', () => {
expect(() => new Refer({})).toThrow();
}); |
||
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.
[MINOR]
SipUricarries Transfer-specific attributesThe imported
SipUriacceptstransferAnswerUrl,transferAnswerFallbackUrl,uui,username,password, etc. as optional attributes. Any of those passed here will serialize into the<SipUri>element inside<Refer>, producing malformed BXML — and TypeScript won't catch it.Python resolved this with a dedicated
ReferSipUriclass accepting onlyuri. C# uses a nestedRefer.SipUriwith only aUriproperty. AReferSipUritype here (or at minimum a narrowed interface) would close that gap: