Skip to content

Commit bda874d

Browse files
Merge pull request #6 from telstra/maintain/v3
Update message sending
2 parents 2d3cd9a + 1ae3fd1 commit bda874d

File tree

5 files changed

+111
-76
lines changed

5 files changed

+111
-76
lines changed

README.md

+59-53
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Add this dependency to your project's POM:
6868
<dependency>
6969
<groupId>com.telstra.messaging</groupId>
7070
<artifactId>telstra-messaging</artifactId>
71-
<version>3.0-SNAPSHOT</version>
71+
<version>3.1-SNAPSHOT</version>
7272
</dependency>
7373
```
7474

@@ -615,7 +615,7 @@ The function `messages.send` can be used to send a message.
615615

616616
It takes an object with following properties as argument:
617617

618-
- `to`: The destination address, expected to be a phone number of the form `+614XXXXXXXX` or `04XXXXXXXX`.
618+
- `to`: The destination address list, expected to be a phone number of the form `+614XXXXXXXX` or `04XXXXXXXX`.
619619
- `from`: This will be either one of your Virtual Numbers or your senderName.
620620
- `messageContent` (Either one of messageContent or multimedia is required): The content of the message.
621621
- `multimedia` (Either one of messageContent or multimedia is required): MMS multimedia content.
@@ -636,7 +636,7 @@ It returns an object with the following properties:
636636

637637
- `messageId`: Use this UUID with our other endpoints to fetch, update or delete the message.
638638
- `status`: The status will be either queued, sent, delivered or expired.
639-
- `to`: The recipient's mobile number(s).
639+
- `to`: The list of recipient's mobile number(s).
640640
- `from`: This will be either one of your Virtual Numbers or your senderName.
641641
- `messageContent`: The content of the message.
642642
- `multimedia`: The multimedia content of the message (MMS only).
@@ -662,59 +662,65 @@ import static org.junit.Assert.assertEquals;
662662
import static org.junit.Assert.assertNotNull;
663663

664664
try{
665-
ApiClient defaultClient = new ApiClient();
666-
ApiClient apiClient = getAuthToken(defaultClient);
667-
MessagesApi messagesApi = new MessagesApi(apiClient);
668-
String to = "0411220643";
669-
String from = "0400000004";
670-
String messageContent = "Hello customer, this is from CBA to confirme your offer!";
671-
Multimedia multimedia = new Multimedia();
672-
String type = "image/jpeg";
673-
String fileName = "image/jpeg";
674-
String payload = "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";
675-
multimedia.setType(type);
676-
multimedia.setFileName(fileName);
677-
multimedia.setPayload(payload);
678-
List<Multimedia> multimediaList = new ArrayList<>();
679-
multimediaList.add(multimedia);
680-
Integer retryTimeout = 10;
681-
String scheduleSend = "2023-09-11T03:48:47.096Z";
682-
Boolean deliveryNotification = false;
683-
String statusCallbackUrl = "http://www.example.com";
684-
List<String> tagsList = new ArrayList<>();
685-
tagsList.add("laborum");
686-
tagsList.add("esse");
687-
tagsList.add("irure Lorem");
688-
tagsList.add("dolore aliqu");
689-
tagsList.add("pariatur do proident magna ut");
690-
tagsList.add("id sunt");
691-
tagsList.add("u");
692-
tagsList.add("tempor velit minim");
693-
tagsList.add("sit dolo");
694-
tagsList.add("laborum qui");
665+
ApiClient defaultClient = new ApiClient();
666+
ApiClient apiClient = getAuthToken(defaultClient);
667+
MessagesApi messagesApi = new MessagesApi(apiClient);
695668

696-
SendMessagesRequest sendMessagesRequest = new SendMessagesRequest()
697-
.to(to)
698-
.from(from)
699-
.messageContent(messageContent)
700-
.multimedia(multimediaList)
701-
.retryTimeout(retryTimeout)
702-
.scheduleSend(scheduleSend)
703-
.deliveryNotification(deliveryNotification)
704-
.statusCallbackUrl(statusCallbackUrl)
705-
.tags(tagsList);
669+
List<String> toList = new ArrayList<>();
670+
toList.add("0400000001");
671+
toList.add("0400000002");
672+
String from = "0400000001";
673+
String messageContent = "Hello customer, this is from CBA to confirme your offer!";
706674

707-
MessageSent response = messagesApi.sendMessages(sendMessagesRequest);
708-
System.out.println(response);
709-
assertNotNull(response.getMessageId());
710-
675+
Multimedia multimedia = new Multimedia();
676+
String type = "image/jpeg";
677+
String fileName = "image/jpeg";
678+
String payload = "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";
679+
multimedia.setType(type);
680+
multimedia.setFileName(fileName);
681+
multimedia.setPayload(payload);
682+
List<Multimedia> multimediaList = new ArrayList<>();
683+
multimediaList.add(multimedia);
684+
685+
Integer retryTimeout = 10;
686+
String scheduleSend = "2024-08-15T20:48:47.096Z";
687+
Boolean deliveryNotification = false;
688+
String statusCallbackUrl = "http://www.example.com";
689+
List<String> tagsList = new ArrayList<>();
690+
tagsList.add("laborum");
691+
tagsList.add("esse");
692+
tagsList.add("irure Lorem");
693+
tagsList.add("dolore aliqu");
694+
tagsList.add("pariatur do proident magna ut");
695+
tagsList.add("id sunt");
696+
tagsList.add("u");
697+
tagsList.add("tempor velit minim");
698+
tagsList.add("sit dolo");
699+
tagsList.add("laborum qui");
700+
701+
SendMessagesRequest sendMessagesRequest = new SendMessagesRequest()
702+
.to(toList)
703+
.from(from)
704+
.messageContent(messageContent)
705+
.multimedia(multimediaList)
706+
.retryTimeout(retryTimeout)
707+
.scheduleSend(scheduleSend)
708+
.deliveryNotification(deliveryNotification)
709+
.statusCallbackUrl(statusCallbackUrl)
710+
.tags(tagsList);
711+
712+
713+
MessageSent response = messagesApi.sendMessages(sendMessagesRequest);
714+
System.out.println(response);
715+
assertNotNull(response.getMessageId());
716+
711717
} catch (ApiException e) {
712-
System.err.println("Exception when calling MessagesApi");
713-
System.err.println("Status code: " + e.getCode());
714-
System.err.println("Reason: " + e.getResponseBody());
715-
System.err.println("Response headers: " + e.getResponseHeaders());
716-
e.printStackTrace();
717-
}
718+
System.err.println("Exception when calling MessagesApi");
719+
System.err.println("Status code: " + e.getCode());
720+
System.err.println("Reason: " + e.getResponseBody());
721+
System.err.println("Response headers: " + e.getResponseHeaders());
722+
e.printStackTrace();
723+
}
718724

719725
```
720726

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<artifactId>telstra-messaging</artifactId>
66
<packaging>jar</packaging>
77
<name>telstra-messaging</name>
8-
<version>3.0-SNAPSHOT</version>
8+
<version>3.1-SNAPSHOT</version>
99
<url>https://github.com/swagger-api/swagger-codegen</url>
1010
<description>Swagger Java</description>
1111
<scm>

src/main/java/com/telstra/MessageSent.java

+16-9
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030

3131
public class MessageSent {
3232
@SerializedName("messageId")
33-
//private List<String> messageId = null;
34-
private UUID messageId = null;
33+
private List<UUID> messageId = null;
3534

3635
/**
3736
* The status will be either queued, sent, delivered, expired or undeliverable.
@@ -81,7 +80,7 @@ public StatusEnum read(final JsonReader jsonReader) throws IOException {
8180
private StatusEnum status = null;
8281

8382
@SerializedName("to")
84-
private String to = null;
83+
private List<String> to = null;
8584

8685
@SerializedName("from")
8786
private String from = null;
@@ -107,7 +106,7 @@ public StatusEnum read(final JsonReader jsonReader) throws IOException {
107106
@SerializedName("tags")
108107
private List<String> tags = null;
109108

110-
public MessageSent messageId(UUID messageId) {
109+
public MessageSent messageId(List<UUID> messageId) {
111110
this.messageId = messageId;
112111
return this;
113112
}
@@ -117,11 +116,11 @@ public MessageSent messageId(UUID messageId) {
117116
* @return messageId
118117
**/
119118
@Schema(description = "Use this UUID with our other endpoints to fetch, update or delete the message.")
120-
public UUID getMessageId() {
119+
public List<UUID> getMessageId() {
121120
return messageId;
122121
}
123122

124-
public void setMessageId(UUID messageId) {
123+
public void setMessageId(List<UUID> messageId) {
125124
this.messageId = messageId;
126125
}
127126

@@ -143,21 +142,29 @@ public void setStatus(StatusEnum status) {
143142
this.status = status;
144143
}
145144

146-
public MessageSent to(String to) {
145+
public MessageSent to(List<String> to) {
147146
this.to = to;
148147
return this;
149148
}
150149

150+
public MessageSent addToItem(String toItem) {
151+
if (this.to == null) {
152+
this.to = new ArrayList<String>();
153+
}
154+
this.to.add(toItem);
155+
return this;
156+
}
157+
151158
/**
152159
* The recipient&#x27;s mobile number(s).
153160
* @return to
154161
**/
155162
@Schema(description = "The recipient's mobile number(s).")
156-
public String getTo() {
163+
public List<String> getTo() {
157164
return to;
158165
}
159166

160-
public void setTo(String to) {
167+
public void setTo(List<String> to) {
161168
this.to = to;
162169
}
163170

src/main/java/com/telstra/SendMessagesRequest.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
public class SendMessagesRequest {
2929
public static final String SERIALIZED_NAME_TO = "to";
3030
@SerializedName(SERIALIZED_NAME_TO)
31-
private String to;
31+
//private String to;
32+
private List<String> to;
3233

3334
public static final String SERIALIZED_NAME_FROM = "from";
3435
@SerializedName(SERIALIZED_NAME_FROM)
@@ -65,21 +66,29 @@ public class SendMessagesRequest {
6566
public SendMessagesRequest() {
6667
}
6768

68-
public SendMessagesRequest to(String to) {
69+
public SendMessagesRequest to(List<String> to) {
6970
this.to = to;
7071
return this;
7172
}
7273

74+
public SendMessagesRequest addToItem(String toItem) {
75+
if (this.to == null) {
76+
this.to = new ArrayList<>();
77+
}
78+
this.to.add(toItem);
79+
return this;
80+
}
81+
7382
/**
7483
* Get to
7584
* @return to
7685
**/
77-
public String getTo() {
86+
public List<String> getTo() {
7887
return to;
7988
}
8089

8190

82-
public void setTo(String to) {
91+
public void setTo(List<String> to) {
8392
this.to = to;
8493
}
8594

src/test/java/com/telstra/messaging/MessagesApiTest.java

+22-9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import static com.telstra.messaging.AuthenticationApi.getAuthToken;
2222
import static org.junit.Assert.assertEquals;
2323
import static org.junit.Assert.assertNotNull;
24+
import java.time.ZonedDateTime;
25+
2426

2527

2628
/**
@@ -56,7 +58,7 @@ public void deleteMessageByIdTest() {
5658
try{
5759
ApiClient apiClient = getAuthToken(defaultClient);
5860
MessagesApi messagesApi = new MessagesApi(apiClient);
59-
UUID messageId = UUID.fromString("119be970-4c71-11ee-a651-ad71114ff6eb");
61+
UUID messageId = UUID.fromString("e15795c1-593f-11ef-be6c-ad62561304a2");
6062

6163
messagesApi.deleteMessageById(messageId);
6264

@@ -78,7 +80,7 @@ public void getMessageByIdTest() {
7880
try{
7981
ApiClient apiClient = getAuthToken(defaultClient);
8082
MessagesApi messagesApi = new MessagesApi(apiClient);
81-
UUID messageId = UUID.fromString("3f58be60-4c71-11ee-a5b2-b5976390898d");
83+
UUID messageId = UUID.fromString("b6980a40-53b8-11ef-8c15-dfa116f49bba");
8284

8385
MessageGet response = messagesApi.getMessageById(messageId);
8486
System.out.println(response);
@@ -127,15 +129,18 @@ public void getMessagesTest() {
127129
* Send an SMS/MMS to a mobile number, or to multiple mobile numbers. Free Trial users can message to up to 10 unique recipient numbers for free. The first five recipients will be automatically added to your Free Trial Numbers list. Need more? Just use the POST /free-trial-numbers call to add another five.
128130
* if the Api call fails
129131
*/
132+
//@Test
130133
@Ignore
131134
public void sendMessagesTest() {
132135

133136
try{
134137
ApiClient apiClient = getAuthToken(defaultClient);
135138
MessagesApi messagesApi = new MessagesApi(apiClient);
136139

137-
String to = "0400000001";
138-
String from = "0428180739";
140+
List<String> toList = new ArrayList<>();
141+
toList.add("0400000001");
142+
toList.add("0400000002");
143+
String from = "0400000001";
139144
String messageContent = "Hello customer, this is from CBA to confirme your offer!";
140145

141146
Multimedia multimedia = new Multimedia();
@@ -150,7 +155,11 @@ public void sendMessagesTest() {
150155

151156
Integer retryTimeout = 10;
152157

153-
String scheduleSend = "2023-09-26T20:48:47.096Z";
158+
String scheduleSend = "2024-08-15T20:48:47.096Z";
159+
ZonedDateTime zdt = ZonedDateTime.parse(scheduleSend);
160+
ZonedDateTime zdtPlusTwoDays = zdt.plusDays(2);
161+
scheduleSend = zdtPlusTwoDays.toString();
162+
154163
Boolean deliveryNotification = false;
155164
String statusCallbackUrl = "http://www.example.com";
156165
List<String> tagsList = new ArrayList<>();
@@ -166,7 +175,7 @@ public void sendMessagesTest() {
166175
tagsList.add("laborum qui");
167176

168177
SendMessagesRequest sendMessagesRequest = new SendMessagesRequest()
169-
.to(to)
178+
.to(toList)
170179
.from(from)
171180
.messageContent(messageContent)
172181
.multimedia(multimediaList)
@@ -202,7 +211,7 @@ public void updateMessageByIdTest() {
202211
try{
203212
ApiClient apiClient = getAuthToken(defaultClient);
204213
MessagesApi messagesApi = new MessagesApi(apiClient);
205-
UUID messageId = UUID.fromString("e31106b0-5c35-11ee-a710-0fd7aacbc74b");
214+
UUID messageId = UUID.fromString("88ed8550-59cd-11ef-be6b-3de6ec7e1aaa");
206215

207216
String to = "0400000001";
208217
String from = "0400000001";
@@ -220,7 +229,11 @@ public void updateMessageByIdTest() {
220229

221230
Integer retryTimeout = 10;
222231

223-
String scheduleSend = "2023-09-26T20:48:47.096Z";
232+
String scheduleSend = "2024-08-15T20:48:47.096Z";
233+
ZonedDateTime zdt = ZonedDateTime.parse(scheduleSend);
234+
ZonedDateTime zdtPlusTwoDays = zdt.plusDays(2);
235+
scheduleSend = zdtPlusTwoDays.toString();
236+
224237
Boolean deliveryNotification = false;
225238
String statusCallbackUrl = "http://www.example.com";
226239
List<String> tagsList = new ArrayList<>();
@@ -271,7 +284,7 @@ public void updateMessageTagsTest() {
271284
try{
272285
ApiClient apiClient = getAuthToken(defaultClient);
273286
MessagesApi messagesApi = new MessagesApi(apiClient);
274-
UUID messageId = UUID.fromString("e31106b0-5c35-11ee-a710-0fd7aacbc74b");
287+
UUID messageId = UUID.fromString("88ed8550-59cd-11ef-be6b-3de6ec7e1aaa");
275288

276289
UpdateMessageTagsRequest updateMessageTagsRequest = new UpdateMessageTagsRequest();
277290
updateMessageTagsRequest.addTagsItem("marketing");

0 commit comments

Comments
 (0)