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.sms; 017 018import com.fasterxml.jackson.annotation.JsonCreator; 019import com.fasterxml.jackson.annotation.JsonFormat; 020import com.fasterxml.jackson.annotation.JsonProperty; 021import com.vonage.client.Jsonable; 022import com.vonage.client.JsonableBaseObject; 023import java.time.Instant; 024 025/** 026 * Represents an <a href=https://developer.vonage.com/en/messaging/sms/guides/inbound-sms>Inbound SMS webhook</a>. 027 * 028 * @since 8.3.0 029 */ 030public final class MessageEvent extends JsonableBaseObject { 031 private String msisdn, to, messageId, text, keyword, nonce, data, udh; 032 private MessageType type; 033 private Instant messageTimestamp; 034 private Long timestamp; 035 private Boolean concat; 036 private Integer concatRef, concatTotal, concatPart; 037 038 private MessageEvent() {} 039 040 /** 041 * The phone number that this inbound message was sent from. 042 * 043 * @return The sender number in E.164 format. 044 */ 045 @JsonProperty("msisdn") 046 public String getMsisdn() { 047 return msisdn; 048 } 049 050 /** 051 * Phone number that the message was sent to. This is your virtual number. 052 * 053 * @return The recipient number in E.164 format. 054 */ 055 @JsonProperty("to") 056 public String getTo() { 057 return to; 058 } 059 060 /** 061 * Vonage's unique identifier for this message. 062 * 063 * @return The message ID. 064 */ 065 @JsonProperty("messageId") 066 public String getMessageId() { 067 return messageId; 068 } 069 070 /** 071 * Type of message. 072 * 073 * @return The message type as an enum. 074 */ 075 @JsonProperty("type") 076 public MessageType getType() { 077 return type; 078 } 079 080 /** 081 * Message body for this inbound message. 082 * 083 * @return The text message, or {@code null} if {@linkplain #getType()} is {@linkplain MessageType#BINARY}. 084 */ 085 @JsonProperty("text") 086 public String getText() { 087 return text; 088 } 089 090 /** 091 * The first word in the message body. This is typically used with short codes. 092 * 093 * @return The message keyword, or {@code null} if {@linkplain #getType()} is {@linkplain MessageType#BINARY}. 094 */ 095 @JsonProperty("keyword") 096 public String getKeyword() { 097 return keyword; 098 } 099 100 /** 101 * The binary content of this message. 102 * 103 * @return The message content as a string, or {@code null} if 104 * {@linkplain #getType()} is not {@linkplain MessageType#BINARY}. 105 */ 106 @JsonProperty("data") 107 public String getData() { 108 return data; 109 } 110 111 /** 112 * The hex encoded user data header. 113 * 114 * @return The user data header as a hex-encoded string, or {@code null} if 115 * {@linkplain #getType()} is not {@linkplain MessageType#BINARY}. 116 */ 117 @JsonProperty("udh") 118 public String getUdh() { 119 return udh; 120 } 121 122 /** 123 * The UTC±00:00 time when Vonage started to push this inbound message to your webhook endpoint. 124 * 125 * @return The message timestamp as an Instant. 126 */ 127 @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "UTC") 128 @JsonProperty("message-timestamp") 129 public Instant getMessageTimestamp() { 130 return messageTimestamp; 131 } 132 133 /** 134 * The Unix timestamp representation of {@link #getMessageTimestamp()}. 135 * 136 * @return The Unix timestamp of the message as a Long, or {@code null} if unavailable. 137 */ 138 @JsonProperty("timestamp") 139 public Long getTimestamp() { 140 return timestamp; 141 } 142 143 /** 144 * A random string that adds an extra element of unpredictability into the signature for the request. 145 * You use the nonce and timestamp parameters with your shared secret to calculate and validate the 146 * signature for inbound messages. 147 * 148 * @return The nonce, or {@code null} if the message is unsigned. 149 */ 150 @JsonProperty("nonce") 151 public String getNonce() { 152 return nonce; 153 } 154 155 /** 156 * Whether the message exceeded the maximum-permitted length of a single message. 157 * 158 * @return {@code true} for multipart (concatenated) message, or {@code null} if not applicable. 159 */ 160 @JsonProperty("concat") 161 public Boolean getConcat() { 162 return concat; 163 } 164 165 /** 166 * The transaction reference. All parts of this message share this reference. 167 * 168 * @return The concatenation reference, or {@code null} if not applicable. 169 */ 170 @JsonProperty("concat-ref") 171 public Integer getConcatRef() { 172 return concatRef; 173 } 174 175 /** 176 * The number of parts in this concatenated message. 177 * 178 * @return Total number of messages used, or {@code null} if not applicable. 179 */ 180 @JsonProperty("concat-total") 181 public Integer getConcatTotal() { 182 return concatTotal; 183 } 184 185 /** 186 * The number of this part in the message. The first part of the message is 1. 187 * 188 * @return The sequence number (part) for this message, or {@code null} if not applicable. 189 */ 190 @JsonProperty("concat-part") 191 public Integer getConcatPart() { 192 return concatPart; 193 } 194 195 /** 196 * Creates an instance of this class from a JSON payload. 197 * 198 * @param json The JSON string to parse. 199 * 200 * @return An instance of this class with the fields populated, if present. 201 */ 202 @JsonCreator 203 public static MessageEvent fromJson(String json) { 204 return Jsonable.fromJson(json); 205 } 206}