Skip to content

Commit 4738c15

Browse files
committed
changes from code snippet audit
1 parent 866c1b0 commit 4738c15

19 files changed

+127
-47
lines changed

.env-example

Lines changed: 0 additions & 13 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.DS_Store
2+
13
# Compiled class file
24
*.class
35

README.md

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,86 @@ So to run the OutboundTextToSpeechExample class, you would run the following:
4242
foreman run java -cp build/libs/nexmo-java-code-snippets-with-dependencies.jar com.nexmo.quickstart.voice.OutboundTextToSpeech
4343
```
4444

45+
Foreman allows you to run only parts of your application instead of having to run the entire jar.
4546
If you set the environment variable `QUICKSTART_DEBUG` to any value, extra information
4647
will be output to the console from the Nexmo Client library.
4748

49+
## Running NCCO Webhook Examples
50+
51+
Sign up for a free [ngrok](https://ngrok.com/) account
52+
53+
Download and install from the ngrok site or use Homebrew (mac0S)
54+
55+
```sh
56+
brew install cask ngrok
57+
```
58+
59+
### Connect the installed ngrok to your ngrok account
60+
1. Go to your ngrok dashboard.
61+
2. Go to Setup & Installation
62+
3. Copy the token from the **Connect your account** step without the `./` prefix. What you copy should look like this:
63+
```shell script
64+
ngrok authentication 112skjl4jlwlkjdl4lkj66565lkjmn56n==e4w4l
65+
```
66+
4. Start a HTTP tunnel forwarding to your local port. Check your snippet to locate the port ngrok should forward to.
67+
For the Voice NCCO snippets we use port 3000, so our command would be:
68+
```shell script
69+
ngrok http 3000
70+
```
71+
72+
You may then enter `http://localhost:4040/inspect/http` in your web browser to see a more detailed view of your requests, or use the
73+
console to http status and message of your requests.
74+
75+
### Setup a Vonage Application
76+
77+
After setting up `ngrok` you will need to setup a Vonage application that will be used for monitoring your webhooks. Add a vonage feature
78+
that you would like your webhook to monitor for. In this example, we will setup a Vonage application and add voice capabilities.
79+
80+
Setup a Vonage Application with voice capabilities using the [Vonage Developer Portal](https://dashboard.nexmo.com/)
81+
1. On the developer portal, go to Applications.
82+
2. Click on the **Create new application** button.
83+
3. Give your applications a name.
84+
4. Under *Capabilities*, toggle the *Voice* capability.
85+
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 the
86+
webhook. Resulting url should look similar to the following:
87+
```sh
88+
http://17e80b46d273.ngrok.io/webhook/answer
89+
```
90+
Go back to the *Voice* capabilities section and add the urls for the webhooks. Ex:
91+
92+
**Answer URL:** http://17e80b46d273.ngrok.io/webhook/answer
93+
94+
**Event URL:** http://17e80b46d273.ngrok.io/webhook/event
95+
96+
**Answer Fallback URL:** http://17e80b46d273.ngrok.io/webhook/fallback (if no path is specified in the snippet use a random domain)
97+
98+
5. Click the **generate public and private key** button. A private key file called private.key should be downloaded to your computer.
99+
6. Move the private key to the nexmo-java-code-snippets project root.
100+
7. Go the developer portal and click **Generate application**
101+
8. In your `.env` file, add the environment variables for your application that is needed to run the snippet to. For the voice dtmf webhook snippet,
102+
we would need the *application id*, and *private key file location*
103+
9. (Optional) Link the number associated with your nexmo account to your app. In the developer portal, click the Link button
104+
on the application details screen to link that number to your application. This will allow you to test webhooks that require you to
105+
call or text a number to test the NCCOs for that snippet.
106+
107+
## Advanced Insight Webhook
108+
109+
To run the Advanced Insight Webhook, you must start the webserver first then run the Advanced Insight snippet
110+
111+
Using your IDE, right click on AsyncInsightTrigger and select Run.
112+
113+
After the web server has started, run the Advanced Insight snippet with foreman.
114+
````sh
115+
foreman run java -cp build/libs/nexmo-java-code-snippets-with-dependencies.jar com.nexmo.quickstart.insight.AdvancedInsightAsync
116+
````
117+
48118
## Request an Example
49119

50120
Please [raise an issue](https://github.com/nexmo-community/nexmo-java-quickstart/issues) to request an example that isn't present within the quickstart. Pull requests will be gratefully received.
51121

52122
## License
53123

54-
This code is licensed under the [MIT](LICENSE.txt) license.
124+
This code is licensed under the [MIT](LICENSE.md) license.
55125

56126
[gradle]: https://gradle.org/
57127
[foreman]: https://github.com/ddollar/foreman

build.gradle

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11

2-
apply plugin: 'java'
2+
plugins {
3+
id 'java'
4+
}
35

46
// Uncomment the following lines to work with a local copy of nexmo-java:
5-
// configurations.all {
6-
// resolutionStrategy.dependencySubstitution {
7-
// substitute module("com.nexmo:client") with project(":client")
8-
// }
9-
// }
7+
configurations.all {
8+
resolutionStrategy.dependencySubstitution {
9+
substitute module("com.nexmo:client") with project(":client")
10+
}
11+
}
1012

1113
repositories {
1214
mavenCentral()
1315
}
1416

1517
dependencies {
16-
testCompile 'junit:junit:4.12'
18+
testImplementation 'junit:junit:4.12'
1719

18-
compile 'com.nexmo:client:5.2.0'
19-
compile "com.sparkjava:spark-core:2.6.0"
20-
compile 'javax.xml.bind:jaxb-api:2.3.0'
20+
implementation 'com.nexmo:client:5.2.0'
21+
implementation 'com.sparkjava:spark-core:2.6.0'
22+
implementation 'javax.xml.bind:jaxb-api:2.3.0'
23+
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.9'
2124
}
2225

23-
task fatJar(type: Jar, dependsOn:configurations.runtime) {
24-
baseName = project.name + '-with-dependencies'
25-
from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } }
26+
task fatJar(type: Jar, dependsOn:configurations.runtimeClasspath) {
27+
archiveBaseName = project.name + '-with-dependencies'
28+
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
2629
with jar
2730
}
31+
2832
assemble.dependsOn fatJar

settings.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Uncomment the following (and update the path if necessary)
22
// to work with a local copy of nexmo-java:
3-
//include ':client'
4-
//project(':client').projectDir = new File(settingsDir, '../nexmo-java')
3+
include ':client'
4+
project(':client').projectDir = new File(settingsDir, '../nexmo-java')

src/main/java/com/nexmo/quickstart/application/DeleteApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,7 @@ public static void main(String... args) {
4040
ApplicationClient applicationClient = client.getApplicationClient();
4141

4242
applicationClient.deleteApplication(NEXMO_APPLICATION_ID);
43+
44+
System.out.println("Application Deleted");
4345
}
4446
}

src/main/java/com/nexmo/quickstart/sms/ReceiveSMS.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static void main(String[] args) throws Exception {
4949
return "";
5050
};
5151

52-
Spark.port(8080);
52+
Spark.port(3000);
5353
Spark.get("/webhooks/inbound-sms", inboundSmsAsGet);
5454
Spark.post("/webhooks/inbound-sms", inboundSmsAsPost);
5555
}

src/main/java/com/nexmo/quickstart/sms/SendUnicodeMessage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ public static void main(String[] args) throws Exception {
4040

4141
NexmoClient client = NexmoClient.builder().apiKey(NEXMO_API_KEY).apiSecret(NEXMO_API_SECRET).build();
4242

43-
TextMessage message = new TextMessage("Acme Inc", TO_NUMBER, "Blue Öyster Cult \uD83E\uDD18", true);
43+
TextMessage message = new TextMessage("17603592332", TO_NUMBER, "Blue Öyster Cult \uD83E\uDD18", true);
4444

4545
SmsSubmissionResponse responses = client.getSmsClient().submitMessage(message);
4646

4747
for (SmsSubmissionResponseMessage responseMessage : responses.getMessages()) {
48-
System.out.println(message);
48+
System.out.println(responseMessage);
4949
}
5050
}
5151
}

src/main/java/com/nexmo/quickstart/voice/EarmuffCall.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static void main(String... args) throws Exception {
2828
CallEvent call = client.getVoiceClient().createCall(new Call(
2929
TO_NUMBER,
3030
NEXMO_NUMBER,
31-
"https://gist.githubusercontent.com/cr0wst/9417cac4c0d9004805a04aed403ae94a/raw/b95e3cd5126587d25986e0bf832eb33a7538394d/tts_long.json"
31+
"https://gist.githubusercontent.com/yallen011/e720c5d127791e0995a9359c195c1eaa/raw/882dfde8e26ebcd167628a576d244d8915cbaac4/long-tts.json"
3232
));
3333

3434
/*

src/main/java/com/nexmo/quickstart/voice/ModifyCall.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import static com.nexmo.quickstart.Util.envVar;
3232

3333
public class ModifyCall {
34-
public static void main(String[] args) throws Exception {
34+
public static void main(String[] args) throws InterruptedException {
3535
configureLogging();
3636

3737
String NEXMO_NUMBER = envVar("NEXMO_NUMBER");
@@ -48,7 +48,7 @@ public static void main(String[] args) throws Exception {
4848
CallEvent call = client.getVoiceClient().createCall(new Call(
4949
TO_NUMBER,
5050
NEXMO_NUMBER,
51-
"https://gist.githubusercontent.com/ChrisGuzman/d6add5b23a8cf913dcdc5a8eabc223ef/raw/a1eb52e0ce2d3cef98bab14d27f3adcdff2af881/long_talk.json"
51+
"https://gist.githubusercontent.com/yallen011/e720c5d127791e0995a9359c195c1eaa/raw/882dfde8e26ebcd167628a576d244d8915cbaac4/long-tts.json"
5252
));
5353

5454
Thread.sleep(20000);

src/main/java/com/nexmo/quickstart/voice/MuteCall.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static void main(String... args) throws Exception {
2828
CallEvent call = client.getVoiceClient().createCall(new Call(
2929
TO_NUMBER,
3030
NEXMO_NUMBER,
31-
"https://gist.githubusercontent.com/cr0wst/9417cac4c0d9004805a04aed403ae94a/raw/b95e3cd5126587d25986e0bf832eb33a7538394d/tts_long.json"
31+
"https://gist.githubusercontent.com/yallen011/e720c5d127791e0995a9359c195c1eaa/raw/882dfde8e26ebcd167628a576d244d8915cbaac4/long-tts.json"
3232
));
3333

3434
/*

src/main/java/com/nexmo/quickstart/voice/OutboundTextToSpeechWithEventUrl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static void main(String[] args) throws Exception {
2525
Call call = new Call(
2626
TO_NUMBER,
2727
NEXMO_NUMBER,
28-
"https://nexmo-community.github.io/ncco-examples/first_call_talk.json"
28+
"https://nexmo-community.github.io/ncco-examples/talk.json"
2929
);
3030
call.setEventUrl(EVENT_URL);
3131
client.getVoiceClient().createCall(call);

src/main/java/com/nexmo/quickstart/voice/RecordCallSplitAudio.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static void main(String[] args) {
5151

5252
res.type("application/json");
5353

54-
return new Ncco(record, connect);
54+
return new Ncco(record, connect).toJson();
5555
};
5656

5757
/*

src/main/java/com/nexmo/quickstart/voice/RetrieveCallInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static void main(String... args) throws Exception {
2828
CallEvent call = client.getVoiceClient().createCall(new Call(
2929
TO_NUMBER,
3030
NEXMO_NUMBER,
31-
"https://gist.githubusercontent.com/cr0wst/9417cac4c0d9004805a04aed403ae94a/raw/b95e3cd5126587d25986e0bf832eb33a7538394d/tts_long.json"
31+
"https://gist.githubusercontent.com/yallen011/e720c5d127791e0995a9359c195c1eaa/raw/882dfde8e26ebcd167628a576d244d8915cbaac4/long-tts.json"
3232
));
3333

3434
/*

src/main/java/com/nexmo/quickstart/voice/RetrieveInfoForAllCalls.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.nexmo.quickstart.voice;
22

3+
import com.fasterxml.jackson.core.JsonProcessingException;
34
import com.fasterxml.jackson.databind.ObjectMapper;
45
import com.nexmo.client.NexmoClient;
56
import com.nexmo.client.voice.CallInfoPage;
@@ -13,7 +14,7 @@
1314
import static com.nexmo.quickstart.Util.envVar;
1415

1516
public class RetrieveInfoForAllCalls {
16-
public static void main(String... args) throws Exception {
17+
public static void main(String... args) throws Exception, JsonProcessingException {
1718
configureLogging();
1819

1920
final String NEXMO_APPLICATION_ID = envVar("NEXMO_APPLICATION_ID");
@@ -32,7 +33,14 @@ public static void main(String... args) throws Exception {
3233
CallInfoPage calls = client.getVoiceClient().listCalls(filter);
3334

3435
// com.fasterxml.jackson.databind.ObjectMapper;
35-
System.out.println(new ObjectMapper().writer().writeValueAsString(calls));
36+
calls.iterator().forEachRemaining(callInfo -> {
37+
try {
38+
System.out.println(new ObjectMapper().writer().writeValueAsString(callInfo));
39+
} catch (JsonProcessingException e) {
40+
e.printStackTrace();
41+
}
42+
});
43+
3644
}
3745

3846
private static Date getTodaysDate() {

src/main/java/com/nexmo/quickstart/voice/SendDtmfToCall.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.nexmo.client.NexmoClient;
2626
import com.nexmo.client.voice.Call;
2727
import com.nexmo.client.voice.CallEvent;
28+
import com.nexmo.client.voice.DtmfResponse;
2829

2930
import static com.nexmo.quickstart.Util.configureLogging;
3031
import static com.nexmo.quickstart.Util.envVar;
@@ -46,13 +47,15 @@ public static void main(String[] args) throws Exception {
4647
CallEvent call = client.getVoiceClient().createCall(new Call(
4748
TO_NUMBER,
4849
NEXMO_NUMBER,
49-
"https://gist.githubusercontent.com/ChrisGuzman/d6add5b23a8cf913dcdc5a8eabc223ef/raw/a1eb52e0ce2d3cef98bab14d27f3adcdff2af881/long_talk.json"
50+
"https://gist.githubusercontent.com/yallen011/e720c5d127791e0995a9359c195c1eaa/raw/882dfde8e26ebcd167628a576d244d8915cbaac4/long-tts.json"
5051
));
5152

5253
Thread.sleep(20000);
5354

5455
final String UUID = call.getUuid();
5556
final String DIGITS = "332393";
56-
client.getVoiceClient().sendDtmf(UUID, DIGITS);
57+
58+
DtmfResponse response = client.getVoiceClient().sendDtmf(UUID, DIGITS);
59+
System.out.println(response.getMessage());
5760
}
5861
}

src/main/java/com/nexmo/quickstart/voice/SendTalkToCall.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.nexmo.client.NexmoClient;
44
import com.nexmo.client.voice.Call;
55
import com.nexmo.client.voice.CallEvent;
6+
import com.nexmo.client.voice.TalkResponse;
67
import com.nexmo.client.voice.VoiceName;
78

89
import static com.nexmo.quickstart.Util.configureLogging;
@@ -33,6 +34,7 @@ public static void main(String[] args) throws Exception {
3334
client.getVoiceClient().startTalk(UUID, TEXT, VoiceName.KIMBERLY, 0);
3435

3536
Thread.sleep(5000);
36-
client.getVoiceClient().stopTalk(UUID);
37+
TalkResponse response = client.getVoiceClient().stopTalk(UUID);
38+
System.out.println(response.getMessage());
3739
}
3840
}

src/main/java/com/nexmo/quickstart/voice/StreamAudioToCall.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static void main(String[] args) throws Exception {
4646
CallEvent call = client.getVoiceClient().createCall(new Call(
4747
TO_NUMBER,
4848
NEXMO_NUMBER,
49-
"https://gist.githubusercontent.com/ChrisGuzman/d6add5b23a8cf913dcdc5a8eabc223ef/raw/a1eb52e0ce2d3cef98bab14d27f3adcdff2af881/long_talk.json"
49+
"https://gist.githubusercontent.com/yallen011/e720c5d127791e0995a9359c195c1eaa/raw/882dfde8e26ebcd167628a576d244d8915cbaac4/long-tts.json"
5050
));
5151

5252
Thread.sleep(20000);

src/main/java/com/nexmo/quickstart/voice/TransferCall.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.nexmo.client.NexmoClient;
44
import com.nexmo.client.voice.Call;
55
import com.nexmo.client.voice.CallEvent;
6+
import com.nexmo.client.voice.ModifyCallResponse;
67

78
import static com.nexmo.quickstart.Util.configureLogging;
89
import static com.nexmo.quickstart.Util.envVar;
@@ -28,7 +29,7 @@ public static void main(String... args) throws Exception {
2829
CallEvent call = client.getVoiceClient().createCall(new Call(
2930
TO_NUMBER,
3031
NEXMO_NUMBER,
31-
"https://gist.githubusercontent.com/cr0wst/9417cac4c0d9004805a04aed403ae94a/raw/b95e3cd5126587d25986e0bf832eb33a7538394d/tts_long.json"
32+
"https://gist.githubusercontent.com/yallen011/e720c5d127791e0995a9359c195c1eaa/raw/882dfde8e26ebcd167628a576d244d8915cbaac4/long-tts.json"
3233
));
3334

3435
/*
@@ -38,6 +39,7 @@ public static void main(String... args) throws Exception {
3839

3940
final String UUID = call.getUuid();
4041
final String NCCO_URL = "https://developer.nexmo.com/ncco/tts.json";
41-
client.getVoiceClient().transferCall(UUID, NCCO_URL);
42+
ModifyCallResponse response = client.getVoiceClient().transferCall(UUID, NCCO_URL);
43+
System.out.println(response);
4244
}
4345
}

0 commit comments

Comments
 (0)