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
15 changes: 15 additions & 0 deletions api/src/main/java/com/messagebird/MessageBirdClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import com.messagebird.objects.conversations.ConversationMessage;
import com.messagebird.objects.conversations.ConversationMessageList;
import com.messagebird.objects.conversations.ConversationMessageRequest;
import com.messagebird.objects.conversations.ConversationSendRequest;
import com.messagebird.objects.conversations.ConversationSendResponse;
import com.messagebird.objects.conversations.ConversationStartRequest;
import com.messagebird.objects.conversations.ConversationStatus;
import com.messagebird.objects.conversations.ConversationWebhook;
Expand Down Expand Up @@ -110,6 +112,7 @@ public class MessageBirdClient {
private static final String VERIFYPATH = "/verify";
private static final String VOICEMESSAGESPATH = "/voicemessages";
private static final String CONVERSATION_PATH = "/conversations";
private static final String CONVERSATION_SEND_PATH = "/send";
private static final String CONVERSATION_MESSAGE_PATH = "/messages";
private static final String CONVERSATION_WEBHOOK_PATH = "/webhooks";
static final String VOICECALLSPATH = "/calls";
Expand Down Expand Up @@ -951,6 +954,18 @@ public Conversation startConversation(ConversationStartRequest request)
return messageBirdService.sendPayLoad(url, request, Conversation.class);
}

/**
* sendMessage allows you to send message to users over any communication platform supported by Programmable Conversations
*
* @param request Data for this request.
* @return The created Message in ConversationSendResponse object.
*/
public ConversationSendResponse sendMessage(ConversationSendRequest request)
throws UnauthorizedException, GeneralException {
String url = String.format("%s%s", this.conversationsBaseUrl, CONVERSATION_SEND_PATH);
return messageBirdService.sendPayLoad(url, request, ConversationSendResponse.class);
}

/**
* Gets a ConversationMessage listing with specified pagination options.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public <T, P> T getJsonData(final String request, final P payload, final String
final String body = apiResponse.getBody();
final int status = apiResponse.getStatus();

if (status == HttpURLConnection.HTTP_OK || status == HttpURLConnection.HTTP_CREATED) {
if (status == HttpURLConnection.HTTP_OK || status == HttpURLConnection.HTTP_CREATED || status == HttpURLConnection.HTTP_ACCEPTED) {
try {
final ObjectMapper mapper = new ObjectMapper();
// If we as new properties, we don't want the system to fail, we rather want to ignore them
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.messagebird.objects.conversations;

public class ConversationFallbackOption {
private String from;
private String after;

public ConversationFallbackOption() {
}

public ConversationFallbackOption(String from, String after) {
this.from = from;
this.after = after;
}

public String getFrom() {
return from;
}

public void setFrom(String from) {
this.from = from;
}

public String getAfter() {
return after;
}

public void setAfter(String after) {
this.after = after;
}

@Override
public String toString() {
return "ConversationFallbackOption{" +
"from='" + from + '\'' +
", after='" + after + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.messagebird.objects.conversations;

public class ConversationSendRequest {
private String to;
private ConversationContentType type;
private ConversationContent content;
private String from;
private String reportUrl;
private ConversationFallbackOption fallback;

public ConversationSendRequest(String to, ConversationContentType type, ConversationContent content, String from, String reportUrl, ConversationFallbackOption fallback) {
this.to = to;
this.type = type;
this.content = content;
this.from = from;
this.reportUrl = reportUrl;
this.fallback = fallback;
}

public ConversationSendRequest() {
}


public String getTo() {
return to;
}

public void setTo(String to) {
this.to = to;
}

public ConversationContentType getType() {
return type;
}

public void setType(ConversationContentType type) {
this.type = type;
}

public ConversationContent getContent() {
return content;
}

public void setContent(ConversationContent content) {
this.content = content;
}

public String getFrom() {
return from;
}

public void setFrom(String from) {
this.from = from;
}

public String getReportUrl() {
return reportUrl;
}

public void setReportUrl(String reportUrl) {
this.reportUrl = reportUrl;
}

public ConversationFallbackOption getFallback() {
return fallback;
}

public void setFallback(ConversationFallbackOption fallback) {
this.fallback = fallback;
}

@Override
public String toString() {
return "ConversationSendRequest{" +
"to='" + to + '\'' +
", type=" + type +
", content=" + content +
", from='" + from + '\'' +
", reportUrl='" + reportUrl + '\'' +
", fallback=" + fallback +
'}';
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.messagebird.objects.conversations;

public class ConversationSendResponse {
private String id; //messageID
private String status;
private FallbackOptionResponse fallback;

public static class FallbackOptionResponse{
private String id;


public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

@Override
public String toString() {
return "FallbackOptionResponse{" +
"id='" + id + '\'' +
'}';
}
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public FallbackOptionResponse getFallback() {
return fallback;
}

public void setFallback(FallbackOptionResponse fallback) {
this.fallback = fallback;
}

@Override
public String toString() {
return "ConversationSendResponse{" +
"id='" + id + '\'' +
", status='" + status + '\'' +
", fallback=" + fallback +
'}';
}
}
51 changes: 51 additions & 0 deletions examples/src/main/java/ExampleConversationSendMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import com.messagebird.MessageBirdClient;
import com.messagebird.MessageBirdService;
import com.messagebird.MessageBirdServiceImpl;
import com.messagebird.exceptions.GeneralException;
import com.messagebird.exceptions.UnauthorizedException;
import com.messagebird.objects.conversations.ConversationContent;
import com.messagebird.objects.conversations.ConversationContentType;
import com.messagebird.objects.conversations.ConversationFallbackOption;
import com.messagebird.objects.conversations.ConversationSendRequest;
import com.messagebird.objects.conversations.ConversationSendResponse;

public class ExampleConversationSendMessage {

public static void main(String[] args) {
if (args.length < 3) {
System.out.println("Please at least specify your access key, the channel id and destination address.\n" +
"Usage : java -jar <this jar file> test_accesskey(Required) channel_id(Required) to(Required) fallback_channel_id(optional)");
return;
}

//First create your service object
final MessageBirdService wsr = new MessageBirdServiceImpl(args[0]);
//Add the service to the client
final MessageBirdClient messageBirdClient = new MessageBirdClient(wsr);



ConversationFallbackOption fallbackOption = null;
if (args.length == 4) {
fallbackOption = new ConversationFallbackOption(args[3], "5m");
}
ConversationContent conversationContent = new ConversationContent();
conversationContent.setText("Hello world from java sdk");

ConversationSendRequest request = new ConversationSendRequest(
args[1],
ConversationContentType.TEXT,
conversationContent,
args[2],
"",
fallbackOption);

try {
ConversationSendResponse sendResponse = messageBirdClient.sendMessage(request);
System.out.println(sendResponse.toString());

} catch (GeneralException | UnauthorizedException exception) {
exception.printStackTrace();
}
}
}