> T get(String batchId) throws ApiException;
/**
- * Send a message or a batch of messages Depending on the length of the body, one message might be
- * split into multiple parts and charged accordingly.
- *
- * Any groups targeted in a scheduled batch will be evaluated at the time of sending. If a
- * group is deleted between batch creation and scheduled date, it will be considered empty.
+ * Send a message or a batch of messages
+ * Depending on the length of the body, one message might be split into multiple parts and charged
+ * accordingly.
+ * Any groups targeted in a scheduled batch will be evaluated at the time of sending. If a group
+ * is deleted between batch creation and scheduled date, it will be considered empty.
+ * Be sure to use the correct region in the server URL.
*
* @param batch The batch to be created
* @param A type of Batch
* @return Batch information
+ * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Batches/#tag/Batches/operation/SendSMS
* @since 1.0
*/
> T send(BaseBatch> batch) throws ApiException;
/**
+ * Dry run
* This operation will perform a dry run of a batch which calculates the bodies and number of
* parts for all messages in the batch without actually sending any messages.
*
@@ -50,39 +57,70 @@ public interface BatchesService {
* response
* @param batch The batch to be send
* @return Details about dryRun execution
+ * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Batches/#tag/Batches/operation/Dry_Run
* @since 1.0
*/
DryRun dryRun(boolean perRecipient, int numberOfRecipient, BaseBatch> batch)
throws ApiException;
/**
+ * List Batches
* With the list operation you can list batch messages created in the last 14 days that you have
* created. This operation supports pagination.
*
* @param parameters Query parameters filtering returned batches
+ * @return Paginated list of Batches
* @since 1.0
+ * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Batches/#tag/Batches/operation/ListBatches
*/
BatchesListResponse list(BatchesListRequestParameters parameters) throws ApiException;
/**
+ * Update a Batch message
* This operation updates all specified parameters of a batch that matches the provided batch ID.
*
* @param batchId The batch ID you received from sending a message
+ * @param batch Batch parameters to be updated
* @param A type of Batch
* @return Batch information
+ * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Batches/#tag/Batches/operation/UpdateBatchMessage
* @since 1.0
*/
> T update(String batchId, UpdateBaseBatchRequest> batch)
throws ApiException;
/**
+ * Replace a batch
* This operation will replace all the parameters of a batch with the provided values. It is the
* same as cancelling a batch and sending a new one instead.
*
* @param batchId The batch ID you received from sending a message
+ * @param batch Batch parameters to be used
* @param A type of Batch
* @return Batch information
+ * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Batches/#tag/Batches/operation/ReplaceBatch
* @since 1.0
*/
> T replace(String batchId, BaseBatch> batch) throws ApiException;
+
+ /**
+ * Cancel a batch message
+ * A batch can be canceled at any point. If a batch is canceled while it's currently being
+ * delivered some messages currently being processed might still be delivered. The delivery report
+ * will indicate which messages were canceled and which weren't.
+ * Canceling a batch scheduled in the future will result in an empty delivery report while
+ * canceling an already sent batch would result in no change to the completed delivery report.
+ *
+ * @param batchId The batch ID you received from sending a message
+ * @param A type of Batch
+ * @return Batch information
+ * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Batches/#tag/Batches/operation/CancelBatchMessage
+ * @since 1.0
+ */
+ > T cancel(String batchId) throws ApiException;
}
diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/BatchesService.java
index 51dcc475..977d07d2 100644
--- a/client/src/main/com/sinch/sdk/domains/sms/adapters/BatchesService.java
+++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/BatchesService.java
@@ -91,4 +91,9 @@ public > T replace(String batchId, BaseBatch> batch) throws
getApi()
.replaceBatch(configuration.getProjectId(), batchId, BatchDtoConverter.convert(batch)));
}
+
+ public > T cancel(String batchId) throws ApiException {
+ return BatchDtoConverter.convert(
+ getApi().cancelBatchMessage(configuration.getProjectId(), batchId));
+ }
}
diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchMediaRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchMediaRequest.java
index 15dfadf8..08bc1986 100644
--- a/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchMediaRequest.java
+++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchMediaRequest.java
@@ -12,8 +12,10 @@ public class UpdateSmsBatchMediaRequest extends UpdateBaseBatchRequest {
* @param toAdd List of phone numbers and group IDs to add to the batch.
* @param toRemove List of phone numbers and group IDs to remove from the batch.
* @param body The message content
+ * @param from Sender number. Must be valid phone number, short code or alphanumeric. Required if
+ * Automatic Default Originator not configured. * @param body The message content
* @param deliveryReport Request delivery report callback. Note that delivery reports can be
* fetched from the API regardless of this setting
* @param sendAt If set in the future, the message will be delayed until send_at occurs. Must be
diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java
index 1fdf9f1c..470f96f5 100644
--- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java
+++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java
@@ -512,4 +512,15 @@ void replaceText() throws ApiException {
Assertions.assertThat(response).usingRecursiveComparison().isEqualTo(batchText);
}
+
+ @Test
+ void cancelBatch() throws ApiException {
+
+ when(api.cancelBatchMessage(eq(configuration.getProjectId()), eq("foo text batch id")))
+ .thenReturn(textResponseDto);
+
+ Batch> response = service.cancel("foo text batch id");
+
+ Assertions.assertThat(response).usingRecursiveComparison().isEqualTo(batchText);
+ }
}
diff --git a/sample-app/README.md b/sample-app/README.md
index 84a549ee..97cf8104 100644
--- a/sample-app/README.md
+++ b/sample-app/README.md
@@ -65,6 +65,7 @@ See https://developers.sinch.com for details about these parameters
| SMS | Batches | - Get | [com.sinch.sample.sms.batches.Get](src/main/java/com/sinch/sample/sms/batches/Get.java) | Require `BATCH_ID` parameter |
| | | - List | [com.sinch.sample.sms.batches.List](src/main/java/com/sinch/sample/sms/batches/List.java) | |
| | | - Send | [com.sinch.sample.sms.batches.Send](src/main/java/com/sinch/sample/sms/batches/Send.java) | |
-| | | - Replace | [com.sinch.sample.sms.batches.Replace](src/main/java/com/sinch/sample/sms/batches/Replace.java) | Require `BATCH_ID` parameter |
-| | | - Update | [com.sinch.sample.sms.batches.Update](src/main/java/com/sinch/sample/sms/batches/Update.java) | Require `BATCH_ID` parameter |
+| | | - Replace | [com.sinch.sample.sms.batches.Replace](src/main/java/com/sinch/sample/sms/batches/Replace.java) | Require `BATCH_ID` parameter |
+| | | - Update | [com.sinch.sample.sms.batches.Update](src/main/java/com/sinch/sample/sms/batches/Update.java) | Require `BATCH_ID` parameter |
| | | - DryRun | [com.sinch.sample.sms.batches.DryRun](src/main/java/com/sinch/sample/sms/batches/dryRun.java) | |
+| | | - Cancel | [com.sinch.sample.sms.batches.Cancel](src/main/java/com/sinch/sample/sms/batches/Cancel.java) | Require `BATCH_ID` parameter |
diff --git a/sample-app/src/main/java/com/sinch/sample/sms/batches/Cancel.java b/sample-app/src/main/java/com/sinch/sample/sms/batches/Cancel.java
new file mode 100644
index 00000000..52c11d72
--- /dev/null
+++ b/sample-app/src/main/java/com/sinch/sample/sms/batches/Cancel.java
@@ -0,0 +1,29 @@
+package com.sinch.sample.sms.batches;
+
+import com.sinch.sample.BaseApplication;
+import com.sinch.sdk.domains.sms.models.BatchText;
+import java.io.IOException;
+import java.util.logging.Logger;
+
+public class Cancel extends BaseApplication {
+ private static final Logger LOGGER = Logger.getLogger(Cancel.class.getName());
+
+ public Cancel() throws IOException {}
+
+ public static void main(String[] args) {
+ try {
+ new Cancel().run();
+ } catch (Exception e) {
+ LOGGER.severe(e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ public void run() {
+
+ LOGGER.info("Cancelling batch: " + batchId);
+ BatchText value = client.sms().batches().cancel(batchId);
+
+ LOGGER.info("Response: " + value);
+ }
+}