001/* 002 * Copyright (c) 2011-2017 Nexmo Inc 003 * 004 * Permission is hereby granted, free of charge, to any person obtaining a copy 005 * of this software and associated documentation files (the "Software"), to deal 006 * in the Software without restriction, including without limitation the rights 007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 008 * copies of the Software, and to permit persons to whom the Software is 009 * furnished to do so, subject to the following conditions: 010 * 011 * The above copyright notice and this permission notice shall be included in 012 * all copies or substantial portions of the Software. 013 * 014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 020 * THE SOFTWARE. 021 */ 022package com.nexmo.client.sms.callback.messages; 023 024import java.math.BigDecimal; 025import java.util.Date; 026 027 028 029/** 030 * This represents an incoming MO callback request 031 * 032 * @author Paul Cook 033 */ 034public class MO implements java.io.Serializable { 035 036 private static final long serialVersionUID = 6978599736439760428L; 037 038 private final String messageId; 039 private final MESSAGE_TYPE messageType; 040 private final String sender; 041 private final String destination; 042 private final Date timeStamp; 043 044 private String networkCode; 045 private String keyword; 046 private String messageBody; 047 private byte[] binaryMessageBody; 048 private byte[] userDataHeader; 049 private BigDecimal price; 050 private String sessionId; 051 052 private boolean concat; 053 private String concatReferenceNumber; 054 private int concatTotalParts; 055 private int concatPartNumber; 056 057 /** 058 * Describes the type of payload this message carries 059 */ 060 public enum MESSAGE_TYPE { 061 062 /** 063 * This is a plain text (8 bit alphabet) message 064 */ 065 TEXT ("text"), 066 067 /** 068 * This is a raw binary message 069 */ 070 BINARY ("binary"), 071 072 /** 073 * This is a unicode message 074 */ 075 UNICODE ("unicode"); 076 077 final String type; 078 079 MESSAGE_TYPE(final String type) { 080 this.type = type; 081 } 082 083 /** 084 * @return String A descriptive value representing this type 085 */ 086 public String getType() { 087 return this.type; 088 } 089 090 } 091 092 public MO(final String messageId, 093 final MESSAGE_TYPE messageType, 094 final String sender, 095 final String destination, 096 final BigDecimal price, 097 final Date timeStamp) { 098 this.messageId = messageId; 099 this.messageType = messageType; 100 this.sender = sender; 101 this.destination = destination; 102 this.price = price; 103 this.timeStamp = timeStamp; 104 105 // Set the rest to defaults: 106 107 // text & unicode: 108 messageBody = null; 109 keyword = null; 110 111 // binary: 112 binaryMessageBody = null; 113 userDataHeader = null; 114 115 // concatenation data: 116 concat = false; 117 concatReferenceNumber = null; 118 concatTotalParts = 1; 119 concatPartNumber = 1; 120 121 // TODO: UNDOCUMENTED 122 networkCode = null; 123 sessionId = null; 124 } 125 126 public void setTextData(String text, 127 String keyword) { 128 this.messageBody = text; 129 this.keyword = keyword; 130 } 131 132 public void setBinaryData(byte[] binaryMessageBody, byte[] userDataHeader) { 133 this.binaryMessageBody = binaryMessageBody; 134 this.userDataHeader = userDataHeader; 135 } 136 137 public void setConcatenationData(String concatReferenceNumber, int concatTotalParts, int concatPartNumber) { 138 concat = true; 139 this.concatReferenceNumber = concatReferenceNumber; 140 this.concatTotalParts = concatTotalParts; 141 this.concatPartNumber = concatPartNumber; 142 } 143 144 public void setNetworkCode(String networkCode) { 145 this.networkCode = networkCode; 146 } 147 148 public void setSessionId(String sessionId) { 149 this.sessionId = sessionId; 150 } 151 152 // public MO(final String messageId, 153// final MESSAGE_TYPE messageType, 154// final String sender, 155// final String destination, 156// final String networkCode, 157// final String keyword, 158// final String messageBody, 159// final byte[] binaryMessageBody, 160// final byte[] userDataHeader, 161// final BigDecimal price, 162// final String sessionId, 163// final boolean concat, 164// final String concatReferenceNumber, 165// final int concatTotalParts, 166// final int concatPartNumber, 167// final Date timeStamp) { 168// this.messageId = messageId; 169// this.messageType = messageType; 170// this.sender = sender; 171// this.destination = destination; 172// this.networkCode = networkCode; 173// this.keyword = keyword; 174// this.messageBody = messageBody; 175// this.binaryMessageBody = binaryMessageBody; 176// this.userDataHeader = userDataHeader; 177// this.price = price; 178// this.sessionId = sessionId; 179// this.concat = concat; 180// this.concatReferenceNumber = concatReferenceNumber; 181// this.concatTotalParts = concatTotalParts; 182// this.concatPartNumber = concatPartNumber; 183// this.timeStamp = timeStamp; 184// } 185 186 /** 187 * @return String the id assigned to this message by Nexmo before delivery 188 */ 189 public String getMessageId() { 190 return this.messageId; 191 } 192 193 /** 194 * @return MESSAGE_TYPE describes what type of payload this message carries, eg, 8 bit text, unicode text or raw binary 195 */ 196 public MESSAGE_TYPE getMessageType() { 197 return this.messageType; 198 } 199 200 /** 201 * @return String the phone number of the end user that sent this message 202 */ 203 public String getSender() { 204 return this.sender; 205 } 206 207 /** 208 * @return String the short-code/long code number that the end user sent the message to 209 */ 210 public String getDestination() { 211 return this.destination; 212 } 213 214 /** 215 * @return String the network code (if available) of the end user 216 */ 217 public String getNetworkCode() { 218 return this.networkCode; 219 } 220 221 /** 222 * @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. 223 */ 224 public String getKeyword() { 225 return this.keyword; 226 } 227 228 /** 229 * @return String The message payload if this is a TEXT or UNICODE message 230 */ 231 public String getMessageBody() { 232 return this.messageBody; 233 } 234 235 /** 236 * @return byte[] the raw binary payload if this is a BINARY message 237 */ 238 public byte[] getBinaryMessageBody() { 239 return this.binaryMessageBody; 240 } 241 242 /** 243 * @return byte[] the raw binary user-data-header if applicable for this message 244 */ 245 public byte[] getUserDataHeader() { 246 return this.userDataHeader; 247 } 248 249 /** 250 * @return BigDecimal if a price was charged for receiving this message, then that is available here 251 */ 252 public BigDecimal getPrice() { 253 return this.price; 254 } 255 256 /** 257 * @return String if this field is populated, then the value should be returned in any MT response 258 */ 259 public String getSessionId() { 260 return this.sessionId; 261 } 262 263 /** 264 * @return boolean is this message part of a concatenated message that needs re-assembly 265 */ 266 public boolean isConcat() { 267 return this.concat; 268 } 269 270 /** 271 * @return String if this message is part of a concatenated set, then this is the reference id that groups the parts together 272 */ 273 public String getConcatReferenceNumber() { 274 return this.concatReferenceNumber; 275 } 276 277 /** 278 * @return String if this message is part of a concatenated set, then this is the total number of parts in the set 279 */ 280 public int getConcatTotalParts() { 281 return this.concatTotalParts; 282 } 283 284 /** 285 * @return String if this message is part of a concatenated set, then this is the 'part number' within the set that this message carries 286 */ 287 public int getConcatPartNumber() { 288 return this.concatPartNumber; 289 } 290 291 /** 292 * @return the timestamp this message was originally received by Nexmo 293 */ 294 public Date getTimeStamp() { 295 return this.timeStamp; 296 } 297 298}