-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from sinch/adding-send-sms-snippet
* feature: Send SMS snippet * refactor: Sync numbers and voice callouts with 'Snippet' templating usage
- Loading branch information
Showing
6 changed files
with
95 additions
and
61 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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,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))); | ||
} | ||
} |
This file contains 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
This file contains 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,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); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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,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; | ||
} | ||
} |