Updating

You can update a message using any of the VoiceLayerMessage.PROPERTY constants.

Update a Single Property

To update a single property for a message:

VoiceLayerMessage updatedMessage = message.update(VoiceLayerMessage.PROPERTY_TEXT, "new_text");

or

message.update(VoiceLayerMessage.PROPERTY_TEXT, "new_text", new VoiceLayerUpdateCallback<VoiceLayerMessage>() {
    @Override
    public void onUpdateComplete(VoiceLayerMessage message, VoiceLayerException exception) {

    }
});

Update Multiple Properties

To update multiple properties on a message first create a map of property keys to their new values:

Map<String, Object> properties = new HashMap<>();
properties.put(VoiceLayerUser.PROPERTY_TEXT, "new_text");
properties.put(VoiceLayerUser.PROPERTY_DURATION, 12.0f);

then perform the message update:

VoiceLayerMessage updatedMessage = message.update(properties);

or

message.update(properties, new VoiceLayerUpdateCallback<VoiceLayerMessage>() {
    @Override
    public void onUpdateComplete(VoiceLayerMessage message, VoiceLayerException exception) {

    }
});

Note that VoiceLayerMessage.PROPERTY_DURATION can only be updated for messages of type VoiceLayerMessage.TYPE_VOICE. Attempting to update the duration for a message of VoiceLayerMessage.TYPE_TEXT or VoiceLayerMessage.TYPE_ATTACHMENT will not return an error but the duration field will not be updated.

Updating Message Text

The message text is stored in the message's meta data with a key of VoiceLayerMessage.PROPERTY_TEXT. Due to this, you can update the text just as you would any other meta data value. Alternatively the SDK will also recognize attempts to update the text directly:

VoiceLayerMessage updatedMessage = message.update(VoiceLayerMessage.PROPERTY_TEXT, "new_text");

and properly update the correct meta data value.

Update Meta Data

To add or update meta data first create a map of meta data keys to values:

Map<String, Object> data = new HashMap<String, Object>();
data.put(metaKey, "meta_data");
data.put(metaKey2, 100);

If you pass a key that does not currently exist in the message's meta data, a new entry will be created. If the key already exists, the existing value for that key will be replaced with the new value provided.

then update the VoiceLayerMessage.PROPERTY_DATA property for the message:

VoiceLayerMessage updatedMessage = message.update(VoiceLayerMessage.PROPERTY_DATA, data);

or

message.update(VoiceLayerMessage.PROPERTY_DATA, data, new VoiceLayerUpdateCallback<VoiceLayerMessage>() {
    @Override
    public void onUpdateComplete(VoiceLayerMessage message, VoiceLayerException exception) {

    }
});

You can also update the VoiceLayerMessage.PROPERTY_DATA field as part of a multiple property update.

Remove a Single Meta Data Entry

To remove meta data for a message:

VoiceLayerMessage updatedMessage = message.removeMeta("meta_key");

or

message.removeMeta("meta_key", new VoiceLayerUpdateCallback<VoiceLayerMessage>() {
    @Override
    public void onUpdateComplete(VoiceLayerMessage message, VoiceLayerException exception) {

    }
});

Remove Multiple Meta Data Entries

First create a list of meta data keys to remove:

List<String> metaKeys = new ArrayList<String>();
metaKeys.add("meta_key");
metaKeys.add("meta_key_2");

then:

VoiceLayerMessage updatedMessage = message.removeMeta(metaKeys);

or

message.removeMeta(metaKeys, new VoiceLayerUpdateCallback<VoiceLayerMessage>() {
    @Override
    public void onUpdateComplete(VoiceLayerMessage message, VoiceLayerException exception) {

    }
});