- initialize
- reset
- login
- logout
- openMessagingView
- sendPageViewEvent
- updatePushNotificationToken
- getUnreadMessageCount
- handleNotification
- addEventListener
- removeSubscription
- removeAllListeners
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 keyskipOpenMessaging
: skip open messaging view after initialize successfully (default:false
, iOS only)- application started by Zendesk push notification, showing messaging view for users.
- References
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();
- References
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');
- References
To unauthenticate a user call the logout
.
- Return Value
Type Promise<void>
/* interfaces */
function logout(): Promise<void>
logout();
- References
Show the native based conversation screen.
- Return Value
Type Promise<void>
/* interfaces */
function openMessagingView(): Promise<void>
openMessagingView();
- References
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
});
- References
🚨 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...');
- References
Get current total number of unread messages.
- Return Value
Type Promise<number>
/* interfaces */
function getUnreadMessageCount(): Promise<number>
const unreadCount = await getUnreadMessageCount();
- References
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 notificationMESSAGING_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 SDKUNKNOWN
: 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({ ... });
- References
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; }
});
- References
Remove subscribed event listener
- Parameters
Name Type Required subscription EmitterSubscription
Yes - Return Value
void
/* interfaces */
function removeSubscription(subscription: EmitterSubscription): void
removeSubscription(subscription);
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');