Advanced integration

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

Messaging metadata

See Messaging Metadata Developer Documentation for more details.

To learn more about Messaging Metadata, see Introduction to Messaging Metadata.

Get Unread Message Count API

'GetUnreadMessageCountAsync()` gets the total number of unread messages the end user has.

Example

The following snippet shows how to retrieve the unread message count.

2.2.1 and below:

UnreadCountResult unreadMessageCountResult = await ZendeskSdk.Instance.Messaging.GetUnreadMessageCountAsync();

2.3.0 and up: Optional parameters:

  • onUnreadCountChanged: (Action) Action to be called when the unread count changes
  • shouldSubscribe: (boolean) Whether to subscribe to the websocket event outside of conversation

The return type of GetUnreadMessageCountAsync is an object of type UnreadCountResult that includes an IsSuccess property indicating the success status of the GetUnreadMessageCountAsync operation. If the operation failed, the Error enum property (of type UnreadCountError) can be queried regarding the nature of the failure.

Authentication

The Zendesk SDK allows authentication of end users so that their identity can be verified by agents using Zendesk. See Enabling authenticated visitors for messaging with Zendesk SDKs for information on setting up authentication for your account. The steps mentioned in this article must be completed before beginning the steps below.

LoginAsync

Use the LoginAsync API with your own JWT to authenticate a user.

Parameters

string JWT

The supported JWT claims are:

NameTypeMandatoryComment
external_idStringtrueThe user's external id
scopeStringtrueScope claim set to "user"
nameStringfalseThe user's name
emailStringfalseThe user's email address

Example minimal JWT payload:

{   "external_id":"1",   "scope":"user"}
Example

If your jwt is "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHRlcm5hbF9pZCI6IjAiLCJzY29wZSI6InVzZXIifQ.bSTt5WAxuMBJacjcZ-p9rWkvWbCQpecFE_8QglcBiR8", then you would call:

await ZendeskSdk.Instance.Messaging.LoginAsync("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHRlcm5hbF9pZCI6IjAiLCJzY29wZSI6InVzZXIifQ.bSTt5WAxuMBJacjcZ-p9rWkvWbCQpecFE_8QglcBiR8");

The return type of LoginAsync is an object of type LoginResult that includes an IsSuccess property indicating the success status of the login operation. If the operation failed, the Error enum property (of type LoginError) can be queried regarding the nature of the failure.

LoginResult result = await ZendeskSdk.Instance.Messaging.LoginAsync("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHRlcm5hbF9pZCI6IjAiLCJzY29wZSI6InVzZXIifQ.bSTt5WAxuMBJacjcZ-p9rWkvWbCQpecFE_8QglcBiR8");

Logout

Use the Logout API to sign out a user.

This is primarily for authenticated users, but calling Logout for an unauthenticated user will clear all their data, including their conversation history. Please note that we cannot recover this data, so only use this for testing purposes. The next time the unauthenticated user enters the conversation screen, a new user and conversation is created for them.

Example
await ZendeskSdk.Instance.Messaging.Logout();

The result of Logout can be observed in the resulting ZendeskResult object that contains IsSuccess property indicating the success status of the logout operation.

LogoutResult result = await ZendeskSdk.Instance.Messaging.Logout();