Skip to content

Commit

Permalink
Merge pull request #5 from Bandwidth-Samples/SWI-3491
Browse files Browse the repository at this point in the history
SWI-3491
  • Loading branch information
brianluisgomez authored Feb 20, 2024
2 parents 0ac2217 + a47a542 commit e69ba66
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 69 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Send and Receive SMS
<a href="http://dev.bandwidth.com"><img src="https://s3.amazonaws.com/bwdemos/BW-VMP.png"/></a>
</div>
<a href="http://dev.bandwidth.com/docs/messaging/quickStart">
<img src="./icon-messaging.svg" title="Messaging Quick Start Guide" alt="Messaging Quick Start Guide"/>
</a>

# Table of Contents

Expand Down
1 change: 1 addition & 0 deletions application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spring.jackson.mapper.ACCEPT_CASE_INSENSITIVE_ENUMS = true
1 change: 1 addition & 0 deletions icon-messaging.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 12 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.bandwidth</groupId>
<artifactId>TextMessaging</artifactId>
<artifactId>Messaging-Send-Receive-SMS</artifactId>
<version>1.0.0</version>

<properties>
Expand All @@ -21,7 +21,7 @@
<dependency>
<groupId>com.bandwidth.sdk</groupId>
<artifactId>bandwidth-sdk</artifactId>
<version>6.0.0</version>
<version>9.1.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
Expand All @@ -31,6 +31,12 @@
<version>2.8.0</version>
</dependency>

<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation-api</artifactId>
<version>1.2.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand All @@ -47,7 +53,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand All @@ -62,7 +68,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.10.1</version>
<configuration>
<!-- or whatever version you use -->
<source>${java.version}</source>
Expand All @@ -71,4 +77,5 @@
</plugin>
</plugins>
</build>
</project>

</project>
2 changes: 1 addition & 1 deletion src/main/java/com/bandwidth/Model/CreateMessage.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bandwidth.Model;
package com.bandwidth.model;

import lombok.Getter;
import lombok.Setter;
Expand Down
32 changes: 0 additions & 32 deletions src/main/java/com/bandwidth/Model/MessageCallback.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/com/bandwidth/Model/MessageReply.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bandwidth.Model;
package com.bandwidth.model;

import lombok.Getter;
import lombok.Setter;
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/bandwidth/controller/CallbacksController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bandwidth.controller;

import com.bandwidth.Model.MessageCallback;
import com.bandwidth.Main;
import com.bandwidth.sdk.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -14,9 +15,9 @@ public class CallbacksController {
Logger logger = LoggerFactory.getLogger(CallbacksController.class);

@RequestMapping("/outbound/messaging/status")
public void statusCallback(@RequestBody MessageCallback[] callbacks) {
public void statusCallback(@RequestBody InboundMessageCallback[] callbacks) {

for (MessageCallback callback : callbacks) {
for (InboundMessageCallback callback : callbacks) {
logger.info(callback.getType());
logger.info(callback.getDescription());
switch (callback.getType()) {
Expand All @@ -37,14 +38,14 @@ public void statusCallback(@RequestBody MessageCallback[] callbacks) {
}

@RequestMapping("/inbound/messaging")
public void inboundCallback(@RequestBody MessageCallback[] callbacks) {
public void inboundCallback(@RequestBody InboundMessageCallback[] callbacks) {

for (MessageCallback callback : callbacks) {
for (InboundMessageCallback callback : callbacks) {
logger.info(callback.getType());
logger.info(callback.getDescription());
switch (callback.getType()) {
case "message-received":
logger.info("from: " + callback.getMessage().getFrom() + "-->" + callback.getMessage().getTo().get(0));
logger.info("from: " + callback.getMessage().getFrom() + "-->" + callback.getMessage().getTo());
logger.info(callback.getMessage().getText());
break;
default:
Expand Down
45 changes: 23 additions & 22 deletions src/main/java/com/bandwidth/controller/MessagesController.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.bandwidth.controller;

import com.bandwidth.BandwidthClient;
import com.bandwidth.Environment;
import com.bandwidth.Model.CreateMessage;
import com.bandwidth.Model.MessageReply;
import com.bandwidth.exceptions.ApiException;
import com.bandwidth.http.response.ApiResponse;
import com.bandwidth.messaging.controllers.APIController;
import com.bandwidth.messaging.models.BandwidthMessage;
import com.bandwidth.messaging.models.MessageRequest;
import com.bandwidth.sdk.ApiClient;
import com.bandwidth.sdk.ApiResponse;
import com.bandwidth.sdk.ApiException;
import com.bandwidth.sdk.ApiClient;
import com.bandwidth.sdk.auth.HttpBasicAuth;
import com.bandwidth.sdk.Configuration;
import com.bandwidth.sdk.model.*;
import com.bandwidth.sdk.api.MessagesApi;
import com.bandwidth.model.CreateMessage;
import com.bandwidth.model.MessageReply;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -31,27 +32,27 @@ public class MessagesController {
private String bwNumber = System.getenv("BW_NUMBER");
private String applicationId = System.getenv("BW_MESSAGING_APPLICATION_ID");

private BandwidthClient client = new BandwidthClient.Builder()
.messagingBasicAuthCredentials(username, password)
.environment(Environment.PRODUCTION)
.build();

private APIController controller = client.getMessagingClient().getAPIController();
ApiClient defaultClient = Configuration.getDefaultApiClient();
HttpBasicAuth Basic = (HttpBasicAuth) defaultClient.getAuthentication("Basic");
private final MessagesApi api = new MessagesApi(defaultClient);
public MessageRequest messageRequest = new MessageRequest();

@PostMapping()
public MessageReply createMessage(@RequestBody CreateMessage createMessage) throws IOException {


// Build the body of the message request to the Bandwidth API
MessageRequest messageRequest = new MessageRequest.Builder()
.text(createMessage.getText())
.from(bwNumber)
.to(Arrays.asList( new String[]{createMessage.getTo()}) )
.applicationId(applicationId)
.build();
Basic.setUsername(username);
Basic.setPassword(password);
messageRequest.applicationId(applicationId);
messageRequest.addToItem(createMessage.getTo());
messageRequest.from(createMessage.getFrom());
messageRequest.text(createMessage.getText());
messageRequest.priority(PriorityEnum.DEFAULT);

MessageReply messageReply = new MessageReply();
try {
ApiResponse<BandwidthMessage> response = controller.createMessage(accountId, messageRequest);
Message response = api.createMessage(accountId, messageRequest);
messageReply.setSuccess(true);
} catch (ApiException e) { // Bandwidth API response status not 2XX
messageReply.setSuccess(false);
Expand Down

0 comments on commit e69ba66

Please sign in to comment.