Conversación de actualización
En este fragmento de código aprenderás a actualizar una Conversación.
Ejemplo
Asegúrese de que las siguientes variables se ajustan a los valores requeridos utilizando cualquier método conveniente:
| Clave | Descripción |
|---|---|
CONVERSATION_ID | The ID of the Conversation. |
CONV_NEW_NAME | The new name. |
CONV_NEW_DISPLAY_NAME | The new display name. |
Requisitos previos
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.
Ejecute su código
Guarde este archivo en su máquina y ejecútelo:
Requisitos previos
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.
Crea un archivo llamado update-conversation.js y añade el siguiente código:
const { Vonage } = require('@vonage/server-sdk');
const vonage = new Vonage({
applicationId: VONAGE_APPLICATION_ID,
privateKey: VONAGE_PRIVATE_KEY,
});Escriba el código
Añada lo siguiente a 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();Ejecute su código
Guarde este archivo en su máquina y ejecútelo:
Requisitos previos
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.
Añada lo siguiente a build.gradle:
Crea un archivo llamado UpdateConversation y añade el siguiente código al método main:
Escriba el código
Añada lo siguiente al método main del archivo UpdateConversation:
Ejecute su código
Podemos utilizar el plugin aplicación para Gradle para simplificar la ejecución de nuestra aplicación. Actualiza tu build.gradle con lo siguiente:
Ejecute el siguiente comando gradle para ejecutar su aplicación, sustituyendo com.vonage.quickstart.conversation por el paquete que contiene UpdateConversation:
Requisitos previos
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.
Crea un archivo llamado UpdateConversation.cs y añade el siguiente código:
Añada lo siguiente a UpdateConversation.cs:
Requisitos previos
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.
Crea un archivo llamado update-conversations.php y añade el siguiente código:
Ejecute su código
Guarde este archivo en su máquina y ejecútelo:
Pruébalo
Cuando ejecute el código actualizará la Conversación especificada con un nuevo nombre y nombre para mostrar.