Récupérer les informations relatives à un appel
Un extrait de code qui montre comment récupérer des informations sur un appel. L'appel pour lequel des informations doivent être récupérées est identifié par un UUID.
Exemple
Remplacez les variables suivantes dans le code de l'exemple :
| Clé | Description |
|---|---|
VOICE_CALL_ID | The UUID of the call leg. |
Conditions préalables
Exécutez la commande suivante à l'invite de votre terminal pour créer le site JWT pour l'authentification :
export JWT=$(nexmo jwt:generate $PATH_TO_PRIVATE_KEY application_id=$NEXMO_APPLICATION_ID)Rédiger le code
Ajouter ce qui suit à retrieve-info-for-a-call.sh:
curl "https://api.nexmo.com/v1/calls/"$VOICE_CALL_ID \
-H "Authorization: Bearer $JWT" \Exécutez votre code
Enregistrez ce fichier sur votre machine et exécutez-le :
Conditions préalables
npm install @vonage/server-sdkCréez un fichier nommé retrieve-info-for-a-call.js et ajoutez le code suivant :
const { Vonage } = require('@vonage/server-sdk');
const vonage = new Vonage({
applicationId: VONAGE_APPLICATION_ID,
privateKey: VONAGE_PRIVATE_KEY,
});Rédiger le code
Ajouter ce qui suit à retrieve-info-for-a-call.js:
vonage.voice.getCall(VOICE_CALL_ID)
.then((call) => console.log(call))
.catch((error) => console.error(error));Exécutez votre code
Enregistrez ce fichier sur votre machine et exécutez-le :
Conditions préalables
Ajouter ce qui suit à build.gradle:
implementation 'com.vonage:server-sdk-kotlin:2.1.1'Créez un fichier nommé RetrieveCallInfo et ajoutez le code suivant à la méthode main:
val client = Vonage {
applicationId(VONAGE_APPLICATION_ID)
privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
}Rédiger le code
Ajouter ce qui suit à la méthode main du fichier RetrieveCallInfo:
val callDetails = client.voice.call(VOICE_CALL_ID).info()
println(callDetails)Exécutez votre code
Nous pouvons utiliser le plugin Applications 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') : ''Exécutez la commande gradle suivante pour exécuter votre application, en remplaçant com.vonage.quickstart.kt.voice par le paquet contenant RetrieveCallInfo:
Conditions préalables
Ajouter ce qui suit à build.gradle:
implementation 'com.vonage:server-sdk:9.3.1'Créez un fichier nommé RetrieveCallInfo et ajoutez le code suivant à la méthode main:
VonageClient client = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build();Rédiger le code
Ajouter ce qui suit à la méthode main du fichier RetrieveCallInfo:
CallInfo details = client.getVoiceClient().getCallDetails(VOICE_CALL_ID);
System.out.println(details);Exécutez votre code
Nous pouvons utiliser le plugin Applications 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') : ''Exécutez la commande gradle suivante pour exécuter votre application, en remplaçant com.vonage.quickstart.voice par le paquet contenant RetrieveCallInfo:
Conditions préalables
Install-Package VonageRédiger le code
Ajouter ce qui suit à RetrieveInfoForCall.cs:
var credentials = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
var client = new VonageClient(credentials);
var response = await client.VoiceClient.GetCallAsync(VOICE_CALL_ID);Conditions préalables
composer require vonage/clientRédiger le code
Ajouter ce qui suit à index.php:
require_once __DIR__ . '/../../vendor/autoload.php';
$keypair = new \Vonage\Client\Credentials\Keypair(file_get_contents(VONAGE_APPLICATION_PRIVATE_KEY_PATH), VONAGE_APPLICATION_ID);
$client = new \Vonage\Client($keypair);
$call = $client->voice()->get(VONAGE_CALL_UUID);
echo json_encode($call->toArray());Exécutez votre code
Enregistrez ce fichier sur votre machine et exécutez-le :
Conditions préalables
pip install vonage python-dotenvRédiger le code
Ajouter ce qui suit à retrieve-info-for-a-call.py:
from vonage import Auth, Vonage
from vonage_voice import CallInfo
client = Vonage(
Auth(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_PRIVATE_KEY,
)
)
response: CallInfo = client.voice.get_call(VOICE_CALL_ID)
pprint(response)Exécutez votre code
Enregistrez ce fichier sur votre machine et exécutez-le :
Conditions préalables
gem install vonageExécutez votre code
Enregistrez ce fichier sur votre machine et exécutez-le :
Essayez-le
Vous devrez :
- Établissez un appel et obtenez l'UUID de l'appel. Pour ce faire, vous pouvez utiliser l'extrait de code "connecter un appel entrant".
- Récupérer les informations relatives à l'appel (cet extrait de code).