Skip to content

Java SDK to send messages with


Notifications You must be signed in to change notification settings


Repository files navigation

@cmdotcom/text-sdk: A helper library to send messages.

Want to send messages in your Java application? Then you are at the right place. If you want to get all the functionalities, go to: API Docs


Warning: Namespace has been changed between 1.3 and 2.0

Above 2.0

You can find our SDK here, or below incase you are using a generic pom.xml.


Version 1.3

Version 1.3 is available as JAR under the 1.3 release here
You will have to add GSON manually:

Instantiate the client

Use your productToken which authorizes you on the CM platform. Get yours on

MessagingClient client = new MessagingClient("YourCMProductToken");

Send a message

By calling SendTextMessage and providing message text, sender name, recipient phone number(s).

   MessagingClient client = new MessagingClient("YourProductToken");
   client.sendTextMessage("Message Text", "TestSender", new String[] {"00316012345678"});

Sending a message with auto detect encoding

By using the MessageBuilder it is possible to send messages with auto detect encoding,

It is possible to let our gateway detect the encoding for you by including the type: auto setting. In case it detects characters that are not part of the GSM character set, the message will be delivered as Unicode.

see our API docs for more info

 MessagingClient client = new MessagingClient("YourProductToken");
 MessageBuilder builder = new MessageBuilder("Message Text", "auto",  "TestSender", new String[] {"00316012345678"});
      Message message = builder.Build();


Sending a rich message

By using the MessageBuilder it is possible to create images with media for channels such as WhatsApp and Viber

 MessagingClient client = new MessagingClient("YourProductToken");

 MessageBuilder builder = new MessageBuilder("Message Text", "TestSender", new String[] {"00316012345678"});

 builder.WithAllowedChannels(new Channel[] {Channel.Viber});

    builder.WithRichMessage(new MediaMessage(

       Message message = builder.Build();


Get the result

Sending an message returns the response body

	"details": "Created 1 message(s)",
	"errorCode": 0,
	"messages": [{
		"to": "00316012345678",
		"status": "Accepted",
		"reference": null,
		"parts": 1,
		"messageDetails": null,
		"messageErrorCode": 0

Whatsapp Templates

Send WhatsApp template messages using the message builder please take a look at our documentation in the Whatsapp templates section

MessagingClient client = new MessagingClient("YourProductToken");
 MessageBuilder builder = new MessageBuilder("Template Test", "CM.COM", new String[] {"0031636170815"});

 builder.WithAllowedChannels(new Channel[] {Channel.WhatsApp});       
		TemplateMessage template = new TemplateMessage();
        template.Content = new TemplateMessageContent();
        template.Content.WhatsAppTemplate = new WhatsAppTemplate();
        template.Content.WhatsAppTemplate.Name = "template-name";
        template.Content.WhatsAppTemplate.Namespace = "the-namespace-of-template";
        template.Content.WhatsAppTemplate.Language =  new TemplateLanguage("CountryCode", "deterministic");
        template.Content.WhatsAppTemplate.LocalizableParams = new LocalizableParam[] {};
        template.Content.WhatsAppTemplate.Components = new TemplateComponents[] {new TemplateComponents("header", 
        new TemplateParameters[] { new TemplateParameters("image",  new MediaContent(""", 
        new TemplateComponents("body", 
                          new TemplateParameters[] { new TemplateParameters("text",  "TestMessage"), 
                          new TemplateParameters("text",  "Dutch GP")})};  

		Message message = builder.Build();

Using the OTP API

Send an OTP code

    MessagingClient client = new MessagingClient(yourProductToken);

    OtpRequest request = new OtpRequestBuilder(senderName, recipientNumber)
    .withMessage("Your OTP code is {code}")

    OtpResponse result = client.sendOtpRequest(request);

Verify the response code

    OtpResponse verifyResult = client.verifyOtpRequest(result.getId(), code);
    verifyResult.isVerified(); //represents whether the check was code was correct