diff --git a/src/main/java/com/bandwidth/sdk/model/bxml/Bxml.java b/src/main/java/com/bandwidth/sdk/model/bxml/Bxml.java index 3d09ad9e..53c5258b 100644 --- a/src/main/java/com/bandwidth/sdk/model/bxml/Bxml.java +++ b/src/main/java/com/bandwidth/sdk/model/bxml/Bxml.java @@ -43,6 +43,7 @@ public class Bxml { @XmlElement(name = PlayAudio.TYPE_NAME, type = PlayAudio.class), @XmlElement(name = Record.TYPE_NAME, type = Record.class), @XmlElement(name = Redirect.TYPE_NAME, type = Redirect.class), + @XmlElement(name = Refer.TYPE_NAME, type = Refer.class), @XmlElement(name = ResumeRecording.TYPE_NAME, type = ResumeRecording.class), @XmlElement(name = Ring.TYPE_NAME, type = Ring.class), @XmlElement(name = SendDtmf.TYPE_NAME, type = SendDtmf.class), diff --git a/src/main/java/com/bandwidth/sdk/model/bxml/Refer.java b/src/main/java/com/bandwidth/sdk/model/bxml/Refer.java new file mode 100644 index 00000000..f640b865 --- /dev/null +++ b/src/main/java/com/bandwidth/sdk/model/bxml/Refer.java @@ -0,0 +1,59 @@ +/** + * The {@code } verb is used to initiate a SIP REFER on an existing call, + * instructing the remote SIP endpoint to contact a third party directly. + * On success the call is terminated — the remote endpoint redirects away from Bandwidth entirely. + */ + +package com.bandwidth.sdk.model.bxml; + +import static com.bandwidth.sdk.model.bxml.utils.BxmlConstants.DEFAULT_CALLBACK_METHOD; + +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlAttribute; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlType; +import java.net.URI; + +import lombok.*; +import lombok.Builder.Default; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = Refer.TYPE_NAME) +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Getter +@EqualsAndHashCode +/** + * + * @param sipUri (SipUri, required): The SIP URI to refer the call to. Must start with "sip:". + * @param referCompleteUrl (str, optional): URL to send the Refer Complete event to and request new BXML for failure recovery. May be a relative URL. Defaults to None. + * @param referCompleteMethod (str, optional): The HTTP method to use for the request to referCompleteUrl. GET or POST. Default value is POST. + * @param tag (str, optional): A custom string that will be sent with these 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. + * + */ +public class Refer implements Verb { + + public static final String TYPE_NAME = "Refer"; + + @XmlElement(name = "SipUri", type = SipUri.class) + @NonNull + protected SipUri sipUri; + + @XmlAttribute + protected URI referCompleteUrl; + + @XmlAttribute + @Default + protected String referCompleteMethod = DEFAULT_CALLBACK_METHOD; + + @XmlAttribute + protected String tag; + + @Override + public String getVerbName() { + return TYPE_NAME; + } +} + diff --git a/src/test/java/com/bandwidth/sdk/unit/models/bxml/ReferVerbTest.java b/src/test/java/com/bandwidth/sdk/unit/models/bxml/ReferVerbTest.java new file mode 100644 index 00000000..940d597c --- /dev/null +++ b/src/test/java/com/bandwidth/sdk/unit/models/bxml/ReferVerbTest.java @@ -0,0 +1,55 @@ +/** + * + * Unit tests for Refer Verb class + * + * @throws JAXBException if the test fails + */ + +package com.bandwidth.sdk.unit.models.bxml; + +import com.bandwidth.sdk.model.bxml.Bxml; +import com.bandwidth.sdk.model.bxml.Refer; +import com.bandwidth.sdk.model.bxml.SipUri; + +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBException; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import java.net.URI; + +public class ReferVerbTest { + + SipUri sipUri = SipUri.builder() + .uri("sip:alice@atlanta.example.com") + .build(); + + Refer refer = Refer.builder() + .sipUri(sipUri) + .referCompleteUrl(URI.create("https://example.com/webhooks/refer_complete")) + .referCompleteMethod("POST") + .tag("test-tag") + .build(); + + Refer referMinimal = Refer.builder() + .sipUri(sipUri) + .build(); + + @Test + public void referVerbWithAllAttributes() throws JAXBException { + JAXBContext jaxbContext = JAXBContext.newInstance(Bxml.class); + String expectedBxml = "sip:alice@atlanta.example.com"; + assertThat(new Bxml().with(refer).toBxml(jaxbContext), is(expectedBxml)); + } + + @Test + public void referVerbMinimal() throws JAXBException { + JAXBContext jaxbContext = JAXBContext.newInstance(Bxml.class); + String expectedBxml = "sip:alice@atlanta.example.com"; + assertThat(new Bxml().with(referMinimal).toBxml(jaxbContext), is(expectedBxml)); + } +} +