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.sms.callback.messages; 017 018import java.math.BigDecimal; 019import java.util.Date; 020 021 022 023/** 024 * This represents an incoming MO callback request 025 * 026 * @author Paul Cook 027 */ 028public class MO implements java.io.Serializable { 029 030 private static final long serialVersionUID = 6978599736439760428L; 031 032 private final String messageId; 033 private final MESSAGE_TYPE messageType; 034 private final String sender; 035 private final String destination; 036 private final Date timeStamp; 037 038 private String networkCode; 039 private String keyword; 040 private String messageBody; 041 private byte[] binaryMessageBody; 042 private byte[] userDataHeader; 043 private BigDecimal price; 044 private String sessionId; 045 046 private boolean concat; 047 private String concatReferenceNumber; 048 private int concatTotalParts; 049 private int concatPartNumber; 050 051 /** 052 * Describes the type of payload this message carries 053 */ 054 public enum MESSAGE_TYPE { 055 056 /** 057 * This is a plain text (8 bit alphabet) message 058 */ 059 TEXT ("text"), 060 061 /** 062 * This is a raw binary message 063 */ 064 BINARY ("binary"), 065 066 /** 067 * This is a unicode message 068 */ 069 UNICODE ("unicode"); 070 071 final String type; 072 073 MESSAGE_TYPE(final String type) { 074 this.type = type; 075 } 076 077 /** 078 * @return String A descriptive value representing this type 079 */ 080 public String getType() { 081 return this.type; 082 } 083 084 } 085 086 public MO(final String messageId, 087 final MESSAGE_TYPE messageType, 088 final String sender, 089 final String destination, 090 final BigDecimal price, 091 final Date timeStamp) { 092 this.messageId = messageId; 093 this.messageType = messageType; 094 this.sender = sender; 095 this.destination = destination; 096 this.price = price; 097 this.timeStamp = timeStamp; 098 099 // Set the rest to defaults: 100 101 // text & unicode: 102 messageBody = null; 103 keyword = null; 104 105 // binary: 106 binaryMessageBody = null; 107 userDataHeader = null; 108 109 // concatenation data: 110 concat = false; 111 concatReferenceNumber = null; 112 concatTotalParts = 1; 113 concatPartNumber = 1; 114 115 // TODO: UNDOCUMENTED 116 networkCode = null; 117 sessionId = null; 118 } 119 120 public void setTextData(String text, 121 String keyword) { 122 this.messageBody = text; 123 this.keyword = keyword; 124 } 125 126 public void setBinaryData(byte[] binaryMessageBody, byte[] userDataHeader) { 127 this.binaryMessageBody = binaryMessageBody; 128 this.userDataHeader = userDataHeader; 129 } 130 131 public void setConcatenationData(String concatReferenceNumber, int concatTotalParts, int concatPartNumber) { 132 concat = true; 133 this.concatReferenceNumber = concatReferenceNumber; 134 this.concatTotalParts = concatTotalParts; 135 this.concatPartNumber = concatPartNumber; 136 } 137 138 public void setNetworkCode(String networkCode) { 139 this.networkCode = networkCode; 140 } 141 142 public void setSessionId(String sessionId) { 143 this.sessionId = sessionId; 144 } 145 146 // public MO(final String messageId, 147// final MESSAGE_TYPE messageType, 148// final String sender, 149// final String destination, 150// final String networkCode, 151// final String keyword, 152// final String messageBody, 153// final byte[] binaryMessageBody, 154// final byte[] userDataHeader, 155// final BigDecimal price, 156// final String sessionId, 157// final boolean concat, 158// final String concatReferenceNumber, 159// final int concatTotalParts, 160// final int concatPartNumber, 161// final Date timeStamp) { 162// this.messageId = messageId; 163// this.messageType = messageType; 164// this.sender = sender; 165// this.destination = destination; 166// this.networkCode = networkCode; 167// this.keyword = keyword; 168// this.messageBody = messageBody; 169// this.binaryMessageBody = binaryMessageBody; 170// this.userDataHeader = userDataHeader; 171// this.price = price; 172// this.sessionId = sessionId; 173// this.concat = concat; 174// this.concatReferenceNumber = concatReferenceNumber; 175// this.concatTotalParts = concatTotalParts; 176// this.concatPartNumber = concatPartNumber; 177// this.timeStamp = timeStamp; 178// } 179 180 /** 181 * @return String the id assigned to this message by Vonage before delivery 182 */ 183 public String getMessageId() { 184 return this.messageId; 185 } 186 187 /** 188 * @return MESSAGE_TYPE describes what type of payload this message carries, eg, 8 bit text, unicode text or raw binary 189 */ 190 public MESSAGE_TYPE getMessageType() { 191 return this.messageType; 192 } 193 194 /** 195 * @return String the phone number of the end user that sent this message 196 */ 197 public String getSender() { 198 return this.sender; 199 } 200 201 /** 202 * @return String the short-code/long code number that the end user sent the message to 203 */ 204 public String getDestination() { 205 return this.destination; 206 } 207 208 /** 209 * @return String the network code (if available) of the end user 210 */ 211 public String getNetworkCode() { 212 return this.networkCode; 213 } 214 215 /** 216 * @return String return the first keyword of the message. If this is a shared short-code then this is what the message will have been routed by. 217 */ 218 public String getKeyword() { 219 return this.keyword; 220 } 221 222 /** 223 * @return String The message payload if this is a TEXT or UNICODE message 224 */ 225 public String getMessageBody() { 226 return this.messageBody; 227 } 228 229 /** 230 * @return byte[] the raw binary payload if this is a BINARY message 231 */ 232 public byte[] getBinaryMessageBody() { 233 return this.binaryMessageBody; 234 } 235 236 /** 237 * @return byte[] the raw binary user-data-header if applicable for this message 238 */ 239 public byte[] getUserDataHeader() { 240 return this.userDataHeader; 241 } 242 243 /** 244 * @return BigDecimal if a price was charged for receiving this message, then that is available here 245 */ 246 public BigDecimal getPrice() { 247 return this.price; 248 } 249 250 /** 251 * @return String if this field is populated, then the value should be returned in any MT response 252 */ 253 public String getSessionId() { 254 return this.sessionId; 255 } 256 257 /** 258 * @return boolean is this message part of a concatenated message that needs re-assembly 259 */ 260 public boolean isConcat() { 261 return this.concat; 262 } 263 264 /** 265 * @return String if this message is part of a concatenated set, then this is the reference id that groups the parts together 266 */ 267 public String getConcatReferenceNumber() { 268 return this.concatReferenceNumber; 269 } 270 271 /** 272 * @return String if this message is part of a concatenated set, then this is the total number of parts in the set 273 */ 274 public int getConcatTotalParts() { 275 return this.concatTotalParts; 276 } 277 278 /** 279 * @return String if this message is part of a concatenated set, then this is the 'part number' within the set that this message carries 280 */ 281 public int getConcatPartNumber() { 282 return this.concatPartNumber; 283 } 284 285 /** 286 * @return the timestamp this message was originally received by Vonage 287 */ 288 public Date getTimeStamp() { 289 return this.timeStamp; 290 } 291 292}