Crear un miembro
En este fragmento de código aprenderás a crear un Miembro. Un Miembro puede ser considerado como un Usuario que ha sido invitado, se ha unido o ha abandonado 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. |
USER_ID | The unique ID of the User. |
Requisitos previos
You will need to use an existing Application that contains a Conversation in order to be able to create a Member. See the Create Conversation code snippet for information on how to create an Application and some sample Conversations.
Escriba el código
Añada lo siguiente a create-member.sh:
curl -X "POST" "https://api.nexmo.com/v1/conversations/$CONV_ID/members" \
-H 'Authorization: Bearer '$JWT\
-H 'Content-Type: application/json' \
-d $'{
"user": {
"id": "'$CONV_USER_ID'"
},
"state": "'$CONV_MEMBER_STATE'",
"channel": {
"type": "app"
}
}'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 a Conversation in order to be able to create a Member. See the Create Conversation code snippet for information on how to create an Application and some sample Conversations.
npm install @vonage/server-sdkCrea un archivo llamado create-member.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 create-member.js:
const run = async () => {
const member = vonage.conversations.createMember(
CONV_ID,
{
user: {
id: CONV_USER_ID,
},
state: CONV_MEMBER_STATE,
channel: {
type:'app',
},
},
);
console.log(member);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 a Conversation in order to be able to create a Member. 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:
implementation 'com.vonage:server-sdk:9.3.1'Crea un archivo llamado CreateMember y añade el siguiente código al método main:
VonageClient client = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build();Escriba el código
Añada lo siguiente al método main del archivo CreateMember:
var member = client.getConversationsClient().createMember(
CONV_ID, Member.builder()
.channelType(ChannelType.APP)
.state(CONV_MEMBER_STATE)
.user(USER_ID)
.build()
);
System.out.println(member);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:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Ejecute el siguiente comando gradle para ejecutar su aplicación, sustituyendo com.vonage.quickstart.conversation por el paquete que contiene CreateMember:
Requisitos previos
You will need to use an existing Application that contains a Conversation in order to be able to create a Member. See the Create Conversation code snippet for information on how to create an Application and some sample Conversations.
Install-Package VonageCrea un archivo llamado CreateMember.cs y añade el siguiente código:
using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Vonage;
using Vonage.Conversations;
using Vonage.Conversations.CreateMember;
using Vonage.Request;Añada lo siguiente a CreateMember.cs:
var credentials = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
var client = new VonageClient(credentials);Escriba el código
Añada lo siguiente a CreateMember.cs:
var response = await client.ConversationsClient.CreateMemberAsync(CreateMemberRequest.Build()
.WithConversationId(CONV_ID)
.WithState(CONV_MEMBER_STATE)
.WithUser(new MemberUser(CONV_USER_ID, CONV_USER_NAME))
.WithApp(CONV_USER_ID, ChannelType.App)
.Create());Requisitos previos
You will need to use an existing Application that contains a Conversation in order to be able to create a Member. See the Create Conversation code snippet for information on how to create an Application and some sample Conversations.
composer require vonage/clientCrea un archivo llamado create-member.php y añade el siguiente código:
Ejecute su código
Guarde este archivo en su máquina y ejecútelo:
Pruébalo
Al ejecutar el código se creará un nuevo Miembro. El Usuario especificado será invitado a unirse a la Conversación especificada.