Mise à jour de la conversation
Dans cet extrait de code, vous apprendrez à mettre à jour une conversation.
Exemple
Veillez à ce que les variables suivantes soient réglées sur les valeurs souhaitées en utilisant toute méthode appropriée :
| Clé | Description |
|---|---|
CONVERSATION_ID | The ID of the Conversation. |
CONV_NEW_NAME | The new name. |
CONV_NEW_DISPLAY_NAME | The new display name. |
Conditions préalables
You will need to use an existing Application that contains Conversations in order to be able to update one. See the Create Conversation code snippet for information on how to create an Application and some sample Conversations.
Rédiger le code
Ajouter ce qui suit à update-conversation.sh:
curl -X "PUT" "https://api.nexmo.com/v1/conversations/$CONV_ID" \
-H 'Authorization: Bearer '$JWT\
-H 'Content-Type: application/json' \
-d $'{
"name": "$CONV_NAME",
"display_name": "$CONV_DISPLAY_NAME"
}'Exécutez votre code
Enregistrez ce fichier sur votre machine et exécutez-le :
Conditions préalables
You will need to use an existing Application that contains Conversations in order to be able to update one. See the Create Conversation code snippet for information on how to create an Application and some sample Conversations.
npm install @vonage/server-sdkCréez un fichier nommé update-conversation.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 à update-conversation.js:
const run = async () => {
let conversation;
try {
// Load the conversation to prevent overwriting
conversation= await vonage.conversations.getConversation(CONVERSATION_ID);
} catch (error) {
console.error('Error loading conversation', error);
return;
}
conversation.name = CONV_NAME;
conversation.displayName = CONV_DISPLAY_NAME;
try {
await vonage.conversations.update(conversation);
console.log('Conversation updated');
} catch (error) {
console.error('Error updating conversation', error);
}
};
run();Exécutez votre code
Enregistrez ce fichier sur votre machine et exécutez-le :
Conditions préalables
You will need to use an existing Application that contains Conversations in order to be able to update one. See the Create Conversation code snippet for information on how to create an Application and some sample Conversations.
Ajouter ce qui suit à build.gradle:
implementation 'com.vonage:server-sdk:9.3.1'Créez un fichier nommé UpdateConversation 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 UpdateConversation:
var updated = client.getConversationsClient().updateConversation(
CONV_ID, Conversation.builder()
.name(CONV_NEW_NAME)
.displayName(CONV_NEW_DISPLAY_NAME)
.build()
);
System.out.println(updated);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.conversation par le paquet contenant UpdateConversation:
Conditions préalables
You will need to use an existing Application that contains Conversations in order to be able to update one. See the Create Conversation code snippet for information on how to create an Application and some sample Conversations.
Install-Package VonageCréez un fichier nommé UpdateConversation.cs et ajoutez le code suivant :
using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Vonage;
using Vonage.Conversations.UpdateConversation;
using Vonage.Request;Ajouter ce qui suit à UpdateConversation.cs:
var credentials = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
var client = new VonageClient(credentials);Rédiger le code
Ajouter ce qui suit à UpdateConversation.cs:
var response = await client.ConversationsClient.UpdateConversationAsync(UpdateConversationRequest.Build()
.WithConversationId(CONV_ID)
.WithName(CONV_NAME)
.WithDisplayName(CONV_DISPLAY_NAME)
.Create());Conditions préalables
You will need to use an existing Application that contains Conversations in order to be able to update one. See the Create Conversation code snippet for information on how to create an Application and some sample Conversations.
composer require vonage/clientCréez un fichier nommé update-conversations.php et ajoutez le code suivant :
Exécutez votre code
Enregistrez ce fichier sur votre machine et exécutez-le :
Essayez-le
Lorsque vous exécutez le code, vous mettez à jour la conversation spécifiée avec un nouveau nom et un nouveau nom d'affichage.