-
Couldn't load subscription status.
- Fork 1
SMS snippets #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
SMS snippets #18
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8f17b13
feat (SMS/Batches): Batches snippets
JPPortier 31540f4
feat (SMS/DeliveryReports): Delivery report snippets
JPPortier ae00e08
feat (SMS/Inbounds): Inbounds snippets
JPPortier fc9df78
feat (SMS/Groups): Groups snippets
JPPortier c893daa
refactor (SMS): Naming enhancements
JPPortier a03bb18
refactor (SMS): Use same pattern for Update snippets related to group…
JPPortier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # SMS snippets | ||
| Sinch Java SDK Code Snippets Repository for SMS APIs | ||
|
|
||
| See main [README.md](../../../../../README.md) for how to execute snippets | ||
|
|
||
| - Batches | ||
| - [sms/batches/Send](./batches/Send.java) | ||
| - [sms/batches/List](./batches/List.java) | ||
| - [sms/batches/DryRun](./batches/DryRun.java) | ||
| - [sms/batches/Get](./batches/Get.java) | ||
| - [sms/batches/Update](./batches/Update.java) | ||
| - [sms/batches/Replace](./batches/Replace.java) | ||
| - [sms/batches/Cancel](./batches/Cancel.java) | ||
| - [sms/batches/SendDeliveryFeedback](./batches/SendDeliveryFeedback.java) | ||
| - Delivery reports | ||
| - [sms/deliveryReports/Get](./deliveryReports/Get.java) | ||
| - [sms/deliveryReports/GetForNumber](./deliveryReports/GetForNumber.java) | ||
| - [sms/deliveryReports/List](./deliveryReports/List.java) | ||
| - Inbounds | ||
| - [sms/inbounds/List](./inbounds/List.java) | ||
| - [sms/inbounds/Get](./inbounds/Get.java) | ||
| - Groups | ||
| - [sms/groups/List](./groups/List.java) | ||
| - [sms/groups/Create](./groups/Create.java) | ||
| - [sms/groups/Get](./groups/Get.java) | ||
| - [sms/groups/Update](./groups/Update.java) | ||
| - [sms/groups/Replace](./groups/Replace.java) | ||
| - [sms/groups/Delete](./groups/Delete.java) | ||
| - [sms/groups/ListMembers](./groups/ListMembers.java) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /** | ||
| * Sinch Java Snippet | ||
| * | ||
| * <p>This snippet is available at https://github.com/sinch/sinch-sdk-java-snippets | ||
| * | ||
| * <p>See https://github.com/sinch/sinch-sdk-java-snippets/blob/main/README.md for details | ||
| */ | ||
| package sms.batches; | ||
|
|
||
| import com.sinch.sdk.SinchClient; | ||
| import com.sinch.sdk.domains.sms.api.v1.BatchesService; | ||
| import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; | ||
| import com.sinch.sdk.models.Configuration; | ||
| import java.util.logging.Logger; | ||
| import utils.Settings; | ||
|
|
||
| public class Cancel { | ||
|
|
||
| private static final Logger LOGGER = Logger.getLogger(Cancel.class.getName()); | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| String projectId = Settings.getProjectId().orElse("MY_PROJECT_ID"); | ||
| String keyId = Settings.getKeyId().orElse("MY_KEY_ID"); | ||
| String keySecret = Settings.getKeySecret().orElse("MY_KEY_SECRET"); | ||
|
|
||
| String batchId = "A_BATCH_ID"; | ||
|
|
||
| Configuration configuration = | ||
| Configuration.builder() | ||
| .setProjectId(projectId) | ||
| .setKeyId(keyId) | ||
| .setKeySecret(keySecret) | ||
| .build(); | ||
|
|
||
| SinchClient client = new SinchClient(configuration); | ||
|
|
||
| BatchesService batchesService = client.sms().v1().batches(); | ||
|
|
||
| LOGGER.info(String.format("Cancelling batch with ID '%s'", batchId)); | ||
|
|
||
| BatchResponse response = batchesService.cancel(batchId); | ||
|
|
||
| LOGGER.info("Response: " + response); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /** | ||
| * Sinch Java Snippet | ||
| * | ||
| * <p>This snippet is available at https://github.com/sinch/sinch-sdk-java-snippets | ||
| * | ||
| * <p>See https://github.com/sinch/sinch-sdk-java-snippets/blob/main/README.md for details | ||
| */ | ||
| package sms.batches; | ||
|
|
||
| import com.sinch.sdk.SinchClient; | ||
| import com.sinch.sdk.domains.sms.api.v1.BatchesService; | ||
| import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; | ||
| import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; | ||
| import com.sinch.sdk.models.Configuration; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.logging.Logger; | ||
| import utils.Settings; | ||
|
|
||
| public class DryRun { | ||
|
|
||
| private static final Logger LOGGER = Logger.getLogger(DryRun.class.getName()); | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| String projectId = Settings.getProjectId().orElse("MY_PROJECT_ID"); | ||
| String keyId = Settings.getKeyId().orElse("MY_KEY_ID"); | ||
| String keySecret = Settings.getKeySecret().orElse("MY_KEY_SECRET"); | ||
|
|
||
| String phoneNumber = Settings.getPhoneNumber().orElse("MY_SINCH_PHONE_NUMBER"); | ||
|
|
||
| List<String> recipients = Arrays.asList("A_RECIPIENT_PHONE_NUMBER"); | ||
| String body = "A body text here"; | ||
|
|
||
| Configuration configuration = | ||
| Configuration.builder() | ||
| .setProjectId(projectId) | ||
| .setKeyId(keyId) | ||
| .setKeySecret(keySecret) | ||
| .build(); | ||
|
|
||
| SinchClient client = new SinchClient(configuration); | ||
|
|
||
| BatchesService batchesService = client.sms().v1().batches(); | ||
|
|
||
| LOGGER.info("DryRun Request"); | ||
|
|
||
| TextRequest request = | ||
| TextRequest.builder().setFrom(phoneNumber).setTo(recipients).setBody(body).build(); | ||
|
|
||
| DryRunResponse response = batchesService.dryRun(request); | ||
|
|
||
| LOGGER.info("Response: " + response); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /** | ||
| * Sinch Java Snippet | ||
| * | ||
| * <p>This snippet is available at https://github.com/sinch/sinch-sdk-java-snippets | ||
| * | ||
| * <p>See https://github.com/sinch/sinch-sdk-java-snippets/blob/main/README.md for details | ||
| */ | ||
| package sms.batches; | ||
|
|
||
| import com.sinch.sdk.SinchClient; | ||
| import com.sinch.sdk.domains.sms.api.v1.BatchesService; | ||
| import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; | ||
| import com.sinch.sdk.models.Configuration; | ||
| import java.util.logging.Logger; | ||
| import utils.Settings; | ||
|
|
||
| public class Get { | ||
|
|
||
| private static final Logger LOGGER = Logger.getLogger(Get.class.getName()); | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| String projectId = Settings.getProjectId().orElse("MY_PROJECT_ID"); | ||
| String keyId = Settings.getKeyId().orElse("MY_KEY_ID"); | ||
| String keySecret = Settings.getKeySecret().orElse("MY_KEY_SECRET"); | ||
|
|
||
| String batchId = "A_BATCH_ID"; | ||
|
|
||
| Configuration configuration = | ||
| Configuration.builder() | ||
| .setProjectId(projectId) | ||
| .setKeyId(keyId) | ||
| .setKeySecret(keySecret) | ||
| .build(); | ||
|
|
||
| SinchClient client = new SinchClient(configuration); | ||
|
|
||
| BatchesService batchesService = client.sms().v1().batches(); | ||
|
|
||
| LOGGER.info(String.format("Get information for batch with ID '%s'", batchId)); | ||
|
|
||
| BatchResponse response = batchesService.get(batchId); | ||
|
|
||
| LOGGER.info("Response: " + response); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /** | ||
| * Sinch Java Snippet | ||
| * | ||
| * <p>This snippet is available at https://github.com/sinch/sinch-sdk-java-snippets | ||
| * | ||
| * <p>See https://github.com/sinch/sinch-sdk-java-snippets/blob/main/README.md for details | ||
| */ | ||
| package sms.batches; | ||
|
|
||
| import com.sinch.sdk.SinchClient; | ||
| import com.sinch.sdk.domains.sms.api.v1.BatchesService; | ||
| import com.sinch.sdk.models.Configuration; | ||
| import java.util.logging.Logger; | ||
| import utils.Settings; | ||
|
|
||
| public class List { | ||
| private static final Logger LOGGER = Logger.getLogger(List.class.getName()); | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| String projectId = Settings.getProjectId().orElse("MY_PROJECT_ID"); | ||
| String keyId = Settings.getKeyId().orElse("MY_KEY_ID"); | ||
| String keySecret = Settings.getKeySecret().orElse("MY_KEY_SECRET"); | ||
|
|
||
| Configuration configuration = | ||
| Configuration.builder() | ||
| .setProjectId(projectId) | ||
| .setKeyId(keyId) | ||
| .setKeySecret(keySecret) | ||
| .build(); | ||
|
|
||
| SinchClient client = new SinchClient(configuration); | ||
|
|
||
| BatchesService batchesService = client.sms().v1().batches(); | ||
|
|
||
| LOGGER.info("List batches"); | ||
|
|
||
| LOGGER.info("Response:"); | ||
|
|
||
| batchesService.list().iterator().forEachRemaining(f -> LOGGER.info(f.toString())); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /** | ||
| * Sinch Java Snippet | ||
| * | ||
| * <p>This snippet is available at https://github.com/sinch/sinch-sdk-java-snippets | ||
| * | ||
| * <p>See https://github.com/sinch/sinch-sdk-java-snippets/blob/main/README.md for details | ||
| */ | ||
| package sms.batches; | ||
|
|
||
| import com.sinch.sdk.SinchClient; | ||
| import com.sinch.sdk.domains.sms.api.v1.BatchesService; | ||
| import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; | ||
| import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; | ||
| import com.sinch.sdk.models.Configuration; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.logging.Logger; | ||
| import utils.Settings; | ||
|
|
||
| public class Replace { | ||
|
|
||
| private static final Logger LOGGER = Logger.getLogger(Replace.class.getName()); | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| String projectId = Settings.getProjectId().orElse("MY_PROJECT_ID"); | ||
| String keyId = Settings.getKeyId().orElse("MY_KEY_ID"); | ||
| String keySecret = Settings.getKeySecret().orElse("MY_KEY_SECRET"); | ||
|
|
||
| String batchId = "A_BATCH_ID"; | ||
| List<String> recipients = Arrays.asList("A_NEW_RECIPIENT_PHONE_NUMBER"); | ||
| String body = "A message body updated"; | ||
|
|
||
| Configuration configuration = | ||
| Configuration.builder() | ||
| .setProjectId(projectId) | ||
| .setKeyId(keyId) | ||
| .setKeySecret(keySecret) | ||
| .build(); | ||
|
|
||
| SinchClient client = new SinchClient(configuration); | ||
|
|
||
| BatchesService batchesService = client.sms().v1().batches(); | ||
|
|
||
| LOGGER.info(String.format("Replacing batch with ID '%s'", batchId)); | ||
|
|
||
| TextRequest request = TextRequest.builder().setTo(recipients).setBody(body).build(); | ||
|
|
||
| BatchResponse response = batchesService.replace(batchId, request); | ||
|
|
||
| LOGGER.info("Response: " + response); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /** | ||
| * Sinch Java Snippet | ||
| * | ||
| * <p>This snippet is available at https://github.com/sinch/sinch-sdk-java-snippets | ||
| * | ||
| * <p>See https://github.com/sinch/sinch-sdk-java-snippets/blob/main/README.md for details | ||
| */ | ||
| package sms.batches; | ||
|
|
||
| import com.sinch.sdk.SinchClient; | ||
| import com.sinch.sdk.domains.sms.api.v1.BatchesService; | ||
| import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; | ||
| import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; | ||
| import com.sinch.sdk.models.Configuration; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.logging.Logger; | ||
| import utils.Settings; | ||
|
|
||
| public class Send { | ||
|
|
||
| private static final Logger LOGGER = Logger.getLogger(Send.class.getName()); | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| String projectId = Settings.getProjectId().orElse("MY_PROJECT_ID"); | ||
| String keyId = Settings.getKeyId().orElse("MY_KEY_ID"); | ||
| String keySecret = Settings.getKeySecret().orElse("MY_KEY_SECRET"); | ||
|
|
||
| String phoneNumber = Settings.getPhoneNumber().orElse("MY_SINCH_PHONE_NUMBER"); | ||
|
|
||
| List<String> recipients = Arrays.asList("A_RECIPIENT_PHONE_NUMBER"); | ||
| String body = "This is a test SMS message using the Sinch Java SDK."; | ||
|
|
||
| Configuration configuration = | ||
| Configuration.builder() | ||
| .setProjectId(projectId) | ||
| .setKeyId(keyId) | ||
| .setKeySecret(keySecret) | ||
| .build(); | ||
|
|
||
| SinchClient client = new SinchClient(configuration); | ||
|
|
||
| BatchesService batchesService = client.sms().v1().batches(); | ||
|
|
||
| LOGGER.info(String.format("Sending SMS Text to recipients '%s'", recipients)); | ||
|
|
||
| TextRequest request = | ||
| TextRequest.builder().setTo(recipients).setBody(body).setFrom(phoneNumber).build(); | ||
|
|
||
| BatchResponse response = batchesService.send(request); | ||
|
|
||
| LOGGER.info("Response: " + response); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.