アプリケーションの更新
このコード・スニペットでは、Applicationsを更新する方法を説明します。
例
以下の置換可能な値が、便利な方法でサンプルコードに設定されていることを確認する必要があります:
| キー | 説明 |
|---|---|
VONAGE_API_KEY | Your Vonage API key (see it on your dashboard). |
VONAGE_API_SECRET | Your Vonage API secret (also available on your dashboard). |
VONAGE_APPLICATION_ID | The Vonage Application ID. |
NAME | The new name for the Vonage application you want to update. |
Write the code
Add the following to update-application.sh:
curl -X "PUT" "https://api.nexmo.com/v2/applications/$VONAGE_APPLICATION_ID" \
-H 'Content-Type: application/json' \
-u "$VONAGE_API_KEY:$VONAGE_API_SECRET" \
-d $'{
"name": "New App Name",
"capabilities": {
"messages": {
"webhooks": {
"inbound_url": {
"address": "https://example.com/webhooks/inbound",
"http_method": "POST"
},
"status_url": {
"address": "https://example.com/webhooks/status",
"http_method": "POST"
}
}
},
"voice": {
"webhooks": {
"answer_url": {
"address": "https://example.com/webhooks/answer",
"http_method": "POST"
},
"event_url": {
"address": "https://example.com/webhooks/event",
"http_method": "POST"
}
}
},
"rtc": {
"webhooks": {
"event_url": {
"address": "https://example.com/webhooks/event",
"http_method": "POST"
}
}
},
"vbc": {},
"verify": {
"webhooks": {
"status_url": {Run your code
Save this file to your machine and run it:
Prerequisites
npm install @vonage/server-sdkCreate a file named update-application.js and add the following code:
const { Vonage } = require('@vonage/server-sdk');
const vonage = new Vonage({
apiKey: VONAGE_API_KEY,
apiSecret: VONAGE_API_SECRET,
});Write the code
Add the following to update-application.js:
vonage.applications.updateApplication({
id: VONAGE_APPLICATION_ID,
name: 'New App Name',
capabilities: {
messages: {
webhooks: {
inboundUrl: {
address: 'https://example.com/webhooks/inbound',
httpMethod: 'POST',
},
statusUrl: {
address: 'https://example.com/webhooks/status',
httpMethod: 'POST',
},
},
},
voice: {
webhooks: {
answerUrl: {
address: 'https://example.com/webhooks/answer',
httpMethod: 'POST',
},
eventUrl: {
address: 'https://example.com/webhooks/event',
httpMethod: 'POST',
},
},
},
rtc: {
webhooks: {
eventUrl: {
address: 'https://example.com/webhooks/event',
httpMethod: 'POST',
},
},
},
vbc: {},
verify: {
webhooks: {
statusUrl: {
address: 'https://example.com/webhooks/status',
httpMethod: 'POST',
},
},
},
},
})
.then((resp) => console.log(resp))
.catch((error) => console.error(error));Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
Create a class named UpdateApplication and add the following code to the main method:
Run your code
We can use the アプリケーション 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 UpdateApplication:
Prerequisites
Add the following to build.gradle:
Create a class named UpdateApplication 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 UpdateApplication class:
ApplicationClient applicationClient = client.getApplicationClient();
Application existingApplication = applicationClient.getApplication(VONAGE_APPLICATION_ID);
Capability messages = 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();
Capability voice = Voice.builder()
.answer(Webhook.builder()
.address("https://example.com/webhooks/answer")
.method(HttpMethod.POST)
.build()
)
.event(Webhook.builder()
.address("https://example.com/webhooks/event")
.method(HttpMethod.POST)
.build()
)
.build();
Capability rtc = Rtc.builder()
.event(Webhook.builder()
.address("https://example.com/webhooks/event")
.method(HttpMethod.POST)
.build()
)
.build();
Capability vbc = Vbc.builder().build();
Application application = applicationClient.updateApplication(
Application.builder(existingApplication)
.name(APPLICATION_NAME)
.addCapability(messages)
.addCapability(voice)
.addCapability(rtc)
.addCapability(vbc)
.build()
);
System.out.println("Application Updated:");
System.out.println("Old: " + existingApplication.toJson());
System.out.println("New: " + application.toJson());Run your code
We can use the アプリケーション 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 UpdateApplication:
Prerequisites
Install-Package VonageCreate a file named UpdateApplication.cs and add the following code:
Add the following to UpdateApplication.cs:
Prerequisites
composer require vonage/clientCreate a file named update-application.php and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
pip install vonage python-dotenvRun your code
Save this file to your machine and run it:
Prerequisites
gem install vonageCreate a file named update-application.rb and add the following code:
client = Vonage::Client.new(
api_key: VONAGE_API_KEY,
api_secret: VONAGE_API_SECRET
)Run your code
Save this file to your machine and run it: