diff --git a/README.md b/README.md index 96721b6..25bc981 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Send and Receive SMS - - + + Messaging Quick Start Guide + # Table of Contents diff --git a/application.properties b/application.properties new file mode 100644 index 0000000..e78beac --- /dev/null +++ b/application.properties @@ -0,0 +1 @@ +spring.jackson.mapper.ACCEPT_CASE_INSENSITIVE_ENUMS = true diff --git a/icon-messaging.svg b/icon-messaging.svg new file mode 100644 index 0000000..cc8cad7 --- /dev/null +++ b/icon-messaging.svg @@ -0,0 +1 @@ + diff --git a/pom.xml b/pom.xml index 1aa28d6..e9d2f6d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.bandwidth - TextMessaging + Messaging-Send-Receive-SMS 1.0.0 @@ -21,7 +21,7 @@ com.bandwidth.sdk bandwidth-sdk - 6.0.0 + 9.1.2 @@ -31,6 +31,12 @@ 2.8.0 + + javax.activation + javax.activation-api + 1.2.0 + + org.springframework.boot spring-boot-starter-web @@ -47,7 +53,7 @@ org.projectlombok lombok - 1.18.16 + 1.18.30 provided @@ -62,7 +68,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.10.1 ${java.version} @@ -71,4 +77,5 @@ - \ No newline at end of file + + diff --git a/src/main/java/com/bandwidth/Model/CreateMessage.java b/src/main/java/com/bandwidth/Model/CreateMessage.java index 14448f8..b137546 100644 --- a/src/main/java/com/bandwidth/Model/CreateMessage.java +++ b/src/main/java/com/bandwidth/Model/CreateMessage.java @@ -1,4 +1,4 @@ -package com.bandwidth.Model; +package com.bandwidth.model; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/com/bandwidth/Model/MessageCallback.java b/src/main/java/com/bandwidth/Model/MessageCallback.java deleted file mode 100644 index 0dfa6ee..0000000 --- a/src/main/java/com/bandwidth/Model/MessageCallback.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.bandwidth.Model; - -import lombok.Getter; -import lombok.Setter; - -import java.util.List; - -@Getter -@Setter -public class MessageCallback { - - private String type; - private String time; - private String description; - private String to; - private Message message; - - @Getter - @Setter - public class Message { - private String id; - private String time; - private List to; - private String from; - private String text; - private String applicationId; - private List media; - private String owner; - private String direction; - private int segmentCount; - } -} diff --git a/src/main/java/com/bandwidth/Model/MessageReply.java b/src/main/java/com/bandwidth/Model/MessageReply.java index b6b91f0..db0522b 100644 --- a/src/main/java/com/bandwidth/Model/MessageReply.java +++ b/src/main/java/com/bandwidth/Model/MessageReply.java @@ -1,4 +1,4 @@ -package com.bandwidth.Model; +package com.bandwidth.model; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/com/bandwidth/controller/CallbacksController.java b/src/main/java/com/bandwidth/controller/CallbacksController.java index 7b1fcbf..fdb6606 100644 --- a/src/main/java/com/bandwidth/controller/CallbacksController.java +++ b/src/main/java/com/bandwidth/controller/CallbacksController.java @@ -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; @@ -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()) { @@ -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: diff --git a/src/main/java/com/bandwidth/controller/MessagesController.java b/src/main/java/com/bandwidth/controller/MessagesController.java index 0348029..1194620 100644 --- a/src/main/java/com/bandwidth/controller/MessagesController.java +++ b/src/main/java/com/bandwidth/controller/MessagesController.java @@ -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; @@ -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 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);