Skip to content

Commit 1cd46ed

Browse files
authored
Merge pull request #170 from olimpias/add-query-param-list-messages
Add query param list messages
2 parents 220785e + 99ff401 commit 1cd46ed

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

api/src/main/java/com/messagebird/MessageBirdClient.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ public class MessageBirdClient {
117117
private static final String[] MESSAGE_LIST_FILTERS_VALS = {"originator", "recipient", "direction", "searchterm", "type", "contact_id", "status", "from", "until"};
118118
private static final Set<String> MESSAGE_LIST_FILTERS = new HashSet<>(Arrays.asList(MESSAGE_LIST_FILTERS_VALS));
119119

120+
private static final String[] CONVERSATION_MESSAGE_LIST_FILTERS_VALS = {"ids", "from"};
121+
private static final Set<String> CONVERSATION_MESSAGE_LIST_FILTERS = new HashSet<>(Arrays.asList(CONVERSATION_MESSAGE_LIST_FILTERS_VALS));
122+
120123
private final String DOWNLOADS = "Downloads";
121124

122125
private MessageBirdService messageBirdService;
@@ -1006,6 +1009,23 @@ public ConversationMessage viewConversationMessage(final String messageId)
10061009
return messageBirdService.requestByID(url, messageId, ConversationMessage.class);
10071010
}
10081011

1012+
/**
1013+
* Gets conversation messages based on query param.
1014+
*
1015+
* @param queryParams only `ids` and `from` is available as an option
1016+
* @return The retrieved messages.
1017+
*/
1018+
public ConversationMessageList listConversationMessagesWithQueryParam(Map<String, Object> queryParams)
1019+
throws NotFoundException, GeneralException, UnauthorizedException {
1020+
for (String queryParam : queryParams.keySet()) {
1021+
if (!CONVERSATION_MESSAGE_LIST_FILTERS.contains(queryParam)) {
1022+
throw new IllegalArgumentException("Invalid filter name: " + queryParam);
1023+
}
1024+
}
1025+
String url = CONVERSATIONS_BASE_URL + CONVERSATION_MESSAGE_PATH;
1026+
return messageBirdService.requestByID(url, null, queryParams, ConversationMessageList.class);
1027+
}
1028+
10091029
/**
10101030
* Sends a message to an existing Conversation.
10111031
*
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import com.messagebird.MessageBirdClient;
2+
import com.messagebird.MessageBirdService;
3+
import com.messagebird.MessageBirdServiceImpl;
4+
import com.messagebird.exceptions.GeneralException;
5+
import com.messagebird.exceptions.NotFoundException;
6+
import com.messagebird.exceptions.UnauthorizedException;
7+
import com.messagebird.objects.conversations.ConversationMessageList;
8+
import java.util.HashMap;
9+
10+
public class ExampleListConversationMessagesWithQueryParam {
11+
public static void main(String[] args) {
12+
13+
if (args.length == 0) {
14+
System.out.println("Please specify your access key example : java -jar <this jar file> test_accesskey");
15+
return;
16+
}
17+
18+
// First create your service object
19+
final MessageBirdService wsr = new MessageBirdServiceImpl(args[0]);
20+
21+
// Add the service to the client
22+
final MessageBirdClient messageBirdClient = new MessageBirdClient(wsr);
23+
24+
try {
25+
// Get list of conversation messages with query param
26+
System.out.println("Retrieving message list");
27+
final ConversationMessageList conversationMessageList = messageBirdClient.listConversationMessagesWithQueryParam(
28+
new HashMap<String, Object>() {
29+
{
30+
put("ids", "9f0b413e79e24d76b01b895381b12a6d,d46054ee0f7245bcbc7ba586878d0ab4");
31+
}
32+
});
33+
34+
// Display conversation Message list
35+
System.out.println(conversationMessageList.toString());
36+
} catch (UnauthorizedException | GeneralException | NotFoundException exception) {
37+
if (exception.getErrors() != null) {
38+
System.out.println(exception.getErrors().toString());
39+
}
40+
exception.printStackTrace();
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)