|
| 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