From 975e50b544d05531643f6f0b099f303295267b56 Mon Sep 17 00:00:00 2001 From: ckoegel Date: Wed, 28 Oct 2026 10:56:58 -0400 Subject: [PATCH] DX-3359 Update Sample --- .github/CODEOWNERS | 2 +- .github/actions/maven-test/Dockerfile | 11 -- .github/actions/maven-test/action.yml | 6 - .github/actions/maven-test/entrypoint.sh | 3 - .github/dependabot.yml | 19 +++ .github/workflows/on-pull-request.yaml | 16 --- .github/workflows/test.yml | 15 +++ .gitignore | 3 + LICENSE | 2 +- README.md | 61 ++++++--- application.properties | 1 - icon-messaging.svg | 4 +- pom.xml | 49 +++----- src/main/java/com/bandwidth/Main.java | 16 ++- .../com/bandwidth/Model/CreateMessage.java | 13 -- .../com/bandwidth/Model/MessageReply.java | 12 -- .../controller/CallbacksController.java | 119 ++++++++++++------ .../controller/MessagesController.java | 92 ++++++++------ 18 files changed, 255 insertions(+), 189 deletions(-) delete mode 100644 .github/actions/maven-test/Dockerfile delete mode 100644 .github/actions/maven-test/action.yml delete mode 100644 .github/actions/maven-test/entrypoint.sh create mode 100644 .github/dependabot.yml delete mode 100644 .github/workflows/on-pull-request.yaml create mode 100644 .github/workflows/test.yml delete mode 100644 application.properties delete mode 100644 src/main/java/com/bandwidth/Model/CreateMessage.java delete mode 100644 src/main/java/com/bandwidth/Model/MessageReply.java diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index beb9074..12776e1 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,2 +1,2 @@ # Global rule: -* @Bandwidth-Samples/dx +* @Bandwidth-Samples/band-swi @Bandwidth-Samples/band-devx diff --git a/.github/actions/maven-test/Dockerfile b/.github/actions/maven-test/Dockerfile deleted file mode 100644 index 8f75cd0..0000000 --- a/.github/actions/maven-test/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -# Container image that runs your code -FROM maven:3.6.2-jdk-14 - -# Copies your code file from your action repository to the filesystem path `/` of the container -COPY entrypoint.sh /entrypoint.sh - -#Make entrypoint.sh exacutable -RUN chmod +x /entrypoint.sh - -# Code file to execute when the docker container starts up (`entrypoint.sh`) -ENTRYPOINT ["/entrypoint.sh"] diff --git a/.github/actions/maven-test/action.yml b/.github/actions/maven-test/action.yml deleted file mode 100644 index 598f220..0000000 --- a/.github/actions/maven-test/action.yml +++ /dev/null @@ -1,6 +0,0 @@ -# action.yml -name: 'Test' -description: 'Runs Maven test command' -runs: - using: 'docker' - image: 'Dockerfile' diff --git a/.github/actions/maven-test/entrypoint.sh b/.github/actions/maven-test/entrypoint.sh deleted file mode 100644 index 91f2160..0000000 --- a/.github/actions/maven-test/entrypoint.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -mvn test diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..78cbe5d --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,19 @@ +version: 2 + +updates: + - package-ecosystem: maven + directory: / + schedule: + interval: monthly + open-pull-requests-limit: 5 + ignore: + - dependency-name: "com.bandwidth.sdk:bandwidth-sdk" + update-types: + - version-update:semver-minor + - version-update:semver-patch + groups: + dependencies: + patterns: + - "*" + exclude-patterns: + - "com.bandwidth.sdk:bandwidth-sdk" diff --git a/.github/workflows/on-pull-request.yaml b/.github/workflows/on-pull-request.yaml deleted file mode 100644 index 17573fb..0000000 --- a/.github/workflows/on-pull-request.yaml +++ /dev/null @@ -1,16 +0,0 @@ -name: Test - -on: - pull_request: - branches: - - main - -jobs: - maven-test: - name: Test - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v1 - - name: Test - uses: ./.github/actions/maven-test \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..62ee593 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,15 @@ +name: Test + +on: + pull_request: + branches: + - main + schedule: + - cron: "0 9 * * 1" + +jobs: + contract-test: + name: Contract Test + uses: Bandwidth-Samples/sample-app-tooling/.github/workflows/java.yml@main + with: + sample: messaging-send-receive diff --git a/.gitignore b/.gitignore index f390797..e60d7fe 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,6 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* + +# Downloaded MMS media +media/ diff --git a/LICENSE b/LICENSE index df9461d..ddc77f4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Bandwidth Samples +Copyright (c) 2026 Bandwidth Samples Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 25bc981..6442994 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ -# Send and Receive SMS - +# Messaging Send and Receive + + Messaging Quick Start Guide @@ -7,29 +8,41 @@ -- [Send and Receive SMS](#send-and-receive-sms) - [Description](#description) - [Bandwidth](#bandwidth) - [Environmental Variables](#environmental-variables) +- [Running the Application](#running-the-application) - [Callback URLs](#callback-urls) - [Ngrok](#ngrok) # Description -Using a tool capable of making POST requests (Postman), send a POST request to the app's endpoint `/callbacks/outbound/messaging` with a json body like: + +This sample app sends and receives SMS and MMS messages. + +Using a tool capable of making POST requests such as [Postman](https://www.postman.com/), send a `POST` request to the `/messages` endpoint with a json body containing the `to` and `text` fields. The `to` field should be an E.164 formatted phone number. + ```json { - "to": "+19199994444", - "text":"Hello World!" + "to": "+19195551234", + "text": "Hello World!" } ``` -The application will text the number `+19199994444` the words `Hello World!`. -If you text your Bandwidth number you will see your text printed out to the logs. -The other two endpoints are used for handling inbound and outbound webhooks from Bandwidth. In order to use the correct endpoints, you must check the "Use multiple callback URLs" box on the application page in Dashboard. Then in Dashboard, set the INBOUND CALLBACK to `/callbacks/inbound/messaging` and the STATUS CALLBACK to `/callbacks/outbound/messaging/status`. The same can be accomplished via the Dashboard API by setting InboundCallbackUrl and OutboundCallbackUrl respectively. +The example above will text the number `+19195551234` the words `Hello World!`. To send an MMS, add a `media` field with a list of media URLs: -Inbound callbacks are sent notifying you of a received message on a Bandwidth number, this app prints the phone numbers involved, as well as the text received. Outbound callbacks are status updates for messages sent from a Bandwidth number, this app has a dedicated response for each type of status update. +```json +{ + "to": "+19195551234", + "text": "Hello World!", + "media": ["https://cdn2.thecatapi.com/images/MTY3ODIyMQ.jpg"] +} +``` + +The other two endpoints are used for handling inbound and outbound webhooks from Bandwidth. In order to use the correct endpoints, you must check the "Use multiple callback URLs" box on the application page in Dashboard. Then in Dashboard, set the INBOUND CALLBACK to `/callbacks/inbound/messaging` and the STATUS CALLBACK to `/callbacks/outbound/messaging/status`. The same can be accomplished via the Dashboard API by setting `InboundCallbackUrl` and `OutboundCallbackUrl` respectively. + +Inbound callbacks are sent notifying you of a received message on a Bandwidth number. This app prints the phone numbers involved and the text received, and saves any media attached to the message to a `media` folder in the project. Outbound callbacks are status updates for messages sent from a Bandwidth number, this app has a dedicated response for each type of status update. # Bandwidth @@ -43,18 +56,34 @@ For more information about API credentials see [here](https://dev.bandwidth.com/ The sample app uses the below environmental variables. ```sh BW_ACCOUNT_ID # Your Bandwidth Account Id -BW_USERNAME # Your Bandwidth API Username -BW_PASSWORD # Your Bandwidth API Password -BW_MESSAGING_APPLICATION_ID # Your Messaging Application Id created in the dashboard +BW_CLIENT_ID # Your Bandwidth API OAuth Client Id +BW_CLIENT_SECRET # Your Bandwidth API OAuth Client Secret BW_NUMBER # The Bandwidth phone number involved with this application +BW_MESSAGING_APPLICATION_ID # Your Messaging Application Id created in the dashboard +LOCAL_PORT # The port number you wish to run the sample on +``` + +# Running the Application + +To install the required packages and build the app, run the command: + +```sh +mvn package +``` + +Use the following command to run the application: + +```sh +mvn spring-boot:run ``` # Callback URLs -For a detailed introduction to Bandwidth Callbacks see https://dev.bandwidth.com/guides/callbacks/callbacks.html +For a detailed introduction, check out our [Bandwidth Messaging Callbacks](https://dev.bandwidth.com/docs/messaging/webhooks) page. Below are the callback paths: -* `/callbacks/messageCallback` +* `/callbacks/outbound/messaging/status` For Outbound Status Callbacks +* `/callbacks/inbound/messaging` For Inbound Message Callbacks ## Ngrok @@ -63,4 +92,4 @@ After you have downloaded and installed `ngrok` run the following command to ope ```cmd ngrok http $LOCAL_PORT ``` -You can view your public URL at `http://127.0.0.1:{LOCAL_PORT}` after ngrok is running. You can also view the status of the tunnel and requests/responses here. +You can view your public URL at `http://127.0.0.1:4040` after ngrok is running. You can also view the status of the tunnel and requests/responses here. Once your public ngrok url has been created, use it as the base of the callback URLs in the messaging application created in the [Bandwidth](#bandwidth) section. diff --git a/application.properties b/application.properties deleted file mode 100644 index e78beac..0000000 --- a/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.jackson.mapper.ACCEPT_CASE_INSENSITIVE_ENUMS = true diff --git a/icon-messaging.svg b/icon-messaging.svg index cc8cad7..fa130bd 100644 --- a/icon-messaging.svg +++ b/icon-messaging.svg @@ -1 +1,3 @@ - + + + diff --git a/pom.xml b/pom.xml index 52b9df0..2f189da 100644 --- a/pom.xml +++ b/pom.xml @@ -5,36 +5,35 @@ 4.0.0 com.bandwidth - Messaging-Send-Receive-SMS + Messaging-Send-Receive 1.0.0 UTF-8 UTF-8 - 11 - 2.5.12 + 21 + 4.1.1 + + + + org.springframework.boot + spring-boot-dependencies + ${spring.version} + pom + import + + + + com.bandwidth.sdk bandwidth-sdk - 9.1.2 - - - - - commons-io - commons-io - 2.14.0 - - - - javax.activation - javax.activation-api - 1.2.0 + 18.3.1 @@ -42,20 +41,6 @@ spring-boot-starter-web ${spring.version} - - - org.springframework.boot - spring-boot-starter-test - ${spring.version} - test - - - - org.projectlombok - lombok - 1.18.30 - provided - @@ -68,7 +53,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.10.1 + 3.16.0 ${java.version} diff --git a/src/main/java/com/bandwidth/Main.java b/src/main/java/com/bandwidth/Main.java index c24bdae..23e0100 100644 --- a/src/main/java/com/bandwidth/Main.java +++ b/src/main/java/com/bandwidth/Main.java @@ -1,10 +1,11 @@ package com.bandwidth; - +import java.util.Collections; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; + import org.springframework.web.bind.annotation.RestController; @SpringBootApplication @@ -14,9 +15,18 @@ public class Main { static Logger logger = LoggerFactory.getLogger(Main.class); public static void main(String[] args) { - SpringApplication.run(Main.class, args); + String port = System.getenv("LOCAL_PORT"); + if (System.getenv("BW_ACCOUNT_ID") == null || System.getenv("BW_CLIENT_ID") == null + || System.getenv("BW_CLIENT_SECRET") == null || System.getenv("BW_MESSAGING_APPLICATION_ID") == null + || System.getenv("BW_NUMBER") == null || port == null || !port.matches("\\d+")) { + System.err.println("Please set the environmental variables defined in the README"); + System.exit(1); + } + + SpringApplication application = new SpringApplication(Main.class); + application.setDefaultProperties(Collections.singletonMap("server.port", port)); + application.run(args); logger.info("Server has started..."); } - } diff --git a/src/main/java/com/bandwidth/Model/CreateMessage.java b/src/main/java/com/bandwidth/Model/CreateMessage.java deleted file mode 100644 index b137546..0000000 --- a/src/main/java/com/bandwidth/Model/CreateMessage.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.bandwidth.model; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class CreateMessage { - - private String to; - private String from; - private String text; -} diff --git a/src/main/java/com/bandwidth/Model/MessageReply.java b/src/main/java/com/bandwidth/Model/MessageReply.java deleted file mode 100644 index db0522b..0000000 --- a/src/main/java/com/bandwidth/Model/MessageReply.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.bandwidth.model; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class MessageReply { - - private boolean success; - private String error; -} diff --git a/src/main/java/com/bandwidth/controller/CallbacksController.java b/src/main/java/com/bandwidth/controller/CallbacksController.java index fdb6606..d6fc7cb 100644 --- a/src/main/java/com/bandwidth/controller/CallbacksController.java +++ b/src/main/java/com/bandwidth/controller/CallbacksController.java @@ -1,9 +1,27 @@ package com.bandwidth.controller; -import com.bandwidth.Main; -import com.bandwidth.sdk.model.*; +import com.bandwidth.sdk.ApiClient; +import com.bandwidth.sdk.JSON; +import com.bandwidth.sdk.api.MediaApi; +import com.bandwidth.sdk.model.InboundCallback; +import com.bandwidth.sdk.model.InboundCallbackMessage; +import com.bandwidth.sdk.model.InboundCallbackTypeEnum; +import com.bandwidth.sdk.model.StatusCallback; +import com.bandwidth.sdk.model.StatusCallbackTypeEnum; + +import java.io.File; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.Arrays; +import java.util.Map; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -14,44 +32,73 @@ public class CallbacksController { Logger logger = LoggerFactory.getLogger(CallbacksController.class); - @RequestMapping("/outbound/messaging/status") - public void statusCallback(@RequestBody InboundMessageCallback[] callbacks) { - - for (InboundMessageCallback callback : callbacks) { - logger.info(callback.getType()); - logger.info(callback.getDescription()); - switch (callback.getType()) { - case "message-sending": - logger.info("message-sending type is only for MMS"); - break; - case "message-delivered": - logger.info("your message has been handed off to the Bandwidth's MMSC network, but has not been confirmed at the downstream carrier"); - break; - case "message-failed": - logger.info("For MMS and Group Messages, you will only receive this callback if you have enabled delivery receipts on MMS. "); - break; - default: - logger.info("Message type does not match endpoint. This endpoint is used for message status callbacks only."); - break; - } + private final String accountId = System.getenv("BW_ACCOUNT_ID"); + private final String clientId = System.getenv("BW_CLIENT_ID"); + private final String clientSecret = System.getenv("BW_CLIENT_SECRET"); + + private final MediaApi mediaApi = new MediaApi(new ApiClient(clientId, clientSecret, null)); + + private static final Map STATUS_MESSAGES = Map.of( + StatusCallbackTypeEnum.MESSAGE_SENDING, "message-sending type is only for MMS.", + StatusCallbackTypeEnum.MESSAGE_DELIVERED, "Your message has been handed off to the Bandwidth's MMSC network, but has not been confirmed at the downstream carrier.", + StatusCallbackTypeEnum.MESSAGE_FAILED, "For MMS and Group Messages, you will only receive this callback if you have enabled delivery receipts on MMS." + ); + + // The SDK models are Gson-based, so callbacks are parsed with the SDK's Gson instead of Spring's Jackson + private static T[] parseCallbacks(String body, Class type) { + try { + return JSON.getGson().fromJson(body, type); + } catch (RuntimeException e) { + return null; + } + } + + private void saveMedia(URI mediaUrl) { + String url = mediaUrl.toString(); + String mediaId = url.substring(url.indexOf("media/") + "media/".length()); + String mediaName = Paths.get(mediaId).getFileName().toString(); + if (mediaName.endsWith(".xml")) { + return; + } + + try { + File media = mediaApi.getMedia(accountId, mediaId); + Path mediaDir = Files.createDirectories(Paths.get("media")); + Files.move(media.toPath(), mediaDir.resolve(mediaName), StandardCopyOption.REPLACE_EXISTING); + logger.info("Saved media to media/" + mediaName); + } catch (Exception e) { + logger.error("Failed to download " + url + ": " + e.getMessage()); } } - @RequestMapping("/inbound/messaging") - public void inboundCallback(@RequestBody InboundMessageCallback[] 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()); - logger.info(callback.getMessage().getText()); - break; - default: - logger.info(("Message type does not match endpoint. This endpoint is used for inbound messages only.\nOutbound message callbacks should be sent to /callbacks/outbound/messaging.")); - break; + @PostMapping("/outbound/messaging/status") + public ResponseEntity statusCallback(@RequestBody String body) { + StatusCallback[] callbacks = parseCallbacks(body, StatusCallback[].class); + if (callbacks == null || !Arrays.stream(callbacks).allMatch(callback -> STATUS_MESSAGES.containsKey(callback.getType()))) { + return ResponseEntity.badRequest().build(); + } + + for (StatusCallback callback : callbacks) { + logger.info(STATUS_MESSAGES.get(callback.getType())); + } + return ResponseEntity.noContent().build(); + } + + @PostMapping("/inbound/messaging") + public ResponseEntity inboundCallback(@RequestBody String body) { + InboundCallback[] callbacks = parseCallbacks(body, InboundCallback[].class); + if (callbacks == null || !Arrays.stream(callbacks).allMatch(callback -> callback.getType() == InboundCallbackTypeEnum.MESSAGE_RECEIVED)) { + return ResponseEntity.badRequest().build(); + } + + for (InboundCallback callback : callbacks) { + InboundCallbackMessage message = callback.getMessage(); + logger.info(callback.getDescription() + "\nTo: " + message.getTo().iterator().next() + + "\nFrom: " + message.getFrom() + "\nText: " + message.getText()); + if (message.getMedia() != null) { + message.getMedia().forEach(this::saveMedia); } } + return ResponseEntity.noContent().build(); } } diff --git a/src/main/java/com/bandwidth/controller/MessagesController.java b/src/main/java/com/bandwidth/controller/MessagesController.java index 1194620..aaf426e 100644 --- a/src/main/java/com/bandwidth/controller/MessagesController.java +++ b/src/main/java/com/bandwidth/controller/MessagesController.java @@ -1,64 +1,82 @@ package com.bandwidth.controller; 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 com.bandwidth.sdk.model.Message; +import com.bandwidth.sdk.model.MessageRequest; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.io.IOException; -import java.util.Arrays; - @RestController -@RequestMapping("callbacks/outbound/messaging") +@RequestMapping("messages") public class MessagesController { Logger logger = LoggerFactory.getLogger(MessagesController.class); - private String username = System.getenv("BW_USERNAME"); - private String password = System.getenv("BW_PASSWORD"); - private String accountId = System.getenv("BW_ACCOUNT_ID"); - private String bwNumber = System.getenv("BW_NUMBER"); - private String applicationId = System.getenv("BW_MESSAGING_APPLICATION_ID"); + private final String accountId = System.getenv("BW_ACCOUNT_ID"); + private final String clientId = System.getenv("BW_CLIENT_ID"); + private final String clientSecret = System.getenv("BW_CLIENT_SECRET"); + private final String applicationId = System.getenv("BW_MESSAGING_APPLICATION_ID"); + private final String number = System.getenv("BW_NUMBER"); + + private final MessagesApi messagesApi = new MessagesApi(new ApiClient(clientId, clientSecret, null)); - ApiClient defaultClient = Configuration.getDefaultApiClient(); - HttpBasicAuth Basic = (HttpBasicAuth) defaultClient.getAuthentication("Basic"); - private final MessagesApi api = new MessagesApi(defaultClient); - public MessageRequest messageRequest = new MessageRequest(); + private static boolean isString(JsonElement element) { + return element != null && element.isJsonPrimitive() && element.getAsJsonPrimitive().isString(); + } @PostMapping() - public MessageReply createMessage(@RequestBody CreateMessage createMessage) throws IOException { + public ResponseEntity sendMessage(@RequestBody String body) { + JsonObject request; + try { + request = JsonParser.parseString(body).getAsJsonObject(); + } catch (RuntimeException e) { + return ResponseEntity.badRequest().build(); + } + JsonElement media = request.has("media") ? request.get("media") : new JsonArray(); + if (!isString(request.get("to")) || !isString(request.get("text")) || !media.isJsonArray()) { + return ResponseEntity.badRequest().build(); + } + + List mediaUrls = new ArrayList<>(); + for (JsonElement url : media.getAsJsonArray()) { + if (!isString(url)) { + return ResponseEntity.badRequest().build(); + } + mediaUrls.add(URI.create(url.getAsString())); + } - // Build the body of the message request to the Bandwidth API - 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); + MessageRequest messageRequest = new MessageRequest() + .applicationId(applicationId) + .addToItem(request.get("to").getAsString()) + .from(number) + .text(request.get("text").getAsString()) + .media(mediaUrls.isEmpty() ? null : mediaUrls); - MessageReply messageReply = new MessageReply(); try { - Message response = api.createMessage(accountId, messageRequest); - messageReply.setSuccess(true); - } catch (ApiException e) { // Bandwidth API response status not 2XX - messageReply.setSuccess(false); - messageReply.setError(e.getMessage()); + Message message = messagesApi.createMessage(accountId, messageRequest); + logger.info("Sent message " + message.getId()); + } catch (Exception e) { + logger.error("Failed to send message: " + e.getMessage()); + return ResponseEntity.internalServerError().build(); } - return messageReply; + return ResponseEntity.noContent().build(); } }