Send a Message

Sends a message via TeleMessage service.

MessageResponsesendMessage (AuthenticationDetailsloginDetails, Message message)

Request

Provide the sending user’s authentication details and the message contents.

Property Type Description
loginDetails
AuthenticationDetails The credentials of the user sending the message.
message
Message The message data.

Response

Returns a MessageResponse object, containing the request result code and description. A successfully received message will also include the message ID and key.

Property Type Description
resultCode
int Numeric representation of result (see Error & Status Codes).
resultDescription
String Textual explanation of result (see Error & Status Codes).
messageID
long Unique identifier for each message in the TeleMessage system. Used to track messages throughout the system.
messageID
String Unique key of a message in the TeleMessage system. The key is randomly generated and used for security reasons to acquire the information about the message. This is similar to having a password accompanying a user ID to secure entrance.

 

  •         try {
                Sender s = new SenderServiceLocator().gettelemessage();
                AuthenticationDetails a = new AuthenticationDetails("xxxxx","xxxxxxx");
                Message m = new Message();
                Recipient r = new Recipient();
                r.setValue("+1xxxxxxxxxx");
                r.setType("SMS");
                m.setTextMessage("Hello");
                m.setRecipients(new Recipient[] {r});
                m.setSubject("1st");
                MessageResponse rs = s.sendMessage(a, m);
                System.out.println("Message id: " + rs.getMessageID() + 
                        ", key: " + rs.getMessageKey() + ", result status: " + 
                        rs.getResultCode());
            } catch (ServiceException e) {
                e.printStackTrace();
            } catch (RemoteException e) {
                e.printStackTrace();
            }

    Note: in order to send an IP Push Notification, you would send the message as if you were sending an SMS. TeleMessage checks if the recipient has the application. If so, the message will then be sent as an IP Push Notification. Please configure whether you want to send IP Push Notifications only, or enable SMS Fallback to ensure that messages will be delivered to the recipient in case the IP Push Notification fails via the TeleMessage web portal

    Explore additional code samples & developer resources: 
    JAVA LibraryPHP LibraryREST APIXML APIHTTP API, and more

  • try {
                Sender sender = new SenderServiceLocator().gettelemessage();
                AuthenticationDetailsauthenticationDetails = new AuthenticationDetails
                        ("84738821", "john_doe");
                Message message = new Message();
                // set the message recipients
                Recipient r1 = new Recipient(0, "Mrs. Jane Doe (SMS)", "SMS",
                        +1 - 781 - 3683109"); // sent as an IP message or as SMS
                        Recipient r2 = new Recipient(0, "Mrs. Jane Doe (FAX)", "FAX",
                        "+1-781-6969597"); // sent as fax
                Recipient r3 = new Recipient(0, "Mrs. Jane Doe (HOME)", "HOME_PHONE",
                        "+1-781-6089886"); // sent as a voice message
                Recipient r4 = new Recipient(0, "Mrs. Jane Doe (EMAIL)", "EMAIL",
                        "jane_doe@telemessage.com"); // sent to email as "TO"
                Recipient r5 = new Recipient(1, "Me (EMAIL)", "EMAIL",
                        "john_doe@telemessage.com"); // sent to email as "CC"
                Recipient r6 = new Recipient(0, "Invalid", "INVALID_DEVICE", "12345");
                // try to send to an invalid device type
                message.setRecipients(new Recipient[]{r1, r2, r3, r4, r5, r6});
                // set the message text and subject
                message.setSubject("Pictures");
                message.setTextMessage("Do you like my smile? ;-)");
                // attach two images to the message
                File file = new File("smiley1.jpg");
                FileInputStreamfileInputStream = new FileInputStream(file);
                String base64String = Base64.encodeBase64String(org.apache.commons.
                        io.IOUtils.toByteArray(fileInputStream));
                FileMessage fm1 = new FileMessage(file.getName(), "image/jpg", "", 0,
                        base64String);
                file = new File("smiley2.jpg");
                fileInputStream = new FileInputStream(file);
                base64String = Base64.encodeBase64String(org.apache.commons.io.
                        IOUtils.toByteArray(fileInputStream));
                FileMessage fm2 = new FileMessage(file.getName(), "image/jpg", "", 0,
                        base64String);
                message.setFileMessages(new FileMessage[]{fm1, fm2});
                // send the message and print the result
                MessageResponsemessageResponse = sender.sendMessage(authenticationDetails,
                        message);
                System.out.format("Send message result code: %d%n", messageResponse.
                        getResultCode());
                System.out.format("Send message result description: %s%n", messageResponse.
                        getResultDescription());
                java.lang.Thread.sleep(10000); // give the system time to send the message
                if (messageResponse.getResultCode() == 100) {
                    System.out.format("Message ID: %d, key: %s%n", messageResponse.getMessageID(),
                            messageResponse.getMessageKey());
                }
            } catch (ServiceException e) {
                e.printStackTrace();
            } catch (RemoteException e) {
                e.printStackTrace();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    Note: The value of FileMessage, has to be file data encoded using the Base64 encoding format. In our example we use Apache Commons Codec. Read more about Base64 here.

    Note: in order to send an IP Push Notification, you would send the message as if you were sending an SMS. TeleMessage checks if the recipient has the application. If so, the message will then be sent as an IP Push Notification. Please configure whether you want to send IP Push Notifications only, or enable SMS Fallback to ensure that messages will be delivered to the recipient in case the IP Push Notification fails via the TeleMessage web portal

    Explore additional code samples & developer resources: 
    JAVA LibraryPHP LibraryREST APIXML APIHTTP API, and more