Indicadores de mecanografía
Product deprecation notice
Effective April 30th, 2026, Vonage In-App Messaging will no longer be available. Access for new users will be closed, and the service will be discontinued for all existing users.
If you have any questions regarding this product’s discontinuation, please contact your account manager or our support team.
Visión general
Esta guía cubre los indicadores de escritura de texto dentro de una conversación.
Antes de empezar, asegúrese de que ha añadido el SDK a su aplicación y eres capaz de crear una conversación.
NOTA: Hay disponible un tutorial paso a paso para crear una aplicación de chat aquí.
Esta guía hará uso de los siguientes conceptos:
- Eventos de conversación -
text:typing:on(empezar a escribir) ytext:typing:off(deje de escribir) eventos que se disparan en una Conversación, después de ser Miembro
Indicadores de mecanografía
Los indicadores de escritura se utilizan para notificar a los miembros de la conversación si un miembro está escribiendo o no un mensaje de texto.
Enviar eventos de estado de escritura
Establezca el estado actual de escritura (activado/desactivado) del usuario cuando empiece o deje de escribir un mensaje de texto:
// call this when a member starts typing
conversation.startTyping();
// call this when a member stops typing
conversation.stopTyping();
// call this when a member starts typing
conversation.startTyping()
// call this when a member stops typing
conversation.stopTyping()
// call this when a member starts typing
conversation.startTyping();
// call this when a member stops typing
conversation.stopTyping();
conversation.sendStartTyping(completionHandler:)
conversation.sendStopTyping(completionHandler:)
// call this when a member starts typing
[conversation sendStartTyping:^(NSError * _Nullable error) completionHandler];
// call this when a member stops typing
[conversation sendStopTyping:^(NSError * _Nullable error) completionHandler];
Escuchar el estado de los demás miembros
Lo siguiente escuchará los eventos de tecleo (encendido/apagado) creados por las llamadas anteriores:
conversation.on('text:typing:on', (event) => {
console.log(event.user.name + " is typing");
});
conversation.on("text:typing:off", (event) => {
console.log(event.user.name + " stopped typing");
});
// Option 1: Listen for typing events using NexmoTypingEventListener
conversation.addTypingEventListener(typingEventListener)
// or
// Option 2: Listen for typing events using NexmoMessageEventListener
conversation.addMessageEventListener(messageListener)
private val typingEventListener = NexmoTypingEventListener { typingEvent ->
val typingState = if(typingEvent?.state == NexmoTypingState.ON) "typing" else "not typing"
Timber.d("User ${typingEvent.fromMemberId} is $typingState")
}
private val messageListener = object : NexmoMessageEventListener {
override fun onTypingEvent(typingEvent: NexmoTypingEvent) {
val typingState = if(typingEvent.state == NexmoTypingState.ON) "typing" else "not typing"
Log.d("TAG", "User ${typingEvent.fromMemberId} is $typingState")
}
override fun onAttachmentEvent(attachmentEvent: NexmoAttachmentEvent) {}
override fun onTextEvent(textEvent: NexmoTextEvent) {}
override fun onSeenReceipt(seenEvent: NexmoSeenEvent) {}
override fun onEventDeleted(deletedEvent: NexmoDeletedEvent) {}
override fun onDeliveredReceipt(deliveredEvent: NexmoDeliveredEvent) {}
}
// Option 1: Listen for typing events using NexmoTypingEventListener
conversation.addTypingEventListener(typingEventListener);
// or
// Option 2: Listen for typing events using NexmoMessageEventListener
conversation.addMessageEventListener(messageListener);
private NexmoTypingEventListener typingEventListener = new NexmoTypingEventListener() {
@Override
public void onTyping(NexmoTypingEvent typingEvent) {
String typingState;
if (typingEvent.getState() == NexmoTypingState.ON) {
typingState = "typing";
} else {
typingState = "not typing";
}
Timber.d("User " + typingEvent.getFromMemberId() + " is " + typingState);
}
};
private NexmoMessageEventListener messageListener = new NexmoMessageEventListener() {
@Override
public void onTypingEvent(@NonNull NexmoTypingEvent typingEvent) {
String typingState;
if (typingEvent.getState() == NexmoTypingState.ON) {
typingState = "typing";
} else {
typingState = "not typing";
}
Log.d("TAG", "User " + typingEvent.getFromMemberId() + " is " + typingState);
}
@Override
public void onTextEvent(@NonNull NexmoTextEvent textEvent) {}
@Override
public void onAttachmentEvent(@NonNull NexmoAttachmentEvent attachmentEvent) {}
@Override
public void onEventDeleted(@NonNull NexmoDeletedEvent deletedEvent) {}
@Override
public void onSeenReceipt(@NonNull NexmoSeenEvent seenEvent) {}
@Override
public void onDeliveredReceipt(@NonNull NexmoDeliveredEvent deliveredEvent) {}
};
Añadir NXMConversationDelegate como extensión de un ViewController o similar, y aplicar conversation(_ conversation: NXMConversation, didReceive event: NXMTextTypingEvent):
Nota: El primer método siguiente es necesario cuando se aplica NXMConversationDelegate:
extension ViewController: NXMConversationDelegate {
func conversation(_ conversation: NXMConversation, didReceive error: Error) {
NSLog("Conversation error: \(error.localizedDescription)")
}
func conversation(_ conversation: NXMConversation, didReceive event: NXMTextTypingEvent) {
if event.status == .on {
NSLog("Started typing")
} else {
NSLog("Typing ended")
}
}
}
Tener un ViewControllero similar, se ajustan a NXMConversationDelegate y aplicar conversation:didReceiveTypingEvent::
Nota: El primer método siguiente es necesario cuando se aplica NXMConversationDelegate:
- (void)conversation:(NXMConversation *)conversation didReceive:(NSError *)error {
NSLog(@"Conversation error: %@", error.localizedDescription);
}
- (void)conversation:(NXMConversation *)conversation didReceiveTypingEvent:(NXMTextTypingEvent *)event {
if (event.status == NXMTextTypingEventStatusOn) {
NSLog(@"Started typing");
} else {
NSLog(@"Typing ended");
}
}