Skip to content

Latest commit

 

History

History
375 lines (273 loc) · 9.04 KB

File metadata and controls

375 lines (273 loc) · 9.04 KB

API References

Index

initialize

Initializing Zendesk SDK.

You should call this function first before using other features.

  • Parameters
    Name Type Required
    config ZendeskInitializeConfig Yes
  • Return Value
    Type
    Promise<void>
/* interfaces */

interface ZendeskInitializeConfig {
  channelKey: string;
  skipOpenMessaging?: boolean; // iOS Only
}

function initialize(config: ZendeskInitializeConfig): Promise<void>
initialize({ channelKey: 'YOUR_ZENDESK_CHANNEL_KEY' });
  • channelKey: Zendesk channel key
  • skipOpenMessaging: skip open messaging view after initialize successfully (default: false, iOS only)
    • application started by Zendesk push notification, showing messaging view for users.

reset

Invalidates the current instance of Zendesk. After calling this method you will have to call initialize again if you would like to use Zendesk.

  • Return Value
    Type
    void
/* interfaces */

function reset(): void
reset();

login

To authenticate a user call the login with your own JWT.

  • Parameters
    Name Type Required
    token string Yes
  • Return Value
    Type
    Promise<ZendeskUser>
/* interfaces */

interface ZendeskUser {
  id: string;
  externalId: string;
}

function login(token: string): Promise<ZendeskUser>
const user = await login('eyJhb...Your own JWT...ssw5c');

logout

To unauthenticate a user call the logout.

  • Return Value
    Type
    Promise<void>
/* interfaces */

function logout(): Promise<void>
logout();

openMessagingView

Show the native based conversation screen.

  • Return Value
    Type
    Promise<void>
/* interfaces */

function openMessagingView(): Promise<void>
openMessagingView();

sendPageViewEvent

Send session-based page view event. event must have pageTitle and url.

Sent events can be seen in agent workspace by support agents using Zendesk.

  • Parameters
    Name Type Required
    event ZendeskPageViewEvent Yes
  • Return Value
    Type
    Promise<void>
/* interfaces */

interface ZendeskPageViewEvent {
  pageTitle: string;
  url: string;
}

function sendPageViewEvent(event: ZendeskPageViewEvent): Promise<void>
sendPageViewEvent({
  pageTitle: 'Home',
  url: 'RootStack/HomeScreen', // eg. react-navigation's current path string
});

updatePushNotificationToken

🚨 It works on Android only (iOS do nothing)

To enable a device to receive push notifications, you must notify the SDK when a new FCM token has been created.

  • Parameters
    Name Type Required
    token string Yes
  • Return Value
    Type
    void
/* interfaces */

function updatePushNotificationToken(token: string): void
updatePushNotificationToken('...FCM Token...');

getUnreadMessageCount

Get current total number of unread messages.

  • Return Value
    Type
    Promise<number>
/* interfaces */

function getUnreadMessageCount(): Promise<number>
const unreadCount = await getUnreadMessageCount();

handleNotification

Handle remote message that received from FCM(Firebase Cloud Messaging) and show notifications.

If remote message isn't Zendesk message, it does nothing.

🚨 Android only

This method for integrate with @react-native-firebase/messaging.

For more details, read the Push Notifications guide.

  • Parameters
    Name Type Required
    remoteMessage object Yes
  • Return Value
    Type
    Promise<ZendeskNotificationResponsibility>
    • MESSAGING_SHOULD_DISPLAY: remoteMessage is handled by Zendesk SDK. it will be appeared as notification
    • MESSAGING_SHOULD_NOT_DISPLAY: remoteMessage is handled by Zendesk SDK. but, it's not appear as notification (eg. bot response)
    • NOT_FROM_MESSAGING: remoteMessage is not handled by Zendesk SDK
    • UNKNOWN: If platform is iOS always return this value and otherwise used by fallback value.
/* interfaces */
type ZendeskNotificationResponsibility =
  | 'MESSAGING_SHOULD_DISPLAY'
  | 'MESSAGING_SHOULD_NOT_DISPLAY'
  | 'NOT_FROM_MESSAGING'
  | 'UNKNOWN';

function handleNotification(remoteMessage: Record<string, string>): Promise<ZendeskNotificationResponsibility>
const responsibility = await handleNotification({ ... });

addEventListener

Add a listener for listening emitted events by Zendesk SDK.

  • Parameters
    Name Type Required
    type ZendeskEventType Yes
    listener (event) => void Yes
  • Return Value
    Type
    EmitterSubscription
/* interfaces */

type ZendeskEventType = 'unreadMessageCountChanged' | 'authenticationFailed';

function addEventListener<EventType extends ZendeskEventType>(type: EventType, listener: (event: ZendeskEventResponse[EventType]) => void): EmitterSubscription
const unreadMessageCountChangedSubscription = addEventListener('unreadMessageCountChanged', (event) => {
  // Event type
  // { unreadCount: number; }
});

const authenticationFailedSubscription = addEventListener('authenticationFailed', (event) => {
  // Event type
  // { reason: string; }
});

removeSubscription

Remove subscribed event listener

  • Parameters
    Name Type Required
    subscription EmitterSubscription Yes
  • Return Value
    • void
/* interfaces */

function removeSubscription(subscription: EmitterSubscription): void
removeSubscription(subscription);

removeAllListeners

Remove all of registered listener by event type.

  • Parameters
    Name Type Required
    type ZendeskEventType Yes
  • Return Value
    • void
/* interfaces */

function removeAllListeners(type: ZendeskEventType): void
removeAllListeners('unreadMessageCountChanged');