Skip to content

Commit

Permalink
Merge pull request #2 from sinch/adding-send-sms-snippet
Browse files Browse the repository at this point in the history
* feature: Send SMS snippet
* refactor: Sync numbers and voice callouts with 'Snippet' templating usage
  • Loading branch information
JPPortier authored Jun 5, 2024
2 parents 2781c4f + 6892e26 commit 5c88980
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 61 deletions.
32 changes: 0 additions & 32 deletions snippets/numbers/available/List.java

This file was deleted.

33 changes: 33 additions & 0 deletions snippets/numbers/available_list/Snippet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package numbers;

import com.sinch.sdk.domains.numbers.*;
import com.sinch.sdk.domains.numbers.models.*;
import com.sinch.sdk.domains.numbers.models.requests.*;
import com.sinch.sdk.domains.numbers.models.responses.AvailableNumberListResponse;
import java.util.logging.Logger;

public class Snippet {

private static final Logger LOGGER = Logger.getLogger(Snippet.class.getName());

static void execute(NumbersService numbersService) {

AvailableNumberService availableNumbersService = numbersService.available();

String regionCode = "US";
NumberType type = NumberType.LOCAL;

AvailableNumberListAllRequestParameters parameters =
AvailableNumberListAllRequestParameters.builder()
.setRegionCode(regionCode)
.setType(type)
.build();

AvailableNumberListResponse response = availableNumbersService.list(parameters);

response.iterator()
.forEachRemaining(
number ->
LOGGER.info(String.format("Available number details: %s", number)));
}
}
6 changes: 3 additions & 3 deletions snippets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

<properties>
<sinch.sdk.java.version>[1.0.0,)</sinch.sdk.java.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.version>3.8.0</maven.compiler.version>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.version>3.13.0</maven.compiler.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
33 changes: 33 additions & 0 deletions snippets/sms/send/Snippet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package sms;

import com.sinch.sdk.domains.sms.*;
import com.sinch.sdk.domains.sms.models.*;
import com.sinch.sdk.domains.sms.models.requests.*;
import java.util.Collection;
import java.util.Collections;
import java.util.logging.Logger;

public class Snippet {

private static final Logger LOGGER = Logger.getLogger(Snippet.class.getName());

static void execute(SMSService smsService) {

BatchesService batchesService = smsService.batches();

String from = "YOUR_sinch_phone_number";
Collection<String> recipients = Collections.singletonList("YOUR_recipient_phone_number");
String body = "This is a test SMS message using the Sinch Java SDK.";

LOGGER.info("Sending SMS Text");
BatchText value =
batchesService.send(
SendSmsBatchTextRequest.builder()
.setTo(recipients)
.setBody(body)
.setFrom(from)
.build());

LOGGER.info("Response: " + value);
}
}
26 changes: 0 additions & 26 deletions snippets/voice/callouts/TextToSpeech.java

This file was deleted.

26 changes: 26 additions & 0 deletions snippets/voice/callouts_text_to_speech/Snippet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package voice;

import com.sinch.sdk.domains.voice.*;
import com.sinch.sdk.domains.voice.models.*;
import com.sinch.sdk.domains.voice.models.requests.*;

public class Snippet {

public static String execute(VoiceService voiceService) {

CalloutsService calloutsService = voiceService.callouts();

String phoneNumber = "YOUR_phone_number";
String message =
"Hello, this is a call from Sinch. Congratulations! You made your first call.";

CalloutRequestParametersTTS parameters =
CalloutRequestParametersTTS.builder()
.setDestination(DestinationNumber.valueOf(phoneNumber))
.setText(message)
.build();

String callId = calloutsService.textToSpeech(parameters);
return callId;
}
}

0 comments on commit 5c88980

Please sign in to comment.