This application demonstrates:
- Receiving webhooks from Telnyx
- Parsing contents from inbound message
- Building an outbound message request
- Sending outbound message based on particular keyword
You will need to set up:
- Telnyx Account
- Completed the messaging Learn & Build to get your:
- Ability to receive webhooks (with something like ngrok)
- Java installed
The following environmental variables need to be set
Variable | Description |
---|---|
TELNYX_API_KEY |
Your Telnyx API Key |
This app uses the excellent dotenv-java package to manage environment variables.
Make a copy of .env.sample
and save as .env
and update the variables to match your creds.
TELNYX_API_KEY="KEYLoremIpsum"
Callback Type | URL |
---|---|
Inbound Message Callback | {ngrok-url}/messaging/inbound |
Outbound Message Status Callback | {ngrok-url}/messaging/outbound built at run time |
Run the following commands to get started
$ git clone https://github.com/d-telnyx/demo-java-telnyx.git
$ cd spring-messaging-auto-response
$ mvn clean install
This application is served on the port defined in the runtime environment (or in the .env
file). Be sure to launch ngrok for that port
./ngrok http 8000
Terminal should look something like
ngrok by @inconshreveable (Ctrl+C to quit)
Session Status online
Account Little Bobby Tables (Plan: Free)
Version 2.3.35
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://your-url.ngrok.io -> http://localhost:8000
Forwarding https://your-url.ngrok.io -> http://localhost:8000
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
At this point you can point your application to generated ngrok URL + path (Example: http://{your-url}.ngrok.io/Callbacks/Voice/Inbound
).
Open your IDE and run the application to launch the spring server
Then text your Telnyx number from your mobile to get different responses!
Application was generated from SpringGenerators, see the Help.md for more information.
The SDK is built using openapi-generator, in order to use the deserializers, you need to include jackson-databind-nullable (see Stack Overflow)
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.1</version>
</dependency>
@Autowired
void configureObjectMapper(final ObjectMapper mapper) {
mapper.registerModule(new JsonNullableModule());
}