Note: The SDK must be initialized before using any of these methods. See Initialize the SDK for more details.

To view a demo of this, see Zendesk SDK Demo app in GitHub.

Conversation fields

Setting conversation fields

You can set values for conversation fields in the SDK to add contextual data about the conversation.

Zendesk.instance.messaging.setConversationFields(fields: Map<String, Any>)

Conversation fields must first be created as custom ticket fields and configured to allow their values to be set by end users in Admin Center. To use conversation fields, see Using messaging metadata with the Zendesk Web Widgets and SDKs.

The values stored are persisted, and will be applied to all conversations going forward. To remove conversation fields stored in the SDK, use the ClearConversationFields API.

Note: Conversation fields are not immediately associated with a conversation when the API is called. Calling the API will store the conversation fields, but those fields will only be applied to a conversation when end users either start a new conversation or send a new message in an existing conversation.

System ticket fields, such as the Priority field, are not supported.

Parameters

fields: Map<String, Any>: A collection of key-value pairs.

TypeDescription
Stringid of custom ticket field
Anyvalue of custom ticket field

Note: Supported types for Any are string, number, and boolean.

Example

For example, if the id of your custom field for flight number is 4422761977114 and you want to set its value to FA2590, then you would call:

Kotlin

val fields = mapOf("4422761977114" to "FA2590")
Zendesk.instance.messaging.setConversationFields(fields)

Java

Map<String,Object> fields = new HashMap<String, Object>();fields.put("4422761977114", "FA2590");
Zendesk.getInstance().messaging.setConversationFields(fields);

Clearing conversation fields

You can clear conversation fields from the SDK storage when the client side context changes. To do this, use the clearConversationFields API. This removes all stored conversation fields from the SDK storage.

Note: This API does not affect conversation fields already applied to the conversation.

Example

Kotlin

Zendesk.instance.messaging.clearConversationFields()

Java

Zendesk.getInstance().messaging.clearConversationFields();

Conversation tags

Set conversation tags

You can set custom conversation tags in the SDK to add contextual data about the conversation.

Zendesk.instance.messaging.setConversationTags(tags: List<String>)

To use conversation tags, refer to Using messaging metadata with the Zendesk Web Widgets and SDKs.

Note: Conversation tags are not immediately associated with a conversation when the API is called. They will only be applied to a conversation when end users either start a new conversation or send a new message in an existing conversation.

Parameters

List<String> A list of strings

Example

For example, to apply promo_code and discount tags to a conversation about an order, then you would call:

Kotlin

val tags = listOf("promo_code", "discount")Zendesk.instance.messaging.setConversationTags(tags)

Java

List<String> tags = new ArrayList<String>();tags.add("promo_code")tags.add("discount")
Zendesk.getInstance().messaging.setConversationTags(tags)

Clear conversation tags

You can clear conversation tags from SDK storage when the client side context changes. To do this, use the clearConversationTags API. This removes all stored conversation tags from the SDK storage.

Note: This API does not affect conversation tags already applied to the conversation.

Example

Kotlin

Zendesk.instance.messaging.clearConversationTags()

Java

Zendesk.getInstance().messaging.clearConversationTags();