001/* 002 * Copyright 2020 Vonage 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.vonage.client.voice.ncco; 017 018import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 019import com.fasterxml.jackson.annotation.JsonInclude; 020 021import java.util.Arrays; 022import java.util.Collection; 023 024/** 025 * An NCCO input action which allows for the collection of digits from a person. 026 */ 027@JsonInclude(value = JsonInclude.Include.NON_NULL) 028@JsonIgnoreProperties(ignoreUnknown = true) 029public class InputAction implements Action { 030 private static final String ACTION = "input"; 031 032 private Integer timeOut; 033 private Integer maxDigits; 034 private Boolean submitOnHash; 035 private Collection<String> eventUrl; 036 private EventMethod eventMethod; 037 038 /** 039 * @deprecated Use {@link Builder} 040 */ 041 @Deprecated 042 public InputAction(Builder builder) { 043 this.timeOut = builder.timeOut; 044 this.maxDigits = builder.maxDigits; 045 this.submitOnHash = builder.submitOnHash; 046 this.eventUrl = builder.eventUrl; 047 this.eventMethod = builder.eventMethod; 048 } 049 050 @Override 051 public String getAction() { 052 return ACTION; 053 } 054 055 public Integer getTimeOut() { 056 return timeOut; 057 } 058 059 public Integer getMaxDigits() { 060 return maxDigits; 061 } 062 063 public Boolean getSubmitOnHash() { 064 return submitOnHash; 065 } 066 067 public Collection<String> getEventUrl() { 068 return eventUrl; 069 } 070 071 public EventMethod getEventMethod() { 072 return eventMethod; 073 } 074 075 public static Builder builder() { 076 return new Builder(); 077 } 078 079 public static class Builder { 080 private Integer timeOut = null; 081 private Integer maxDigits = null; 082 private Boolean submitOnHash = null; 083 private Collection<String> eventUrl = null; 084 private EventMethod eventMethod = null; 085 086 /** 087 * @param timeOut The result of the callee's activity is sent to the eventUrl webhook endpoint timeOut seconds 088 * after the last action. The default value is 3. Max is 10. 089 * 090 * @return The {@link Builder} to keep building. 091 */ 092 public Builder timeOut(Integer timeOut) { 093 this.timeOut = timeOut; 094 return this; 095 } 096 097 /** 098 * @param maxDigits The number of digits the user can press. The maximum value is 20, the default is 4 digits. 099 * 100 * @return The {@link Builder} to keep building. 101 */ 102 public Builder maxDigits(Integer maxDigits) { 103 this.maxDigits = maxDigits; 104 return this; 105 } 106 107 /** 108 * @param submitOnHash Set to true so the callee's activity is sent to your webhook endpoint at eventUrl after 109 * he or she presses #. If # is not pressed the result is submitted after timeOut seconds. 110 * The default value is false. That is, the result is sent to your webhook endpoint after 111 * timeOut seconds. 112 * 113 * @return The {@link Builder} to keep building. 114 */ 115 public Builder submitOnHash(Boolean submitOnHash) { 116 this.submitOnHash = submitOnHash; 117 return this; 118 } 119 120 /** 121 * @param eventUrl Vonage sends the digits pressed by the callee to this URL after timeOut pause in activity or 122 * when # is pressed. 123 * 124 * @return The {@link Builder} to keep building. 125 */ 126 public Builder eventUrl(Collection<String> eventUrl) { 127 this.eventUrl = eventUrl; 128 return this; 129 } 130 131 /** 132 * @param eventUrl Vonage sends the digits pressed by the callee to this URL after timeOut pause in activity or 133 * when # is pressed. 134 * 135 * @return The {@link Builder} to keep building. 136 */ 137 public Builder eventUrl(String... eventUrl) { 138 return eventUrl(Arrays.asList(eventUrl)); 139 } 140 141 /** 142 * @param eventMethod The HTTP method used to send event information to event_url The default value is POST. 143 * 144 * @return The {@link Builder} to keep building. 145 */ 146 public Builder eventMethod(EventMethod eventMethod) { 147 this.eventMethod = eventMethod; 148 return this; 149 } 150 151 /** 152 * @return A new {@link InputAction} object from the stored builder options. 153 */ 154 public InputAction build() { 155 return new InputAction(this); 156 } 157 } 158}