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.verify2; 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 com.vonage.client.VonageResponseParseException; 024import java.net.URI; 025import java.time.Instant; 026import java.util.List; 027import java.util.UUID; 028 029/** 030 * Webhook for verification status updates and events. See the 031 * <a href=https://developer.vonage.com/en/api/verify.v2#websockets>API reference</a> for details. 032 */ 033public class VerificationCallback extends JsonableBaseObject { 034 protected Channel channel; 035 protected UUID requestId; 036 protected Instant triggeredAt, finalizedAt, submittedAt; 037 protected VerificationStatus status; 038 protected CallbackType type; 039 protected String clientRef; 040 protected Integer channelTimeout; 041 protected List<WorkflowStatus> workflows; 042 @JsonProperty("action") Action action; 043 044 static class Action extends JsonableBaseObject { 045 @JsonProperty("type") String type; 046 @JsonProperty("check_url") URI checkUrl; 047 } 048 049 protected VerificationCallback() { 050 } 051 052 /** 053 * If {@linkplain #getType()} is {@linkplain CallbackType#EVENT}, this will return 054 * the contact channel of the event update, {@code null} otherwise. 055 * 056 * @return The communication channel, or {@code null} if not applicable. 057 */ 058 @JsonProperty("channel") 059 public Channel getChannel() { 060 return channel; 061 } 062 063 /** 064 * The ID of the request. 065 * 066 * @return The verification request ID. 067 */ 068 @JsonProperty("request_id") 069 public UUID getRequestId() { 070 return requestId; 071 } 072 073 /** 074 * If {@linkplain #getType()} is {@linkplain CallbackType#EVENT}, this will return 075 * the date-time the verification request was triggered in ISO 8601 format, {@code null} otherwise. 076 * 077 * @return The verification request's start timestamp, or {@code null} if not applicable. 078 */ 079 @JsonProperty("triggered_at") 080 public Instant getTriggeredAt() { 081 return triggeredAt; 082 } 083 084 /** 085 * The date and time the verification request was completed in ISO 8601 format 086 * or {@code null} if this callback is not an event update. 087 * 088 * @return The request completion timestamp, or {@code null} if not applicable. 089 */ 090 @JsonProperty("finalized_at") 091 public Instant getFinalizedAt() { 092 return finalizedAt; 093 } 094 095 /** 096 * If {@linkplain #getType()} is {@linkplain CallbackType#SUMMARY}, this will return the 097 * date-time the verification request was submitted in ISO 8601 format, {@code null} otherwise. 098 * 099 * @return The verification request's start timestamp, or {@code null} if not applicable. 100 */ 101 @JsonProperty("submitted_at") 102 public Instant getSubmittedAt() { 103 return submittedAt; 104 } 105 106 /** 107 * Current status of this request. 108 * 109 * @return The request status as an enum. 110 */ 111 @JsonProperty("status") 112 public VerificationStatus getStatus() { 113 return status; 114 } 115 116 /** 117 * Type of response. {@linkplain CallbackType#SUMMARY} only applies to WhatsApp Interactive and Silent Auth. 118 * 119 * @return The event type as an enum. 120 */ 121 @JsonProperty("type") 122 public CallbackType getType() { 123 return type; 124 } 125 126 /** 127 * Contains the client reference given in the original Verify request if one was provided. 128 * 129 * @return The client reference, or {@code null} if not available / applicable. 130 */ 131 @JsonProperty("client_ref") 132 public String getClientRef() { 133 return clientRef; 134 } 135 136 /** 137 * If {@linkplain #getType()} is {@linkplain CallbackType#SUMMARY}, this will return the number of 138 * seconds before the current step in the verification request times out, {@code null} otherwise. 139 * 140 * @return The verification request timeout, or {@code null} if not applicable. 141 */ 142 @JsonProperty("channel_timeout") 143 public Integer getChannelTimeout() { 144 return channelTimeout; 145 } 146 147 /** 148 * If {@linkplain #getType()} is {@linkplain CallbackType#SUMMARY}, this will return metadata of the workflow 149 * steps in the order they were declared / executed along with their status, {@code null} otherwise. 150 * 151 * @return The workflow status updates, or {@code null} if not applicable. 152 */ 153 @JsonProperty("workflow") 154 public List<WorkflowStatus> getWorkflows() { 155 return workflows; 156 } 157 158 /** 159 * If {@linkplain #getChannel()} is {@linkplain Channel#SILENT_AUTH}, this will return 160 * the URL for Silent Auth Verify workflow completion, {@code null} otherwise. 161 * 162 * @return The Silent Authentication URL to check, or {@code null} if not applicable. 163 */ 164 @JsonIgnore 165 public URI getSilentAuthUrl() { 166 if (action == null || channel != Channel.SILENT_AUTH) { 167 return null; 168 } 169 return action.checkUrl; 170 } 171 172 /** 173 * Constructs an instance of this class from a JSON payload. 174 * 175 * @param json The webhook response JSON string. 176 * 177 * @return The deserialized webhook response object. 178 * @throws VonageResponseParseException If the response could not be deserialized. 179 */ 180 @JsonCreator 181 public static VerificationCallback fromJson(String json) { 182 return Jsonable.fromJson(json); 183 } 184}