Mise à jour de l'application

Dans cet extrait de code, vous verrez comment mettre à jour une Applications.

Exemple

Vous devrez vous assurer que les valeurs remplaçables suivantes sont définies dans le code de l'exemple à l'aide d'une méthode appropriée :

Clé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).

VONAGE_APPLICATION_ID

The Vonage Application ID.

NAME

The new name for the Vonage application you want to update.

Rédiger le code

Ajouter ce qui suit à 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": {

Voir la source complète

Exécutez votre code

Enregistrez ce fichier sur votre machine et exécutez-le :

./update-application.sh

Conditions préalables

npm install @vonage/server-sdk

Créez un fichier nommé update-application.js et ajoutez le code suivant :

const { Vonage } = require('@vonage/server-sdk');

const vonage = new Vonage({
  apiKey: VONAGE_API_KEY,
  apiSecret: VONAGE_API_SECRET,
});

Voir la source complète

Rédiger le code

Ajouter ce qui suit à 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));

Voir la source complète

Exécutez votre code

Enregistrez ce fichier sur votre machine et exécutez-le :

node update-application.js

Conditions préalables

Ajouter ce qui suit à build.gradle:

implementation 'com.vonage:server-sdk-kotlin:2.1.1'

Créez un fichier nommé UpdateApplication et ajoutez le code suivant à la méthode main:

val client = Vonage {
    apiKey(VONAGE_API_KEY)
    apiSecret(VONAGE_API_SECRET)
}

Voir la source complète

Rédiger le code

Ajouter ce qui suit à la méthode main du fichier UpdateApplication:

val application = client.application.application(VONAGE_APPLICATION_ID).update {
    name(APPLICATION_NAME)
    messages {
        inbound {
            address("https://example.com/webhooks/inbound")
            method(HttpMethod.POST)
        }
        status {
            address("https://example.com/webhooks/status")
            method(HttpMethod.POST)
        }
    }
    voice {
        answer {
            address("https://example.com/webhooks/answer")
            method(HttpMethod.GET)
        }
        event {
            address("https://example.com/webhooks/event")
            method(HttpMethod.POST)
        }
        rtc {
            event {
                address("https://example.com/webhooks/event")
                method(HttpMethod.POST)
            }
        }
        vbc()
    }
}

Voir la source complète

Exécutez votre code

Nous pouvons utiliser le plugin application pour Gradle afin de simplifier l'exécution de notre application. Mettez à jour votre build.gradle avec ce qui suit :

apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''

Lancez la commande suivante gradle pour exécuter votre application, en remplaçant com.vonage.quickstart.kt.application par le paquet contenant UpdateApplication:

gradle run -Pmain=com.vonage.quickstart.kt.application.UpdateApplication

Conditions préalables

Ajouter ce qui suit à build.gradle:

implementation 'com.vonage:server-sdk:9.3.1'

Créez un fichier nommé UpdateApplication et ajoutez le code suivant à la méthode main:

VonageClient client = VonageClient.builder()
        .apiKey(VONAGE_API_KEY)
        .apiSecret(VONAGE_API_SECRET)
        .build();

Voir la source complète

Rédiger le code

Ajouter ce qui suit à la méthode main du fichier UpdateApplication:

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());

Voir la source complète

Exécutez votre code

Nous pouvons utiliser le plugin application pour Gradle afin de simplifier l'exécution de notre application. Mettez à jour votre build.gradle avec ce qui suit :

apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''

Lancez la commande suivante gradle pour exécuter votre application, en remplaçant com.vonage.quickstart.application par le paquet contenant UpdateApplication:

gradle run -Pmain=com.vonage.quickstart.application.UpdateApplication

Conditions préalables

Install-Package Vonage

Créez un fichier nommé UpdateApplication.cs et ajoutez le code suivant :

using Vonage;
using Vonage.Applications;
using Vonage.Applications.Capabilities;
using Vonage.Request;

Voir la source complète

Ajouter ce qui suit à UpdateApplication.cs:

var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SECRET);
var client = new VonageClient(credentials);

Voir la source complète

Rédiger le code

Ajouter ce qui suit à UpdateApplication.cs:

var request = new CreateApplicationRequest
{
    Name = "New App Name",
    Capabilities = new ApplicationCapabilities
    {
        Messages = Vonage.Applications.Capabilities.Messages.Build()
            .WithInboundUrl("https://example.com/webhooks/inbound")
            .WithStatusUrl("https://example.com/webhooks/status"),
        Rtc = Rtc.Build().WithEventUrl("https://example.com/webhooks/events", WebhookHttpMethod.Post),
        Voice = Vonage.Applications.Capabilities.Voice.Build()
            .WithAnswerUrl("https://example.com/webhooks/answer", WebhookHttpMethod.Get)
            .WithEventUrl("https://example.com/webhooks/events", WebhookHttpMethod.Post),
        Vbc = Vbc.Build()
    }
};
var response = await client.ApplicationClient.UpdateApplicationAsync(VONAGE_APPLICATION_ID, request);

Voir la source complète

Conditions préalables

composer require vonage/client

Créez un fichier nommé update-application.php et ajoutez le code suivant :

$basic  = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Container($basic));

Voir la source complète

Rédiger le code

Ajouter ce qui suit à update-application.php:

try {
    $application = $client->applications()->get(VONAGE_APPLICATION_ID);
    $application->setName('New Name2');
    $application->getVoiceConfig()->setWebhook(
        Nexmo\Application\VoiceConfig::ANSWER,
        new Nexmo\Application\Webhook('http://test.domain/webhook/voice')
    );
    $application = $client->applications()->update($application);

    echo $application->getId() . PHP_EOL;
    echo $application->getName() . PHP_EOL;
} catch (\InvalidArgumentException $e) {
    echo $e->getMessage() . PHP_EOL;
}

Voir la source complète

Exécutez votre code

Enregistrez ce fichier sur votre machine et exécutez-le :

php update-application.php

Conditions préalables

pip install vonage python-dotenv

Rédiger le code

Ajouter ce qui suit à update-application.py:

from vonage import Auth, Vonage
from vonage_application import (ApplicationConfig, ApplicationData,
                                ApplicationUrl, Messages, MessagesWebhooks)

client = Vonage(Auth(api_key=VONAGE_API_KEY, api_secret=VONAGE_API_SECRET))

config = ApplicationConfig(
    name='My Renamed Application',
    capabilities=Messages(
        webhooks=MessagesWebhooks(
            inbound_url=ApplicationUrl(
                address='https://example.com/inbound_new_url', http_method='GET'
            ),
            status_url=ApplicationUrl(
                address='https://example.com/status_new_url', http_method='GET'
            ),
        ),
        authenticate_inbound_media=False,
    ),
)
response: ApplicationData = client.application.update_application(
    id=VONAGE_APPLICATION_ID, config=config
)

print(response)

Voir la source complète

Exécutez votre code

Enregistrez ce fichier sur votre machine et exécutez-le :

python application/update-application.py

Conditions préalables

gem install vonage

Créez un fichier nommé update-application.rb et ajoutez le code suivant :

client = Vonage::Client.new(
  api_key: VONAGE_API_KEY,
  api_secret: VONAGE_API_SECRET
)

Voir la source complète

Rédiger le code

Ajouter ce qui suit à update-application.rb:

response = client.applications.update(
  VONAGE_APPLICATION_ID,
  id: VONAGE_APPLICATION_ID,
  name: 'Ruby Update App',
  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'
        }
      }
    }
  }
)

Voir la source complète

Exécutez votre code

Enregistrez ce fichier sur votre machine et exécutez-le :

ruby update-application.rb