001/*
002 *   Copyright 2024 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;
017
018import com.fasterxml.jackson.annotation.JsonCreator;
019import com.fasterxml.jackson.annotation.JsonIgnore;
020import com.fasterxml.jackson.annotation.JsonProperty;
021import com.vonage.client.Jsonable;
022import com.vonage.client.JsonableBaseObject;
023import java.net.URI;
024import java.util.Map;
025import java.util.UUID;
026
027/**
028 * Maps the fields for data sent to the {@code answer_url} configured in your voice application.
029 * See <a href=https://developer.vonage.com/en/voice/voice-api/webhook-reference#answer-webhook>
030 * the webhook reference</a> for details.
031 *
032 * @since 8.2.0
033 */
034public class AnswerWebhook extends JsonableBaseObject {
035    @JsonProperty("endpoint_type") private EndpointType endpointType;
036    @JsonProperty("from") private String from;
037    @JsonProperty("from_user") private String fromUser;
038    @JsonProperty("to") private String to;
039    @JsonProperty("conversation_uuid") private String conversationUuid;
040    @JsonProperty("uuid") private UUID uuid;
041    @JsonProperty("region_url") private URI regionUrl;
042    @JsonProperty("custom_data") private Map<String, ?> customData;
043
044    protected AnswerWebhook() {}
045
046    /**
047     * The type of endpoint that answered the call.
048     *
049     * @return The endpoint type as an enum, or {@code null} if unknown.
050     * @since 8.12.0
051     */
052    public EndpointType getEndpointType() {
053        return endpointType;
054    }
055
056    /**
057     * The user or number that answered the call. This is the virtual number linked to in your application.
058     *
059     * @return The answering user or number in E.164 format.
060     */
061    public String getTo() {
062        return to;
063    }
064
065    /**
066     * The number or user that made the call. This could be a landline or mobile number or another virtual number if
067     * the call was made programmatically. It could also be a username if the call was made by a user.
068     *
069     * @return The calling user or number in E.164 format, or {@code null} if absent.
070     */
071    @JsonIgnore
072    public String getFrom() {
073        return from != null ? from : fromUser;
074    }
075
076    /**
077     * Unique identifier for this conversation. Starts with {@code CON-} followed by a UUID.
078     *
079     * @return The conversation ID as a string.
080     */
081    public String getConversationUuid() {
082        return conversationUuid;
083    }
084
085    /**
086     * Unique identifier for this call.
087     *
088     * @return The call ID as a UUID.
089     */
090    public UUID getUuid() {
091        return uuid;
092    }
093
094    /**
095     * Regional API endpoint which should be used to control the call with REST API; see the
096     * <a href=https://developer.vonage.com/en/voice/voice-api/concepts/regions>full list of regions.</a>
097     *
098     * @return The configured region URL.
099     */
100    public URI getRegionUrl() {
101        return regionUrl;
102    }
103
104    /**
105     * A custom data map, optionally passed as parameter on the {@code callServer} method when a call is initiated
106     * from an application using <a href=https://developer.vonage.com/en/client-sdk/in-app-voice/guides/make-call>
107     * the Client SDK</a>.
108     *
109     * @return The custom data object as a Map, or {@code null} if absent / not applicable.
110     */
111    public Map<String, ?> getCustomData() {
112        return customData;
113    }
114
115    /**
116     * Constructs an instance, populating this class's fields from the JSON string.
117     *
118     * @param json The JSON payload as a string.
119     *
120     * @return A new instance of this class.
121     */
122    @JsonCreator
123    public static AnswerWebhook fromJson(String json) {
124        return Jsonable.fromJson(json);
125    }
126}