com.twilio.twiml.voice.VirtualAgent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of twilio Show documentation
Show all versions of twilio Show documentation
Twilio Java Helper Library
/**
* This code was generated by
* \ / _ _ _| _ _
* | (_)\/(_)(_|\/| |(/_ v1.0.0
* / /
*/
package com.twilio.twiml.voice;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.twilio.http.HttpMethod;
import com.twilio.twiml.TwiML;
import com.twilio.twiml.TwiMLException;
import java.util.HashMap;
import java.util.Map;
/**
* TwiML wrapper for {@code }
*/
@JsonDeserialize(builder = VirtualAgent.Builder.class)
public class VirtualAgent extends TwiML {
private final String connectorName;
private final String language;
private final Boolean sentimentAnalysis;
private final String statusCallback;
private final HttpMethod statusCallbackMethod;
/**
* For XML Serialization/Deserialization
*/
private VirtualAgent() {
this(new Builder());
}
/**
* Create a new {@code } element
*/
private VirtualAgent(Builder b) {
super("VirtualAgent", b);
this.connectorName = b.connectorName;
this.language = b.language;
this.sentimentAnalysis = b.sentimentAnalysis;
this.statusCallback = b.statusCallback;
this.statusCallbackMethod = b.statusCallbackMethod;
}
/**
* Attributes to set on the generated XML element
*
* @return A Map of attribute keys to values
*/
protected Map getElementAttributes() {
// Preserve order of attributes
Map attrs = new HashMap<>();
if (this.getConnectorName() != null) {
attrs.put("connectorName", this.getConnectorName());
}
if (this.getLanguage() != null) {
attrs.put("language", this.getLanguage());
}
if (this.isSentimentAnalysis() != null) {
attrs.put("sentimentAnalysis", this.isSentimentAnalysis().toString());
}
if (this.getStatusCallback() != null) {
attrs.put("statusCallback", this.getStatusCallback());
}
if (this.getStatusCallbackMethod() != null) {
attrs.put("statusCallbackMethod", this.getStatusCallbackMethod().toString());
}
return attrs;
}
/**
* Defines the conversation profile Dialogflow needs to use
*
* @return Defines the conversation profile Dialogflow needs to use
*/
public String getConnectorName() {
return connectorName;
}
/**
* Language to be used by Dialogflow to transcribe speech
*
* @return Language to be used by Dialogflow to transcribe speech
*/
public String getLanguage() {
return language;
}
/**
* Whether sentiment analysis needs to be enabled or not
*
* @return Whether sentiment analysis needs to be enabled or not
*/
public Boolean isSentimentAnalysis() {
return sentimentAnalysis;
}
/**
* URL to post status callbacks from Twilio
*
* @return URL to post status callbacks from Twilio
*/
public String getStatusCallback() {
return statusCallback;
}
/**
* HTTP method to use when requesting the status callback URL
*
* @return HTTP method to use when requesting the status callback URL
*/
public HttpMethod getStatusCallbackMethod() {
return statusCallbackMethod;
}
/**
* Create a new {@code } element
*/
@JsonPOJOBuilder(withPrefix = "")
public static class Builder extends TwiML.Builder {
/**
* Create and return a {@code } from an XML string
*/
public static Builder fromXml(final String xml) throws TwiMLException {
try {
return OBJECT_MAPPER.readValue(xml, Builder.class);
} catch (final JsonProcessingException jpe) {
throw new TwiMLException(
"Failed to deserialize a VirtualAgent.Builder from the provided XML string: " + jpe.getMessage());
} catch (final Exception e) {
throw new TwiMLException("Unhandled exception: " + e.getMessage());
}
}
private String connectorName;
private String language;
private Boolean sentimentAnalysis;
private String statusCallback;
private HttpMethod statusCallbackMethod;
/**
* Defines the conversation profile Dialogflow needs to use
*/
@JacksonXmlProperty(isAttribute = true, localName = "connectorName")
public Builder connectorName(String connectorName) {
this.connectorName = connectorName;
return this;
}
/**
* Language to be used by Dialogflow to transcribe speech
*/
@JacksonXmlProperty(isAttribute = true, localName = "language")
public Builder language(String language) {
this.language = language;
return this;
}
/**
* Whether sentiment analysis needs to be enabled or not
*/
@JacksonXmlProperty(isAttribute = true, localName = "sentimentAnalysis")
public Builder sentimentAnalysis(Boolean sentimentAnalysis) {
this.sentimentAnalysis = sentimentAnalysis;
return this;
}
/**
* URL to post status callbacks from Twilio
*/
@JacksonXmlProperty(isAttribute = true, localName = "statusCallback")
public Builder statusCallback(String statusCallback) {
this.statusCallback = statusCallback;
return this;
}
/**
* HTTP method to use when requesting the status callback URL
*/
@JacksonXmlProperty(isAttribute = true, localName = "statusCallbackMethod")
public Builder statusCallbackMethod(HttpMethod statusCallbackMethod) {
this.statusCallbackMethod = statusCallbackMethod;
return this;
}
/**
* Add a child {@code } element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Config")
public Builder config(Config config) {
this.children.add(config);
return this;
}
/**
* Add a child {@code } element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Parameter")
public Builder parameter(Parameter parameter) {
this.children.add(parameter);
return this;
}
/**
* Create and return resulting {@code } element
*/
public VirtualAgent build() {
return new VirtualAgent(this);
}
}
}