Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,21 @@ By using the `MessageBuilder` it is possible to create images with media for cha

client.sendMessage(message);
```

## Get the result
Sending an message returns the response body
```cs
{
"details": "Created 1 message(s)",
"errorCode": 0,
"messages": [{
"to": "00316012345678",
"status": "Accepted",
"reference": null,
"parts": 1,
"messageDetails": null,
"messageErrorCode": 0
}]
}
```

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
<version>2.8.2</version>
</dependency>
</dependencies>
</project>
81 changes: 0 additions & 81 deletions src/main/java/MessagingClient.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.cmtelecom.text.sdk;

public class Config {

public static String ApiUrl = "https://gw.cmtelecom.com/v1.0/message";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import models.Body;
import models.Channel;
import models.Message;
import models.Recipient;
import models.multichannel.IRichMessage;
import models.multichannel.RichContent;
import models.multichannel.Suggestion;
package com.cmtelecom.text.sdk;

import com.cmtelecom.text.sdk.models.Body;
import com.cmtelecom.text.sdk.models.Channel;
import com.cmtelecom.text.sdk.models.Message;
import com.cmtelecom.text.sdk.models.Recipient;
import com.cmtelecom.text.sdk.models.multichannel.IRichMessage;
import com.cmtelecom.text.sdk.models.multichannel.RichContent;
import com.cmtelecom.text.sdk.models.multichannel.Suggestion;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MessageBuilder {
Expand Down
78 changes: 78 additions & 0 deletions src/main/java/com/cmtelecom/text/sdk/MessagingClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.cmtelecom.text.sdk;

import com.google.gson.Gson;
import com.cmtelecom.text.sdk.models.Message;
import com.cmtelecom.text.sdk.models.Request;
import com.cmtelecom.text.sdk.models.Response;
import com.cmtelecom.text.sdk.utils.HttpHelper;

public class MessagingClient {

private String productToken;


public MessagingClient( String productToken ) {
this.productToken = productToken;
}


public Response.HttpResponseBody sendTextMessage( String messageText, String from, String[] to ) {

MessageBuilder builder = new MessageBuilder( messageText, from, to );

Message message = builder.Build();

String body = GetHttpPostBody( productToken, message );

String result = HttpHelper.post( Config.ApiUrl, body );

return getResponseBody( result );
}


public Response.HttpResponseBody sendMessage( Message message ) {
String body = GetHttpPostBody( productToken, message );
String result = HttpHelper.post( Config.ApiUrl, body );
return getResponseBody( result );
}


/// <summary>
/// Gets the HTTP post body.
/// </summary>
/// <param name="apiKey">The API key.</param>
/// <param name="message">The message to send.</param>
/// <returns></returns>
protected static Response.HttpResponseBody getResponseBody( String body ) {
try {
Response.HttpResponseBody result = new Gson().fromJson( body, Response.HttpResponseBody.class );
return result;
}
catch ( Exception e ) {
throw new RuntimeException( "Invalid json response-body", e );
}
}


/// <summary>
/// Gets the HTTP post body.
/// </summary>
/// <param name="apiKey">The API key.</param>
/// <param name="message">The message to send.</param>
/// <returns></returns>
protected static String GetHttpPostBody( String productToken, Message message ) {
Request.Messages messages = new Request.Messages();
Request.MessagesEnvelope request = new Request.MessagesEnvelope();
request.setAuthentication( new Request.Authentication( productToken ) );
Message[] msg = new Message[]{ message };
request.setMessages( msg );
messages.setMessages( request );
try {
return new Gson().toJson( messages );
}
catch ( Exception e ) {
throw new RuntimeException( "Invalid request body", e );
}
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models;
package com.cmtelecom.text.sdk.models;

import com.google.gson.annotations.SerializedName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models;
package com.cmtelecom.text.sdk.models;

public enum Channel {
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models;
package com.cmtelecom.text.sdk.models;

import com.google.gson.annotations.SerializedName;

Expand Down Expand Up @@ -113,7 +113,7 @@ public class Message {
public String Reference;


public models.multichannel.RichContent RichContent;
public com.cmtelecom.text.sdk.models.multichannel.RichContent RichContent;


public Message(Body body, String from, List<Recipient> recipientList) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models;
package com.cmtelecom.text.sdk.models;

import com.google.gson.annotations.SerializedName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models;
package com.cmtelecom.text.sdk.models;

import com.google.gson.annotations.SerializedName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models;
package com.cmtelecom.text.sdk.models;



Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models.multichannel;
package com.cmtelecom.text.sdk.models.multichannel;

import com.google.gson.annotations.SerializedName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models.multichannel;
package com.cmtelecom.text.sdk.models.multichannel;

public enum CarouselCardWidth {
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models.multichannel;
package com.cmtelecom.text.sdk.models.multichannel;

import com.google.gson.annotations.SerializedName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models.multichannel;
package com.cmtelecom.text.sdk.models.multichannel;

import com.google.gson.annotations.SerializedName;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.cmtelecom.text.sdk.models.multichannel;

public interface IRichMessage {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models.multichannel;
package com.cmtelecom.text.sdk.models.multichannel;

public class MediaContent {
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models.multichannel;
package com.cmtelecom.text.sdk.models.multichannel;

import com.google.gson.annotations.SerializedName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models.multichannel;
package com.cmtelecom.text.sdk.models.multichannel;

import com.google.gson.annotations.SerializedName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models.multichannel;
package com.cmtelecom.text.sdk.models.multichannel;

import com.google.gson.annotations.SerializedName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models.multichannel;
package com.cmtelecom.text.sdk.models.multichannel;

import com.google.gson.annotations.SerializedName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models.multichannel;
package com.cmtelecom.text.sdk.models.multichannel;

import com.google.gson.annotations.SerializedName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models.multichannel;
package com.cmtelecom.text.sdk.models.multichannel;

import com.google.gson.annotations.SerializedName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models.multichannel;
package com.cmtelecom.text.sdk.models.multichannel;

import com.google.gson.annotations.SerializedName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models.multichannel;
package com.cmtelecom.text.sdk.models.multichannel;

import com.google.gson.annotations.SerializedName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models.multichannel;
package com.cmtelecom.text.sdk.models.multichannel;

import com.google.gson.annotations.SerializedName;

Expand Down
Loading