- Notifications
You must be signed in to change notification settings - Fork32
Java code examples for using Vonage
License
Vonage/vonage-java-code-snippets
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Quickstarts also available for:Python,.NET,Node.js,PHP,Ruby andcurl.
The purpose of the quickstart guide is to provide simple examples focused onone goal. For example, sending an SMS, handling an incoming SMS webhook,making a Text to Speech call.
To use this sample you will first need aNexmo account.
For some of the examples you will need tobuy a number.
You will need to haveGradle installed to build the code. Onceyou have gradle installed, run the following to build a jar that containsthe quickstart code along with all the nexmo client library dependencies:
gradle assemble
This will build the following file:build/libs/nexmo-java-quickstart-with-dependencies.jar
Copy.env-example to.env and edit the values. You'll need to load thosevalues into environment variables, so you'll probably want to use a tool likeForeman to run your code like this:
foreman run java -cp build/libs/nexmo-java-quickstart-with-dependencies.jar CLASS
So to run the OutboundTextToSpeechExample class, you would run the following:
foreman run java -cp build/libs/nexmo-java-code-snippets-with-dependencies.jar com.nexmo.quickstart.voice.OutboundTextToSpeech
Foreman allows you to run only parts of your application instead of having to run the entire jar.If you set the environment variableQUICKSTART_DEBUG to any value, extra informationwill be output to the console from the Nexmo Client library.
Sign up for a freengrok account
Download and install from the ngrok site or use Homebrew (mac0S)
brew install cask ngrok
- Go to your ngrok dashboard.
- Go to Setup & Installation
- Copy the token from theConnect your account step without the
./prefix. What you copy should look like this:
ngrok authentication 112skjl4jlwlkjdl4lkj66565lkjmn56n==e4w4l
- Start a HTTP tunnel forwarding to your local port. Check your snippet to locate the port ngrok should forward to.For the Voice NCCO snippets we use port 3000, so our command would be:
ngrok http 3000
You may then enterhttp://localhost:4040/inspect/http in your web browser to see a more detailed view of your requests, or use theconsole to http status and message of your requests.
After setting upngrok you will need to setup a Vonage application that will be used for monitoring your webhooks. Add a vonage featurethat you would like your webhook to monitor for. In this example, we will setup a Vonage application and add voice capabilities.
Setup a Vonage Application with voice capabilities using theVonage Developer Portal
- On the developer portal, go to Applications.
- Click on theCreate new application button.
- Give your applications a name.
- UnderCapabilities, toggle theVoice capability.Go back to the terminal that has ngrok fired up and grab the forwarding url. Add that domain as the prefix to the path for thewebhook. Resulting url should look similar to the following:
http://17e80b46d273.ngrok.io/webhook/answer
Go back to theVoice capabilities section and add the urls for the webhooks. Ex:
Answer URL:http://17e80b46d273.ngrok.io/webhook/answer
Event URL:http://17e80b46d273.ngrok.io/webhook/event
Answer Fallback URL:http://17e80b46d273.ngrok.io/webhook/fallback (if no path is specified in the snippet use a random domain)
- Click thegenerate public and private key button. A private key file called private.key should be downloaded to your computer.
- Move the private key to the nexmo-java-code-snippets project root.
- Go the developer portal and clickGenerate application
- In your
.envfile, add the environment variables for your application that is needed to run the snippet to. For the voice dtmf webhook snippet,we would need theapplication id, andprivate key file location - (Optional) Link the number associated with your nexmo account to your app. In the developer portal, click the Link buttonon the application details screen to link that number to your application. This will allow you to test webhooks that require you tocall or text a number to test the NCCOs for that snippet.
Pleaseraise an issue to request an example that isn't present within the quickstart. Pull requests will be gratefully received.
This code is licensed under theMIT license.
About
Java code examples for using Vonage
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.