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 github 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: [String : AnyHashable])

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: [String : AnyHashable]: A dictionary of key-value pairs.

TypeDescription
Stringid of custom ticket field
AnyHashablevalue of the custom ticket field

Note: The supported types for AnyHashable are string, number, and boolean.

Example

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

Swift

Zendesk.instance.messaging.setConversationFields(["4422761977114": "FA2590"])

Objective-C

[Zendesk.instance.messaging setConversationFields:@{@"4422761977114": @"FA2590"}];

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

Swift

Zendesk.instance.messaging.clearConversationFields()

Objective-C

[Zendesk.instance.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: [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

[String] An array of strings.

TypeDescription
[String]The array of custom tags to be provided.

Example

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

Swift

Zendesk.instance.messaging.setConversationTags(["promo_code", "discount"])

Objective-C

[Zendesk.instance.messaging setConversationTags:@[@"promo_code", @"discount"]];

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

Swift

Zendesk.instance.messaging.clearConversationTags()

Objective-C

[Zendesk.instance.messaging clearConversationTags];