Prior to version 4.0.0 of the VoiceLayer SDK, if you wanted to send messages directly to another user you had to use one of two approaches:

  • Create a managed channel and invite the other user to join that channel.
  • Create a direct channel.

Both of these approaches required creating and/or retrieving the channel prior to being able to send any messages. Conversations instead function by sending messages to the user directly, eliminating the need to create and maintain a channel.

Identifying Conversation Messages

VoiceLayerMessage objects now feature 3 new properties:

  • receiver: This will have a value of either "channel" or "user" with the latter indicating the message belongs to a conversation.
  • conversationId: For conversation messages this will be the id of the conversation partner. For channel messages this will be null.
  • partner: For conversation messages this will be the conversation partner. For channel messages this will be null.

Querying Messages

The VoiceLayerUser object now provides two methods for querying messages sent to and received from the specified user:

public VoiceLayerUserMessageResponse getMessages(int count, String cursor);
public void getMessages(int count, String cursor, VoiceLayerFetchCallback<VoiceLayerUserMessageResponse> callback);

For each message in the response you will receive an associated cursor. This is a unique string that will indicate the message's position in the conversation. You can then use this cursor to retrieve messages prior to that position in the list. For the initial query you can provide a value of null for the query to get the first page of messages.

Sending Messages

You can send a message to a user the same way you would send one to a channel:

// Text Messages
public VoiceLayerMessage postMessage(String message);
public VoiceLayerMessage postMessage(String message, Map<String, Object> data);
public void postMessage(String message, VoiceLayerCreateCallback<VoiceLayerMessage> callback);
public void postMessage(String message, Map<String, Object> data, VoiceLayerCreateCallback<VoiceLayerMessage> callback);

// Location Messages
public VoiceLayerMessage postLocationMessage(String message, double latitude, double longitude);
public void postLocationMessage(String message, double latitude, double longitude, VoiceLayerCreateCallback<VoiceLayerMessage> callback);

// Attachments
public VoiceLayerMessage postAttachment(File attachment);
public void postAttachment(File attachment, VoiceLayerCreateCallback<VoiceLayerMessage> callback);

Recording Messages

Similarly, you can now record messages to a user the same as you would for a channel:

public VoiceLayerMessage startRecording(VoiceLayerUser user);
public VoiceLayerMessage startRecording(VoiceLayerUser user, Map<String, Object> messageData);


A new method has been added to the VoiceLayerMessageEventListener for when a message is deleted in a conversation:

void onMessageRemoved(String messageId, VoiceLayerUser partner);