public class NexmoConversation extends java.lang.Object implements android.os.Parcelable, java.lang.Comparable<NexmoConversation>
Class allows users to communicate with each other by sending events (eg. text message or an image). Each
NexmoUser
that joined the conversation (has NexmoMemberState
) is represented as NexmoMember
.
Each conversation message is represented as NexmoEvent
eg. NexmoTextEvent
.
Before creating new conversation NexmoClient
has to be initialized.
Create a new conversation using NexmoClient
instance:
client.newConversation("My NexmoConversation name", "My NexmoConversation display name", new RequestHandler<NexmoConversation>() { @Override public void onSuccess(NexmoConversation conversation) { Log.d("onSuccess", "Conversation loaded " + conversation.getDisplayName()); } @Override public void onError(NexmoAPIError error) { Log.d("onError", "Error: Unable to load conversation %s", apiError.getMessage()); } });
In above example name
can be supplied, but if left empty the name will be
auto-generated and assigned to the conversation.
Load existing conversation:
client.getConversation("conversationId", new NexmoRequestListener() { @Override public void onSuccess(@Nullable NexmoConversation conversation) { Log.d("onSuccess", "Conversation loaded " + conversation.getDisplayName()); } @Override public void onError(@NonNull NexmoApiError error) { Log.d("onError", "Error: Unable to load conversation %s", apiError.getMessage()); } });
Join the NexmoConversation:
conversation.join("username", new NexmoRequestListener<NexmoMember>() { @Override public void onSuccess(NexmoMember member) { // member.getUser().getName(); } @Override public void onError(NexmoAPIError apiError) { // apiError.getMessage()); } });
Send a text message to the conversation:
conversation.sendText("message payload...", new NexmoRequestListener<NexmoEvent>() { @Override public void onSuccess(NexmoEvent event) { // Message sent } @Override public void onError(NexmoAPIError apiError) { // apiError.getMessage()); } });
In above example will be relayed to every other member of the conversation.
Listen for incoming message events:
conversation.addMessageEventListener().add(new MessageEventListener() { @Override public void onTextEvent(TextEvent text) { // New text message received } @Override public void onAttachmentEvent(AttachmentEvent attachment) { // New attachment received } @Override public void onEventDeleted(DeletedEvent deleteEvent) { } });
Load all conversation events:
conversation.getEvents(100, NexmoPageOrder.NexmoMPageOrderAsc, null, new NexmoRequestListener() { @Override public void onSuccess(@Nullable NexmoEventsPage eventsPage) { // eventsPage.getData(); } @Override public void onError(@NonNull NexmoApiError apiError) { // apiError.getMessage()); } });
For more use cases and samples please check the client-sdk-android-samples repository.
Modifier and Type | Field and Description |
---|---|
static android.os.Parcelable.Creator<NexmoConversation> |
CREATOR |
Modifier and Type | Method and Description |
---|---|
void |
addCustomEventListener(NexmoCustomEventListener listener)
Adds a callback to be invoked when custom event is received.
|
void |
addDTMFEventListener(NexmoDTMFEventListener listener)
Deprecated.
|
void |
addLegStatusEventListener(NexmoLegStatusEventListener listener)
Adds a callback to be invoked when leg event is received.
|
void |
addMediaActionEventListener(NexmoMediaActionEventListener mediaActionEventListener)
Adds a callback to be invoked when media action event is received.
|
void |
addMediaEventListener(NexmoMediaEventListener mediaEventListener)
Adds a callback to be invoked when media event is received.
|
void |
addMediaStatusListener(NexmoMediaStatusListener listener)
Adds a callback to be invoked when media status is received.
|
void |
addMemberEventListener(NexmoMemberEventListener listener)
Adds a callback to be invoked when member event is received.
|
void |
addMemberMessageStatusEventListener(NexmoMemberMessageStatusEventListener listener)
Adds a callback to be invoked when member message status event is received.
|
void |
addMessageEventListener(NexmoMessageEventListener listener)
Adds a callback to be invoked when conversation message is received.
|
void |
addNexmoConversationListener(NexmoConversationListener listener)
Adds a callback to be invoked when conversation related event occurs.
|
void |
addTypingEventListener(NexmoTypingEventListener listener)
Adds a callback to be invoked when typing event is received.
|
void |
clearCustomEventListeners()
Unsubscribes all listeners from Custom events.
|
void |
clearDTMFEventListeners()
Unsubscribes all listeners from DTMF events.
|
void |
clearLegStatusEventListeners()
Unsubscribes all listeners from Leg Status events.
|
void |
clearMemberEventListeners()
Unsubscribes all listeners from incoming Member related events.
|
void |
clearMemberMessageStatusEventListeners()
Unsubscribes all listeners from member message status events.
|
void |
clearMessageEventListeners()
Unsubscribes all listeners from incoming Message related events.
|
void |
clearNexmoConversationListeners()
Unsubscribes all listeners from incoming Message related events.
|
void |
clearNexmoEventsListeners()
Unsubscribes all listeners from incoming events.
|
void |
clearTypingEventListeners()
Unsubscribes all listeners from incoming Typing related events.
|
int |
compareTo(NexmoConversation nexmoConversation) |
int |
describeContents() |
void |
disableMedia() |
void |
enableMedia() |
boolean |
equals(java.lang.Object o) |
java.lang.String |
getConversationId()
Gets the id of this conversation synchronously.
|
java.util.Date |
getCreationDate()
Gets the creation date of this conversation synchronously.
|
java.lang.String |
getDisplayName()
Gets the display name of this conversation synchronously.
|
void |
getEvents(java.lang.Integer pageSize,
NexmoPageOrder order,
NexmoRequestListener<NexmoEventsPage> listener)
Deprecated.
|
void |
getEvents(java.lang.Integer pageSize,
NexmoPageOrder order,
java.lang.String eventType,
NexmoRequestListener<NexmoEventsPage> listener) |
java.lang.String |
getLastEventId()
Gets the id of the last NexmoEvent in this conversation synchronously.
|
void |
getMember(java.lang.String memberId,
NexmoRequestListener<NexmoMember> listener)
Get conversation member by id.
|
void |
getMembers(java.lang.Integer pageSize,
NexmoPageOrder order,
NexmoRequestListener<NexmoMembersSummaryPage> listener) |
NexmoMember |
getMyMember()
Gets member of the conversation that represents currently logged in
NexmoUser . |
java.lang.String |
getName()
Gets the name of this conversation synchronously.
|
int |
hashCode() |
void |
invite(java.lang.String userName,
NexmoRequestListener<java.lang.String> listener) |
void |
join(NexmoRequestListener<java.lang.Void> listener)
Joins the current logged in
NexmoUser to this conversation. |
void |
join(java.lang.String username,
NexmoRequestListener<java.lang.String> listener)
Joins a
NexmoUser to this conversation. |
void |
kick(java.lang.String memberId,
NexmoRequestListener<java.lang.Void> listener)
Removes a
NexmoUser from this conversation. |
void |
reconnectMedia()
Manually Reconnect Media Stream
|
void |
removeCustomEventListener(NexmoCustomEventListener listener)
Unsubscribes from Custom events.
|
void |
removeDTMFEventListener(NexmoDTMFEventListener listener)
Deprecated.
|
void |
removeLegStatusEventListener(NexmoLegStatusEventListener listener)
Unsubscribes from Leg Status events.
|
void |
removeMemberEventListener(NexmoMemberEventListener listener)
Unsubscribes from incoming Member related events.
|
void |
removeMemberMessageStatusEventListener(NexmoMemberMessageStatusEventListener listener)
Unsubscribes from member message events.
|
void |
removeMessageEventListener(NexmoMessageEventListener listener)
Unsubscribes from incoming Message related events.
|
void |
removeNexmoConversationListener(NexmoConversationListener listener)
Unsubscribes from incoming Message related events.
|
void |
removeTypingEventListener(NexmoTypingEventListener listener)
Unsubscribes from incoming Typing related events.
|
void |
sendAttachment(java.io.File attachment,
NexmoRequestListener listener)
Deprecated.
Use NexmoClient.uploadAttachment(attachment, listener) and
NexmoConversation.sendMessage(message, listener) methods instead.
Once the image is uploaded, you will be able to access all 3 representations:
|
void |
sendCustomEvent(java.lang.String customType,
java.util.HashMap<java.lang.String,java.lang.Object> customData,
NexmoRequestListener<java.lang.Void> listener)
Sends a Custom event to a conversation.
|
void |
sendMessage(NexmoMessage message,
NexmoRequestListener<java.lang.Void> listener)
Sends a Message event to a conversation.
|
void |
sendText(java.lang.String text,
NexmoRequestListener<java.lang.Void> listener)
Deprecated.
Use NexmoConversation.sendMessage(message, listener) method instead.
|
void |
startTyping()
Sends start typing indication.
|
void |
stopTyping()
Sends stop typing indication.
|
java.lang.String |
toString() |
void |
writeToParcel(android.os.Parcel dest,
int flags) |
public static final android.os.Parcelable.Creator<NexmoConversation> CREATOR
public NexmoMember getMyMember()
NexmoUser
.@Deprecated public void getEvents(java.lang.Integer pageSize, NexmoPageOrder order, NexmoRequestListener<NexmoEventsPage> listener)
public void getEvents(java.lang.Integer pageSize, NexmoPageOrder order, java.lang.String eventType, NexmoRequestListener<NexmoEventsPage> listener)
public void getMembers(java.lang.Integer pageSize, NexmoPageOrder order, NexmoRequestListener<NexmoMembersSummaryPage> listener)
public void getMember(java.lang.String memberId, NexmoRequestListener<NexmoMember> listener)
memberId
- member identifier.public void sendText(java.lang.String text, NexmoRequestListener<java.lang.Void> listener)
text
- The text payload.listener
- The request completion listener.public void sendMessage(NexmoMessage message, NexmoRequestListener<java.lang.Void> listener)
message
- The params of the message event.listener
- The request completion listener.public void sendCustomEvent(java.lang.String customType, java.util.HashMap<java.lang.String,java.lang.Object> customData, NexmoRequestListener<java.lang.Void> listener)
customType
- the type of custom event.customData
- the data of custom event.listener
- The request completion listener.public void sendAttachment(java.io.File attachment, NexmoRequestListener listener)
Once the image is uploaded, you will be able to access all 3 representations:
NexmoAttachmentEvent.getOriginal()
NexmoAttachmentEvent.getMedium()
NexmoAttachmentEvent.getThumbnail()
attachment
- The attachment file.listener
- The request completion listener.public void join(NexmoRequestListener<java.lang.Void> listener)
NexmoUser
to this conversation.
Note: any NexmoUser
that joins a NexmoConversation
becomes a
NexmoMember
.
listener
- The request completion listener.public void join(java.lang.String username, NexmoRequestListener<java.lang.String> listener)
NexmoUser
to this conversation.
Note: any NexmoUser
that joins a NexmoConversation
becomes a
NexmoMember
.
username
- The username of the user that will join this
NexmoConversation.listener
- The request completion listener.public void kick(java.lang.String memberId, NexmoRequestListener<java.lang.Void> listener)
NexmoUser
from this conversation.memberId
- The memberId to be removed.listener
- The request completion listener.public void invite(java.lang.String userName, NexmoRequestListener<java.lang.String> listener)
public void startTyping()
public void stopTyping()
public void addNexmoConversationListener(NexmoConversationListener listener)
listener
- NexmoConversationListener.public void removeNexmoConversationListener(NexmoConversationListener listener)
listener
- NexmoConversationListener.public void clearNexmoConversationListeners()
public void addMessageEventListener(NexmoMessageEventListener listener)
Event types:
listener
- Event listener.public void removeMessageEventListener(NexmoMessageEventListener listener)
listener
- Event listener.public void clearMessageEventListeners()
@Deprecated public void addDTMFEventListener(NexmoDTMFEventListener listener)
listener
- Event listener.@Deprecated public void removeDTMFEventListener(NexmoDTMFEventListener listener)
listener
- Event listener.public void clearDTMFEventListeners()
public void addLegStatusEventListener(NexmoLegStatusEventListener listener)
listener
- Event listener.public void removeLegStatusEventListener(NexmoLegStatusEventListener listener)
listener
- Event listener.public void clearLegStatusEventListeners()
public void addMemberMessageStatusEventListener(NexmoMemberMessageStatusEventListener listener)
listener
- Event listener.public void removeMemberMessageStatusEventListener(NexmoMemberMessageStatusEventListener listener)
listener
- Event listener.public void clearMemberMessageStatusEventListeners()
public void addCustomEventListener(NexmoCustomEventListener listener)
listener
- Event listener.public void removeCustomEventListener(NexmoCustomEventListener listener)
listener
- Event listener.public void clearCustomEventListeners()
public void addMemberEventListener(NexmoMemberEventListener listener)
listener
- Event listener.public void removeMemberEventListener(NexmoMemberEventListener listener)
listener
- Event listener.public void clearMemberEventListeners()
public void addTypingEventListener(NexmoTypingEventListener listener)
listener
- Event listener.public void removeTypingEventListener(NexmoTypingEventListener listener)
listener
- Event listener.public void clearTypingEventListeners()
public void clearNexmoEventsListeners()
public java.lang.String getConversationId()
public java.lang.String getName()
public java.lang.String getDisplayName()
public java.util.Date getCreationDate()
public java.lang.String getLastEventId()
public int describeContents()
describeContents
in interface android.os.Parcelable
public void writeToParcel(android.os.Parcel dest, int flags)
writeToParcel
in interface android.os.Parcelable
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public void disableMedia()
public void enableMedia()
public void reconnectMedia()
public void addMediaEventListener(NexmoMediaEventListener mediaEventListener)
mediaEventListener
- Event listener.public void addMediaActionEventListener(NexmoMediaActionEventListener mediaActionEventListener)
mediaActionEventListener
- Event listener.public void addMediaStatusListener(NexmoMediaStatusListener listener)
listener
- Event listener.public int compareTo(NexmoConversation nexmoConversation)
compareTo
in interface java.lang.Comparable<NexmoConversation>