001/*
002 * Copyright (c) 2011-2017 Nexmo Inc
003 *
004 * Permission is hereby granted, free of charge, to any person obtaining a copy
005 * of this software and associated documentation files (the "Software"), to deal
006 * in the Software without restriction, including without limitation the rights
007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008 * copies of the Software, and to permit persons to whom the Software is
009 * furnished to do so, subject to the following conditions:
010 *
011 * The above copyright notice and this permission notice shall be included in
012 * all copies or substantial portions of the Software.
013 *
014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
020 * THE SOFTWARE.
021 */
022package com.nexmo.client.voice.ncco;
023
024import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
025import com.fasterxml.jackson.annotation.JsonInclude;
026
027import java.util.Arrays;
028import java.util.Collection;
029
030/**
031 * An NCCO input action which allows for the collection of digits from a person.
032 */
033@JsonInclude(value = JsonInclude.Include.NON_NULL)
034@JsonIgnoreProperties(ignoreUnknown = true)
035public class InputAction implements Action {
036    private static final String ACTION = "input";
037
038    private Integer timeOut;
039    private Integer maxDigits;
040    private Boolean submitOnHash;
041    private Collection<String> eventUrl;
042    private EventMethod eventMethod;
043
044    /**
045     * @deprecated Use {@link Builder}
046     */
047    @Deprecated
048    public InputAction(Builder builder) {
049        this.timeOut = builder.timeOut;
050        this.maxDigits = builder.maxDigits;
051        this.submitOnHash = builder.submitOnHash;
052        this.eventUrl = builder.eventUrl;
053        this.eventMethod = builder.eventMethod;
054    }
055
056    @Override
057    public String getAction() {
058        return ACTION;
059    }
060
061    public Integer getTimeOut() {
062        return timeOut;
063    }
064
065    public Integer getMaxDigits() {
066        return maxDigits;
067    }
068
069    public Boolean getSubmitOnHash() {
070        return submitOnHash;
071    }
072
073    public Collection<String> getEventUrl() {
074        return eventUrl;
075    }
076
077    public EventMethod getEventMethod() {
078        return eventMethod;
079    }
080
081    public static Builder builder() {
082        return new Builder();
083    }
084
085    public static class Builder {
086        private Integer timeOut = null;
087        private Integer maxDigits = null;
088        private Boolean submitOnHash = null;
089        private Collection<String> eventUrl = null;
090        private EventMethod eventMethod = null;
091
092        /**
093         * @param timeOut The result of the callee's activity is sent to the eventUrl webhook endpoint timeOut seconds
094         *                after the last action. The default value is 3. Max is 10.
095         *
096         * @return The {@link Builder} to keep building.
097         */
098        public Builder timeOut(Integer timeOut) {
099            this.timeOut = timeOut;
100            return this;
101        }
102
103        /**
104         * @param maxDigits The number of digits the user can press. The maximum value is 20, the default is 4 digits.
105         *
106         * @return The {@link Builder} to keep building.
107         */
108        public Builder maxDigits(Integer maxDigits) {
109            this.maxDigits = maxDigits;
110            return this;
111        }
112
113        /**
114         * @param submitOnHash Set to true so the callee's activity is sent to your webhook endpoint at eventUrl after
115         *                     he or she presses #. If # is not pressed the result is submitted after timeOut seconds.
116         *                     The default value is false. That is, the result is sent to your webhook endpoint after
117         *                     timeOut seconds.
118         *
119         * @return The {@link Builder} to keep building.
120         */
121        public Builder submitOnHash(Boolean submitOnHash) {
122            this.submitOnHash = submitOnHash;
123            return this;
124        }
125
126        /**
127         * @param eventUrl Nexmo sends the digits pressed by the callee to this URL after timeOut pause in activity or
128         *                 when # is pressed.
129         *
130         * @return The {@link Builder} to keep building.
131         */
132        public Builder eventUrl(Collection<String> eventUrl) {
133            this.eventUrl = eventUrl;
134            return this;
135        }
136
137        /**
138         * @param eventUrl Nexmo sends the digits pressed by the callee to this URL after timeOut pause in activity or
139         *                 when # is pressed.
140         *
141         * @return The {@link Builder} to keep building.
142         */
143        public Builder eventUrl(String... eventUrl) {
144            return eventUrl(Arrays.asList(eventUrl));
145        }
146
147        /**
148         * @param eventMethod The HTTP method used to send event information to event_url The default value is POST.
149         *
150         * @return The {@link Builder} to keep building.
151         */
152        public Builder eventMethod(EventMethod eventMethod) {
153            this.eventMethod = eventMethod;
154            return this;
155        }
156
157        /**
158         * @return A new {@link InputAction} object from the stored builder options.
159         */
160        public InputAction build() {
161            return new InputAction(this);
162        }
163    }
164}