Skip to content

Commit

Permalink
adding better logging and setting region
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-sberna authored and JPPortier committed Aug 1, 2024
1 parent 041efcf commit 58c44ce
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.sinch.sdk.SinchClient;
import com.sinch.sdk.core.utils.StringUtil;
import com.sinch.sdk.models.Configuration;
import com.sinch.sdk.models.SMSRegion;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

Expand All @@ -18,6 +19,9 @@ public class Config {
@Value("${credentials.key-secret}")
String keySecret;

@Value("${sms.region}")
String region;

@Bean
public SinchClient sinchClient() {

Expand All @@ -26,13 +30,15 @@ public SinchClient sinchClient() {
if (!StringUtil.isEmpty(projectId)) {
builder.setProjectId(projectId);
}

if (!StringUtil.isEmpty(keyId)) {
builder.setKeyId(keyId);
}
if (!StringUtil.isEmpty(keySecret)) {
builder.setKeySecret(keySecret);
}
if (!StringUtil.isEmpty(region)) {
builder.setSmsRegion(SMSRegion.from(region));
}

return new SinchClient(builder.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.sinch.sdk.domains.sms.BatchesService;
import com.sinch.sdk.domains.sms.models.InboundText;
import com.sinch.sdk.domains.sms.models.requests.SendSmsBatchTextRequest;
import com.sinch.sdk.domains.sms.models.webhooks.WebhooksEvent;
import java.util.Collections;
import java.util.logging.Logger;
import org.springframework.stereotype.Component;
Expand All @@ -21,17 +20,18 @@ public ServerBusinessLogic(SinchClient sinchClient) {
private static final Logger LOGGER = Logger.getLogger(ServerBusinessLogic.class.getName());

public void processInboundEvent(InboundText event) {
trace(event);

batches.send(
LOGGER.info("Handle event: " + event);

SendSmsBatchTextRequest smsRequest =
SendSmsBatchTextRequest.builder()
.setTo(Collections.singletonList(event.getFrom()))
.setBody("You sent: " + event.getBody())
.setFrom(event.getTo())
.build());
}
.build();

private void trace(WebhooksEvent event) {
LOGGER.info("Handle event: " + event);
LOGGER.info("Replying with: " + smsRequest);

batches.send(smsRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ credentials:
project-id:
key-id:
key-secret:

sms:
# Sets the region for SMS
# valid values are US and EU
region: US

0 comments on commit 58c44ce

Please sign in to comment.