Skip to content

Commit 4a6fd79

Browse files
authored
Merge pull request #106 from olimpias/media-caption
Media caption is added for conversation
2 parents 3f1ec79 + 27b8ae8 commit 4a6fd79

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

api/src/main/java/com/messagebird/objects/conversations/ConversationContentMedia.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
public class ConversationContentMedia {
88

99
private String url;
10+
private String caption;
11+
12+
public ConversationContentMedia(final String url, final String caption) {
13+
this.url = url;
14+
this.caption = caption;
15+
}
1016

1117
public ConversationContentMedia(final String url) {
1218
this.url = url;
@@ -24,10 +30,19 @@ public void setUrl(final String url) {
2430
this.url = url;
2531
}
2632

33+
public String getCaption() {
34+
return caption;
35+
}
36+
37+
public void setCaption(String caption) {
38+
this.caption = caption;
39+
}
40+
2741
@Override
2842
public String toString() {
2943
return "ConversationContentMedia{" +
3044
"url='" + url + '\'' +
45+
", caption='" + caption + '\'' +
3146
'}';
3247
}
3348
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import com.messagebird.MessageBirdClient;
2+
import com.messagebird.MessageBirdServiceImpl;
3+
import com.messagebird.exceptions.GeneralException;
4+
import com.messagebird.exceptions.UnauthorizedException;
5+
import com.messagebird.objects.conversations.*;
6+
7+
/**
8+
* Created by olimpias on 24/3/20.
9+
*/
10+
public class ExampleSendConversationMessage {
11+
12+
public static void main(String[] args) {
13+
if (args.length < 3) {
14+
System.out.println("Please specify your access key, one ore more phone numbers and a message body example : java -jar <this jar file> test_accesskey 31612345678,3161112233 \"My message to be send\"");
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+
ConversationMessageRequest request = new ConversationMessageRequest();
24+
request.setChannelId(args[1]);
25+
ConversationContent content = new ConversationContent();
26+
ConversationContentMedia media = new ConversationContentMedia("https://example.com/photo.png", "example");
27+
content.setImage(media);
28+
request.setContent(content);
29+
request.setType(ConversationContentType.IMAGE);
30+
try {
31+
final ConversationMessage response = messageBirdClient.sendConversationMessage(args[2], request);
32+
//Display message response
33+
System.out.println(response.toString());
34+
} catch (UnauthorizedException | GeneralException exception) {
35+
if (exception.getErrors() != null) {
36+
System.out.println(exception.getErrors().toString());
37+
}
38+
exception.printStackTrace();
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)