Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Global rule:
* @Bandwidth-Samples/dx
* @Bandwidth-Samples/band-swi @Bandwidth-Samples/band-devx
11 changes: 0 additions & 11 deletions .github/actions/maven-test/Dockerfile

This file was deleted.

6 changes: 0 additions & 6 deletions .github/actions/maven-test/action.yml

This file was deleted.

3 changes: 0 additions & 3 deletions .github/actions/maven-test/entrypoint.sh

This file was deleted.

19 changes: 19 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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"
16 changes: 0 additions & 16 deletions .github/workflows/on-pull-request.yaml

This file was deleted.

15 changes: 15 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
61 changes: 45 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,48 @@
# Send and Receive SMS
<a href="http://dev.bandwidth.com/docs/messaging/quickStart">
# Messaging Send and Receive

<a href="https://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

<!-- TOC -->

- [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)

<!-- /TOC -->

# 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

Expand All @@ -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

Expand All @@ -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.
1 change: 0 additions & 1 deletion application.properties

This file was deleted.

4 changes: 3 additions & 1 deletion 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.
49 changes: 17 additions & 32 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,42 @@
<modelVersion>4.0.0</modelVersion>

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

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<spring.version>2.5.12</spring.version>
<java.version>21</java.version>
<spring.version>4.1.1</spring.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>

<!-- https://mvnrepository.com/artifact/com.bandwidth.sdk/bandwidth-sdk -->
<dependency>
<groupId>com.bandwidth.sdk</groupId>
<artifactId>bandwidth-sdk</artifactId>
<version>9.1.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.14.0</version>
</dependency>

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

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -68,7 +53,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<version>3.16.0</version>
<configuration>
<!-- or whatever version you use -->
<source>${java.version}</source>
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/bandwidth/Main.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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...");
}


}
13 changes: 0 additions & 13 deletions src/main/java/com/bandwidth/Model/CreateMessage.java

This file was deleted.

12 changes: 0 additions & 12 deletions src/main/java/com/bandwidth/Model/MessageReply.java

This file was deleted.

Loading
Loading