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.callback.messages;
017
018import java.math.BigDecimal;
019import java.util.Date;
020
021/**
022 * This represents an incoming MO callback request.
023 *
024 * @deprecated This class is not maintained and will be removed in the next major release.
025 * Please consider using the Messages API instead.
026 */
027@Deprecated
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 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        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    /**
147     * @return String the id assigned to this message by Vonage before delivery
148     */
149    public String getMessageId() {
150        return messageId;
151    }
152
153    /**
154     * @return MESSAGE_TYPE describes what type of payload this message carries, eg, 8 bit text, unicode text or raw binary
155     */
156    public MESSAGE_TYPE getMessageType() {
157        return messageType;
158    }
159
160    /**
161     * @return String the phone number of the end user that sent this message
162     */
163    public String getSender() {
164        return sender;
165    }
166
167    /**
168     * @return String the short-code/long code number that the end user sent the message to
169     */
170    public String getDestination() {
171        return destination;
172    }
173
174    /**
175     * @return String the network code (if available) of the end user
176     */
177    public String getNetworkCode() {
178        return networkCode;
179    }
180
181    /**
182     * @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.
183     */
184    public String getKeyword() {
185        return keyword;
186    }
187
188    /**
189     * @return String The message payload if this is a TEXT or UNICODE message
190     */
191    public String getMessageBody() {
192        return messageBody;
193    }
194
195    /**
196     * @return byte[] the raw binary payload if this is a BINARY message
197     */
198    public byte[] getBinaryMessageBody() {
199        return binaryMessageBody;
200    }
201
202    /**
203     * @return byte[] the raw binary user-data-header if applicable for this message
204     */
205    public byte[] getUserDataHeader() {
206        return userDataHeader;
207    }
208
209    /**
210     * @return BigDecimal if a price was charged for receiving this message, then that is available here
211     */
212    public BigDecimal getPrice() {
213        return price;
214    }
215
216    /**
217     * @return String if this field is populated, then the value should be returned in any MT response
218     */
219    public String getSessionId() {
220        return sessionId;
221    }
222
223    /**
224     * @return boolean is this message part of a concatenated message that needs re-assembly
225     */
226    public boolean isConcat() {
227        return concat;
228    }
229
230    /**
231     * @return String if this message is part of a concatenated set, then this is the reference id that groups the parts together
232     */
233    public String getConcatReferenceNumber() {
234        return concatReferenceNumber;
235    }
236
237    /**
238     * @return String if this message is part of a concatenated set, then this is the total number of parts in the set
239     */
240    public int getConcatTotalParts() {
241        return concatTotalParts;
242    }
243
244    /**
245     * @return String if this message is part of a concatenated set, then this is the 'part number' within the set that this message carries
246     */
247    public int getConcatPartNumber() {
248        return concatPartNumber;
249    }
250
251    /**
252     * @return the timestamp this message was originally received by Vonage
253     */
254    public Date getTimeStamp() {
255        return timeStamp;
256    }
257
258}