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.messages; 017 018import java.util.Map; 019 020/** 021 * Represents the details of a plain-text message that is to be submitted via the Vonage REST api. 022 */ 023public class TextMessage extends Message { 024 private final String messageBody; 025 026 /** 027 * Instantiate a new text-message request.<br> 028 * This message will be submitted as a regular 8 bit text message 029 * 030 * @param from the 'from' address that will be seen on the handset when this message arrives, 031 * typically either a valid short-code / long code that can be replied to, or a short text 032 * description of the application sending the message (Max 11 chars) 033 * @param to the phone number of the handset that you wish to send the message to 034 * @param messageBody The text of the message to be sent to the handset 035 */ 036 public TextMessage(final String from, 037 final String to, 038 final String messageBody) { 039 this(from, to, messageBody, false); 040 } 041 042 /** 043 * Instantiate a new text-message request.<br> 044 * This message will be submitted as a regular 8 bit text message 045 * 046 * @param from the 'from' address that will be seen on the handset when this message arrives, 047 * typically either a valid short-code / long code that can be replied to, or a short text 048 * description of the application sending the message (Max 11 chars) 049 * @param to the phone number of the handset that you wish to send the message to 050 * @param messageBody The text of the message to be sent to the handset 051 * @param unicode set this flag to true if the message needs to be submitted as a unicode message 052 */ 053 public TextMessage(final String from, 054 final String to, 055 final String messageBody, 056 final boolean unicode) { 057 super(unicode ? MessageType.UNICODE : MessageType.TEXT, from, to); 058 this.messageBody = messageBody; 059 } 060 061 /** 062 * @return String The text of the message to be sent to the handset 063 */ 064 public String getMessageBody() { 065 return messageBody; 066 } 067 068 /** 069 * @return boolean This flag is set to true if the message needs to be submitted as a unicode message. This would 070 * be for scenario's where the message contains text that does not fit within the Latin GSM alphabet. Examples 071 * would be messages to be sent in non-western scripts, such as Arabic, Kanji, Chinese, etc. 072 */ 073 public boolean isUnicode() { 074 return getType() == MessageType.UNICODE; 075 } 076 077 @Override 078 public Map<String, String> makeParams() { 079 Map<String, String> params = super.makeParams(); 080 params.put("text", getMessageBody()); 081 return params; 082 } 083}