All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.twilio.twiml.voice.Sms Maven / Gradle / Ivy

There is a newer version: 10.6.4
Show newest version
/**
 * This code was generated by
 * \ / _    _  _|   _  _
 *  | (_)\/(_)(_|\/| |(/_  v1.0.0
 *       /       /
 */

package com.twilio.twiml.voice;

import com.twilio.converter.Promoter;
import com.twilio.http.HttpMethod;
import com.twilio.twiml.TwiML;

import java.net.URI;
import java.util.HashMap;
import java.util.Map;

/**
 * TwiML wrapper for {@code }
 */
public class Sms extends TwiML {
    private final com.twilio.type.PhoneNumber to;
    private final com.twilio.type.PhoneNumber from;
    private final URI action;
    private final HttpMethod method;
    private final URI statusCallback;
    private final String message;

    /**
     * For XML Serialization/Deserialization
     */
    private Sms() {
        this(new Builder((String) null));
    }

    /**
     * Create a new {@code } element
     */
    private Sms(Builder b) {
        super("Sms", b);
        this.to = b.to;
        this.from = b.from;
        this.action = b.action;
        this.method = b.method;
        this.statusCallback = b.statusCallback;
        this.message = b.message;
    }

    /**
     * The body of the TwiML element
     *
     * @return Element body as a string if present else null
     */
    protected String getElementBody() {
        return this.getMessage() == null ? null : this.getMessage();
    }

    /**
     * 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.getTo() != null) {
            attrs.put("to", this.getTo().toString());
        }
        if (this.getFrom() != null) {
            attrs.put("from", this.getFrom().toString());
        }
        if (this.getAction() != null) {
            attrs.put("action", this.getAction().toString());
        }
        if (this.getMethod() != null) {
            attrs.put("method", this.getMethod().toString());
        }
        if (this.getStatusCallback() != null) {
            attrs.put("statusCallback", this.getStatusCallback().toString());
        }

        return attrs;
    }

    /**
     * Number to send message to
     *
     * @return Number to send message to
     */
    public com.twilio.type.PhoneNumber getTo() {
        return to;
    }

    /**
     * Number to send message from
     *
     * @return Number to send message from
     */
    public com.twilio.type.PhoneNumber getFrom() {
        return from;
    }

    /**
     * Action URL
     *
     * @return Action URL
     */
    public URI getAction() {
        return action;
    }

    /**
     * Action URL method
     *
     * @return Action URL method
     */
    public HttpMethod getMethod() {
        return method;
    }

    /**
     * Status callback URL
     *
     * @return Status callback URL
     */
    public URI getStatusCallback() {
        return statusCallback;
    }

    /**
     * Message body
     *
     * @return Message body
     */
    public String getMessage() {
        return message;
    }

    /**
     * Create a new {@code } element
     */
    public static class Builder extends TwiML.Builder {
        private com.twilio.type.PhoneNumber to;
        private com.twilio.type.PhoneNumber from;
        private URI action;
        private HttpMethod method;
        private URI statusCallback;
        private String message;

        /**
         * Create a {@code } with message
         */
        public Builder(String message) {
            this.message = message;
        }

        /**
         * Number to send message to
         */
        public Builder to(com.twilio.type.PhoneNumber to) {
            this.to = to;
            return this;
        }

        /**
         * Number to send message to
         */
        public Builder to(String to) {
            this.to = Promoter.phoneNumberFromString(to);
            return this;
        }

        /**
         * Number to send message from
         */
        public Builder from(com.twilio.type.PhoneNumber from) {
            this.from = from;
            return this;
        }

        /**
         * Number to send message from
         */
        public Builder from(String from) {
            this.from = Promoter.phoneNumberFromString(from);
            return this;
        }

        /**
         * Action URL
         */
        public Builder action(URI action) {
            this.action = action;
            return this;
        }

        /**
         * Action URL
         */
        public Builder action(String action) {
            this.action = Promoter.uriFromString(action);
            return this;
        }

        /**
         * Action URL method
         */
        public Builder method(HttpMethod method) {
            this.method = method;
            return this;
        }

        /**
         * Status callback URL
         */
        public Builder statusCallback(URI statusCallback) {
            this.statusCallback = statusCallback;
            return this;
        }

        /**
         * Status callback URL
         */
        public Builder statusCallback(String statusCallback) {
            this.statusCallback = Promoter.uriFromString(statusCallback);
            return this;
        }

        /**
         * Create and return resulting {@code } element
         */
        public Sms build() {
            return new Sms(this);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy