Create an Application
In this code snippet you will see how to create an Application.
Example
You will need to ensure that the following replaceable values are set in the example code using any convenient method:
| Key | Description |
|---|---|
VONAGE_API_KEY | Your Vonage API key (see it on your dashboard). |
VONAGE_API_SECRET | Your Vonage API secret (also available on your dashboard). |
Run your code
Save this file to your machine and run it:
Prerequisites
Create a file named create-application.js and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
Create a file named CreateApplication and add the following code to the main method:
Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.application with the package containing CreateApplication:
Prerequisites
Add the following to build.gradle:
Create a file named CreateApplication and add the following code to the main method:
VonageClient client = VonageClient.builder()
.apiKey(VONAGE_API_KEY)
.apiSecret(VONAGE_API_SECRET)
.build();Write the code
Add the following to the main method of the CreateApplication file:
Application application = client.getApplicationClient().createApplication(
Application.builder()
.name(APPLICATION_NAME)
.addCapability(Messages.builder()
.inbound(Webhook.builder()
.address("https://example.com/webhooks/inbound")
.method(HttpMethod.POST)
.build()
)
.status(Webhook.builder()
.address("https://example.com/webhooks/status")
.method(HttpMethod.POST)
.build()
)
.build()
)
.build()
);
System.out.println("Application Created:");
System.out.println(application.toJson());Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.application with the package containing CreateApplication:
Prerequisites
Create a file named CreateApplication.cs and add the following code:
Add the following to CreateApplication.cs:
Prerequisites
Create a file named create-application.php and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
Write the code
Add the following to create-application.py:
from vonage import Auth, Vonage
from vonage_application import (ApplicationConfig, ApplicationData,
ApplicationUrl, Capabilities, Messages,
MessagesWebhooks, Region, Verify,
VerifyWebhooks, Voice, VoiceUrl, VoiceWebhooks)
client = Vonage(Auth(api_key=VONAGE_API_KEY, api_secret=VONAGE_API_SECRET))
# Voice application options
voice = Voice(
webhooks=VoiceWebhooks(
answer_url=VoiceUrl(
address='https://example.com/answer',
http_method='POST',
connect_timeout=500,
socket_timeout=3000,
),
fallback_answer_url=VoiceUrl(
address='https://example.com/fallback',
http_method='POST',
connect_timeout=500,
socket_timeout=3000,
),
event_url=VoiceUrl(
address='https://example.com/event',
http_method='POST',
connect_timeout=500,
socket_timeout=3000,
),
),
signed_callbacks=True,
conversations_ttl=8000,
leg_persistence_time=14,
region=Region.NA_EAST,
)
# Messages application options
messages = Messages(
version='v1',
webhooks=MessagesWebhooks(
inbound_url=ApplicationUrl(
address='https://example.com/inbound', http_method='POST'
),
status_url=ApplicationUrl(
address='https://example.com/status', http_method='POST'
),
),
authenticate_inbound_media=True,
)
# Verify application options
verify = Verify(
webhooks=VerifyWebhooks(
status_url=ApplicationUrl(address='https://example.com/status', http_method='GET')
),
)
# Set the application capabilities
capabilities = Capabilities(voice=voice, messages=messages, verify=verify)
# Set the application configuration that will be applied
params = ApplicationConfig(
name='My Custom Application',
capabilities=capabilities,
)
# Call the API
response: ApplicationData = client.application.create_application(params)
print(response)Run your code
Save this file to your machine and run it:
Prerequisites
Create a file named create-application.rb and add the following code:
Run your code
Save this file to your machine and run it: