Skip to content

Commit c6ef707

Browse files
authored
Update network_apis on startup (#15)
1 parent 04ea4d9 commit c6ef707

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ All the parameters required to run the demo can be provided through environment
2424
- `VONAGE_APPLICATION_ID`: Vonage application UUID.
2525
- `VONAGE_PRIVATE_KEY_PATH`: Absolute path to the private key associated with your Vonage application.
2626
- `VCR_PORT`: Port to run the demo on. By default, this is `8080`.
27+
- `VONAGE_SERVER_URL`: The public base URL for the application. For example, this might be your ngrok instance URL.
2728

2829
Other parameters can be provided for convenience or defaults for pre-populating certain fields. These are:
2930

@@ -40,9 +41,16 @@ If you have [IntelliJ IDEA](https://www.jetbrains.com/idea/) installed, you can
4041
and run it through the IDE, where the entry point is the `Application` class
4142
(src/main/java/com/vonage/sample/serversdk/springboot/Application.java).
4243

43-
To run the demo standalone from the command line, do `mvn install spring-boot:run`.
44+
To run the demo standalone from the command line, simply invoke `mvn` or `./mvnw` if you don't have it installed.
4445
Then open a browser to [localhost:8080](http://localhost:8080) to use the application.
4546

47+
The default Maven goal for this project is `spring-boot:run`. To ensure a full build, you can use `mvn clean install`.
48+
49+
On startup, your Vonage application will be updated with the webhook URLs for the demo.
50+
This is so that you don't have to manually set the webhook URLs on the dashboard every time you restart
51+
ngrok (or your preferred HTTP tunneling service). You can verify this manually by checking the application
52+
from [the Vonage dashboard](https://dashboard.nexmo.com/applications).
53+
4654
### Maven and Gradle
4755
As a demo application, this project uses Maven, however it can be adapted to work with Gradle too.
4856
You can use the Maven wrapper by invoking `./mvnw`. For a local installation, you can download this

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<dependency>
5555
<groupId>com.vonage</groupId>
5656
<artifactId>server-sdk</artifactId>
57-
<version>8.11.0</version>
57+
<version>8.12.0</version>
5858
</dependency>
5959
<dependency>
6060
<groupId>org.springframework.boot</groupId>

src/main/java/com/vonage/sample/serversdk/springboot/ApplicationStartup.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.vonage.client.application.Application;
2525
import com.vonage.client.application.ApplicationResponseException;
2626
import com.vonage.client.application.capabilities.Messages;
27+
import com.vonage.client.application.capabilities.NetworkApis;
2728
import com.vonage.client.application.capabilities.Verify;
2829
import com.vonage.client.application.capabilities.Voice;
2930
import com.vonage.client.common.HttpMethod;
@@ -61,6 +62,11 @@ public void init() {
6162
var application = ac.updateApplication(
6263
Application.builder(existing)
6364
.improveAi(true)
65+
.addCapability(NetworkApis.builder()
66+
.redirectUri(resolveEndpoint(NUMBER_VERIFICATION_REDIRECT_ENDPOINT).toString())
67+
.networkApplicationId(existing.getCapabilities().getNetworkApis().getNetworkApplicationId())
68+
.build()
69+
)
6470
.addCapability(Verify.builder()
6571
.addWebhook(Webhook.Type.STATUS, buildWebhook(VERIFY_STATUS_ENDPOINT)).build()
6672
).addCapability(Messages.builder()

src/main/java/com/vonage/sample/serversdk/springboot/NumberVerificationController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.web.bind.annotation.*;
2929
import org.springframework.web.servlet.view.RedirectView;
3030
import java.net.URI;
31+
import java.util.UUID;
3132

3233
@Controller
3334
public final class NumberVerificationController extends VonageController {
@@ -53,7 +54,7 @@ public RedirectView buildVerificationUrl(@ModelAttribute NumberVerificationParam
5354
var redirectUrl = getServerUrl().resolve(NUMBER_VERIFICATION_REDIRECT_ENDPOINT);
5455
try {
5556
nvParams.url = getNumberVerificationClient().initiateVerification(
56-
nvParams.msisdn, redirectUrl, nvParams.msisdn
57+
nvParams.msisdn, redirectUrl, UUID.randomUUID().toString().replace("-", "")
5758
);
5859
model.addAttribute(NUMBER_VERIFICATION_PARAMS_NAME, nvParams);
5960
return new RedirectView(nvParams.url.toString());

0 commit comments

Comments
 (0)