Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
d433593
feat (Getting-Started/SMS): Add 'Send an SMS Message with the Sinch J…
JPPortier May 21, 2025
2e6d23f
feat (Getting-Started/Conversation): Add 'Send a Conversation Message…
JPPortier May 22, 2025
cd278a4
feat (Getting-Started/Voice): Add 'Make a call with Java SDK'
JPPortier May 22, 2025
cda4efc
feat (Getting-Started/Numbers): Add 'Rent the first available number …
JPPortier May 22, 2025
c486c49
feat (Getting-Started/Numbers): Add 'Search for virtual number using …
JPPortier May 22, 2025
f4a1e2c
feat (Getting-Started/Numbers): Add 'Rent and configure your virtual …
JPPortier May 22, 2025
3d1c309
doc (Getting-Started/Verification): Fix README text
JPPortier May 22, 2025
9868158
chore (Templates/client): Add dependency onto 'sl4j' avoiding end use…
JPPortier May 22, 2025
5b88e1a
doc: (templates): Refine configuration's files comment
JPPortier May 23, 2025
002ab81
doc: (Getting-Started): Refine configuration's files comment
JPPortier May 23, 2025
eb925fc
doc: (Getting-Started/Numbers): Fix URL from 'rent and configure'
JPPortier May 23, 2025
341a288
doc: (Getting-Started/Numbers): Refine log
JPPortier May 23, 2025
2f15522
doc: (Getting-Started/SMS): config comment
JPPortier May 23, 2025
ec41133
doc: (Getting-Started/SMS): Refine log
JPPortier May 23, 2025
cbcfefb
feat (templates): Support Conversation region definition from configu…
JPPortier May 24, 2025
114115c
feat (Getting-Started): Synchronize getting started sources with temp…
JPPortier May 24, 2025
6e7a435
feat (Getting-Started): Webhooks validation deactivated by default
JPPortier May 27, 2025
b1e7ca9
doc (Getting-Started/Number): Improve log info comment for 'rent-firs…
JPPortier May 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions getting-started/compile.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#!/bin/sh

DIRECTORIES="
conversation/send-text-message/client
numbers/rent-and-configure/client
numbers/rent-first-available-number/client
numbers/search-available/client
sms/send-sms-message/client
sms/respond-to-incoming-message/server
verification/user-verification-using-sms-pin/client
voice/respond-to-incoming-call/server
voice/make-a-call/client
"

for DIRECTORY in $DIRECTORIES
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Sinch Getting started

Code is related to [Send a Conversation Message with the Sinch Java SDK](https://developers.sinch.com/docs/conversation/getting-started/java-sdk/send-message).

See [Client template README](https://github.com/sinch/sinch-sdk-java-quickstart/blob/main/templates/client/README.md) for details about configuration and usage.
85 changes: 85 additions & 0 deletions getting-started/conversation/send-text-message/client/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>my.company.com</groupId>
<artifactId>sinch-java-sdk-client-application</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Sinch Java SDK Client Application</name>

<properties>
<sinch.sdk.java.version>[1.5.0,)</sinch.sdk.java.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>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<id>add-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>
Application
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.sinch.sdk</groupId>
<artifactId>sinch-sdk-java</artifactId>
<version>${sinch.sdk.java.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>2.0.9</version>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import com.sinch.sdk.SinchClient;
import conversation.ConversationQuickStart;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.LogManager;
import java.util.logging.Logger;

public abstract class Application {

private static final String LOGGING_PROPERTIES_FILE = "logging.properties";
private static final Logger LOGGER = initializeLogger();

public static void main(String[] args) {
try {

SinchClient client = SinchClientHelper.initSinchClient();
LOGGER.info("Application initiated. SinchClient ready.");

ConversationQuickStart conversation = new ConversationQuickStart(client.conversation().v1());

} catch (Exception e) {
LOGGER.severe(String.format("Application failure: %s", e.getMessage()));
}
}

static Logger initializeLogger() {
try (InputStream logConfigInputStream =
Application.class.getClassLoader().getResourceAsStream(LOGGING_PROPERTIES_FILE)) {

if (logConfigInputStream != null) {
LogManager.getLogManager().readConfiguration(logConfigInputStream);
} else {
throw new RuntimeException(
String.format("The file '%s' couldn't be loaded.", LOGGING_PROPERTIES_FILE));
}

} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
return Logger.getLogger(Application.class.getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import com.sinch.sdk.SinchClient;
import com.sinch.sdk.models.Configuration;
import com.sinch.sdk.models.ConversationRegion;
import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;
import java.util.Properties;
import java.util.logging.Logger;

public class SinchClientHelper {

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

private static final String SINCH_PROJECT_ID = "SINCH_PROJECT_ID";
private static final String SINCH_KEY_ID = "SINCH_KEY_ID";
private static final String SINCH_KEY_SECRET = "SINCH_KEY_SECRET";

private static final String CONVERSATION_REGION = "CONVERSATION_REGION";

private static final String CONFIG_FILE = "config.properties";

public static SinchClient initSinchClient() {

LOGGER.info("Initializing client");

Configuration configuration = getConfiguration();

return new SinchClient(configuration);
}

private static Configuration getConfiguration() {

Properties properties = loadProperties();

Configuration.Builder builder = Configuration.builder();

manageUnifiedCredentials(properties, builder);
manageConversationConfiguration(properties, builder);

return builder.build();
}

private static Properties loadProperties() {

Properties properties = new Properties();

try (InputStream input =
SinchClientHelper.class.getClassLoader().getResourceAsStream(CONFIG_FILE)) {
if (input != null) {
properties.load(input);
} else {
LOGGER.severe(String.format("'%s' file could not be loaded", CONFIG_FILE));
}
} catch (IOException e) {
LOGGER.severe(String.format("Error loading properties from '%s'", CONFIG_FILE));
}

return properties;
}

static void manageUnifiedCredentials(Properties properties, Configuration.Builder builder) {

Optional<String> projectId = getConfigValue(properties, SINCH_PROJECT_ID);
Optional<String> keyId = getConfigValue(properties, SINCH_KEY_ID);
Optional<String> keySecret = getConfigValue(properties, SINCH_KEY_SECRET);

projectId.ifPresent(builder::setProjectId);
keyId.ifPresent(builder::setKeyId);
keySecret.ifPresent(builder::setKeySecret);
}

private static void manageConversationConfiguration(
Properties properties, Configuration.Builder builder) {

Optional<String> region = getConfigValue(properties, CONVERSATION_REGION);

region.ifPresent(value -> builder.setConversationRegion(ConversationRegion.from(value)));
}

private static Optional<String> getConfigValue(Properties properties, String key) {
String value = null != System.getenv(key) ? System.getenv(key) : properties.getProperty(key);

// empty value means setting not set
if (null != value && value.trim().isEmpty()) {
return Optional.empty();
}

return Optional.ofNullable(value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package conversation;

import com.sinch.sdk.domains.conversation.api.v1.ConversationService;

public class ConversationQuickStart {

private final ConversationService conversationService;

public ConversationQuickStart(ConversationService conversationService) {
this.conversationService = conversationService;

// replace by your code and business logic
Snippet.execute(this.conversationService);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package conversation;

import com.sinch.sdk.domains.conversation.api.v1.ConversationService;
import com.sinch.sdk.domains.conversation.api.v1.MessagesService;
import com.sinch.sdk.domains.conversation.models.v1.*;
import com.sinch.sdk.domains.conversation.models.v1.messages.*;
import com.sinch.sdk.domains.conversation.models.v1.messages.request.*;
import com.sinch.sdk.domains.conversation.models.v1.messages.response.SendMessageResponse;
import com.sinch.sdk.domains.conversation.models.v1.messages.types.text.*;
import java.util.*;
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(ConversationService conversationService) {

MessagesService messagesService = conversationService.messages();

String appId = "YOUR_app_id";
String from = "YOUR_sms_sender";
String to = "RECIPIENT_number";

String body = "This is a test Conversation message using the Sinch Java SDK.";
String smsSender = "SMS_SENDER";

ChannelRecipientIdentities recipients =
ChannelRecipientIdentities.of(
ChannelRecipientIdentity.builder()
.setChannel(ConversationChannel.SMS)
.setIdentity(to)
.build());

AppMessage<TextMessage> message =
AppMessage.<TextMessage>builder()
.setBody(TextMessage.builder().setText(body).build())
.build();

SendMessageRequest<TextMessage> request =
SendMessageRequest.<TextMessage>builder()
.setAppId(appId)
.setRecipient(recipients)
.setMessage(message)
.setChannelProperties(Collections.singletonMap(smsSender, from))
.build();

LOGGER.info("Sending SMS Text using Conversation API");

SendMessageResponse value = messagesService.sendMessage(request);

LOGGER.info("Response: " + value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Required credentials for using the Conversation API
SINCH_PROJECT_ID=
SINCH_KEY_ID=
SINCH_KEY_SECRET=

# See https://github.com/sinch/sinch-sdk-java/blob/main/client/src/main/com/sinch/sdk/models/ConversationRegion.java for list of supported values
#CONVERSATION_REGION = us
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

handlers = java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = INFO
com.sinch.level = INFO

java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=[%1$tF %1$tT] [%4$-7s %2$s] %5$s %n

5 changes: 5 additions & 0 deletions getting-started/numbers/rent-and-configure/client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Sinch Getting started

Code is related to [Rent and configure your virtual number using Java](https://developers.sinch.com/docs/numbers/getting-started/java-sdk/rentandconfig).

See [Client template README](https://github.com/sinch/sinch-sdk-java-quickstart/blob/main/templates/client/README.md) for details about configuration and usage.
Loading