@kustomer/chat-react-native
Version:
Kustomer Chat SDK wrapper for React Native
202 lines • 12.2 kB
TypeScript
import type { FirebaseMessagingTypes } from '@react-native-firebase/messaging';
import type { KustomerClientStatus } from './KustomerClientStatus';
import type { KusConversation } from './KusConversation';
import type { KustomerCustomerAttributes } from './KustomerCustomerAttributes';
import type { KustomerDisplayMode } from './KustomerDisplayMode';
import type { KusInitialMessage } from './KusInitialMessage';
import type { KusActiveAssistant, KustomerOptions } from './KustomerOptions';
import type { KustomerTrackingIdentity } from './KustomerTrackingIdentity';
import type { RNModule } from './util/RNModule';
export interface IKustomerChat extends RNModule {
getConstants(this: void): Readonly<{
/** Version of the Kustomer SDK */
sdkVersion: string;
/** Build number of Kustomer SDK */
sdkBuild: string;
}>;
isConfigured(this: void): Promise<boolean>;
/**
* Configures the Kustomer SDK.
* Does not initiate any network calls. Can call from anywhere. Must call before trying to present the UI, observing unread counts, or manually calling Kustomer.start(this: void): void
* If there was a problem configuring, the KustomerClient returned's .status will be .configurationError
* Note: this also sets your `UNUserNotificationCenter.current(this: void, ).delegate` property
*
* @param {string} [apiKey] - An API key, with `org.tracking` permissions. FOR NOW: Must include `org.admin`, `org.user.read`, `org.admin.kb.read`, `org.user.customer.read`, `org.tracking` permissions.
* @param {KustomerOptions} [options] - Options to configure the SDK
* @returns {Promise<void>}
* @throws {KustomerConfigurationError}
*/
configure(this: void, apiKey: string, options?: KustomerOptions): Promise<void>;
/**
* Shows the Support Center using a preferred view. See {@link KustomerDisplayMode}.
*
* @param {KustomerDisplayMode} [displayMode=KustomerDisplayMode.default] - The preferred view to show. Defaults to `KustomerDisplayMode.default`.
*/
show(this: void, displayMode?: KustomerDisplayMode): Promise<void>;
/**
* Hides the Kustomer UI if it's open. The promise is resolved after the `KustomerOptions.onDismiss` block.
*
* @param {boolean} [animated=true] - Whether to animate the transition.
*
* **iOS:**
* - `animated` controls the animation for the transition and defaults to `true`.
*
* **Android:**
* - `animated` is ignored and has no effect.
* - On Android, the Kustomer SDK creates a new activity, sending the React Native app to the background. This behavior pauses the JavaScript thread, preventing JavaScript code from executing on the main thread while the Kustomer UI is open (e.g., `setTimeout` functions will not run).
* - We recommend using [`react-native-background-timer`](https://www.npmjs.com/package/react-native-background-timer) or [Headless JS](https://reactnative.dev/docs/headless-js-android) to interact with the SDK via JavaScript while the Kustomer UI is open.
*
* @returns {Promise<void>}
*/
close(this: void, animated?: boolean): Promise<void>;
/** The current status of the Kustomer client. */
getStatus(this: void): Promise<KustomerClientStatus>;
getStatusSync(this: void): KustomerClientStatus;
/** Is the Kustomer UI visible, or is it in the process of being presented? */
isVisible(this: void): Promise<boolean>;
isVisibleSync(this: void): boolean;
/**
* Checks if the user is logged in using the provided ID.
* @param {string} idType - The type of ID to check. Can be either 'email' or 'userId'.
* @param {string} id - The ID to check.
* @returns {Promise<boolean>}
*/
isLoggedIn(this: void, idType: 'email' | 'userId', id: string): Promise<boolean>;
/**
* Clears the user's access to any existing chats from the device. If you're using push, deregisters them from the Kustomer push service.
* Can fail if you're using push notifications and we're unable to deregister the user from future pushes (this: void, e.g. if they try to log out while there is no internet).
* If you're not using push notifications, it will always succeed.
* @returns {Promise<void>}
* @throws {KError}
*/
logOut(this: void): Promise<void>;
/**
* Logs in as the customer w/ the JWT passed. Loads all their chat histories in the background, as network conditions permit.
*
* @param {string} jwt - The JWT to log in with.
* @returns {Promise<KustomerTrackingIdentity>}
* @throws {KError}
*/
logIn(this: void, jwt: string): Promise<KustomerTrackingIdentity>;
/**
* Logs out, then logs in as the customer w/ the JWT passed. Loads all their chat histories in the background, as network conditions permit.
*
* @param {string} jwt - The JWT to log in with.
* @returns {Promise<KustomerTrackingIdentity>}
* @throws {KError}
*/
logOutThenLogIn(this: void, jwt: string): Promise<KustomerTrackingIdentity>;
/**
* Creates a new conversation and opens the Chat UI.
*
* This always creates a new conversation, regardless of your settings.
*
* @param {KusInitialMessage} [initialMessage] - The initial message to send to the new conversation. Optional.
* @param {Record<string, string>} [customDescribe] - The custom descriptions object to send to the new conversation. Optional.
* @param {boolean} [animated=true] - \@ios Whether to animate the transition to the conversation. Defaults to `true`.
*
* @returns {Promise<KusConversation | void>} A promise that resolves with the new conversation object if successful.
*
* ```
* startNewConversation(initialMessage, customDescribe, true)
* .then((conversation) => {
* console.log("Conversation created:", conversation);
* })
* .catch((error) => {
* console.error("Error creating conversation:", error);
* });
* ```
*/
startNewConversation(this: void, initialMessage?: KusInitialMessage, customDescribe?: Record<string, string>, animated?: boolean): Promise<KusConversation>;
/** Change the ID of the chat assistant used when the user clicks 'New conversation'. */
changeActiveAssistant(this: void, options: KusActiveAssistant): Promise<void>;
/**
* Changes the business schedule ID. If the UI is visible, closes the UI and re-opens it with the new business schedule.
*
* @throws {KustomerError} - If the business schedule id is invalid, will return an `invalidBusinessScheduleId` error.
*
* If this happens you need to call changeBusinessSchedule(this: void, scheduleId:completion) again with a valid scheduleId,
* or with an `undefined` scheduleId. An `undefined` schedule id will use your org's default business schedule.
*/
changeBusinessSchedule(this: void, scheduleId?: string): Promise<void>;
/**
* Checks the "turned on/off" status of your chat alongwith within Business Hours and outside of Holidays settings asynchronously.
* For example if chat is turned off or outside of business hours, you may want to disable the button or deflect customers to contact an email).
* If you change your business hours or holidays in the admin panel, you must restart the app to see the new values.
*/
isChatAvailable(this: void): Promise<boolean>;
isChatAvailableSync(this: void): boolean;
/**
* Opens an existing conversation.
*
* @param {string} id The identifier for the desired conversation.
* @param {boolean} [animated=true] - \@ios Whether to animate the transition to the conversation. Defaults to `true`.
* @returns {KusConversation} - A descriptor for the conversation.
* @throws {KError} - If the conversation does not exist.
*/
openConversation(this: void, id: string, animated?: boolean): Promise<KusConversation>;
/** Loads the knowledge base at a specific article. */
showKbArticle(this: void, id: string): Promise<void>;
/** Loads the knowledge base at a specific category */
showKbCategory(this: void, id: string): Promise<void>;
/**
* Creates the connection to the Kustomer SDK backend.
* This runs automatically, when {@link Kustomer.show} is called.
* @ios
*/
start(this: void): Promise<void>;
/**
* Starts a new chat with our bot using the passed chat assistant ID.
*
* @param {string} [chatAssistantId] - The chat assistant ID to start a chat with.
* @param {string} [startDialog] - Any opening dialog you wish to append to the chat assistant. Optional.
* @param {(this: void, conversation: KusConversation) => void} [afterFirstMessage] - Runs after the first customer-submitted response is processed fully. Similar to `KustomerClient.openNewChat(this: void, ...)`. Optional.
* @param {string[]} [initialMessages] - The initial messages from the customer. Optional.
* @param {Record<string, string>} [customDescribe] - Key-value pairs to describe the created conversation (this: void, must be set up in Kustomer Portal). Optional.
* @param {boolean} [animated=true] - \@ios Whether to animate the presentation. Defaults to `true`.
* @returns {Promise<void>}
* @throws {KError}
*/
openChatAssistant(this: void, chatAssistantId: string, startDialog?: string, initialMessages?: string[], customDescribe?: Record<string, string>, animated?: boolean): Promise<void>;
/**
* Use `describeCustomer` to add predefined and custom attributes to the Customer
* object of the customer logged into the chat.
* @param {KustomerCustomerAttributes} [attributes] - The predefined attributes to set on the customer.
* @param {Record<string, string | number | boolean>} [customAttributes] - The custom attributes to set on the customer.
*/
describeCustomer(this: void, attributes?: KustomerCustomerAttributes, customAttributes?: Record<string, string | number | boolean>): Promise<boolean>;
/**
* Use `describeConversation` to add predefined and custom attributes to the Conversation
* object of the conversation with the conversationId.
* @param {string} conversationId - The conversationId of the conversation to describe.
* @param {Record<string, string | number | boolean>} attributes - The attributes to set on the conversation.
*/
describeConversation(this: void, conversationId: string, attributes: Record<string, string | number | boolean>): Promise<void>;
/**
* Fetch the current customer's unread count. Use the KustomerEventEmitter to be notified when this changes.
* @returns {Promise<number>}
* @throws {KError}
*/
getUnreadCount(this: void): Promise<number>;
/**
* Fetch the current customer's number of open conversations. Open conversations are ones that:
* - haven't been closed by the user or customer
* - have been successfully created and received by our servers
* - have had at least one message in the last 30 days
*/
getOpenConversationCount(this: void): Promise<number>;
/**
* @android Call this with the FCM token from your Push Notification library
* @ios Do not use. Follow the instructions [here](https://developer.kustomer.com/chat-sdk/v4.2.0-iOS/docs/push-notifications#configure-kustomer-push-notifications) to configure push notifications on iOS.
* */
setPushToken(this: void, token: string): Promise<void>;
/** Call this if you want to check if a RemoteMessage is from a Kustomer push */
isKustomerNotification<TMessage extends {
data: Record<string, string>;
}>(this: void, message: TMessage): boolean;
/** @android Call this from Firebase's appropriate callback to forward the event to the Kustomer SDK */
onRemoteMessage(this: void, message: FirebaseMessagingTypes.RemoteMessage): Promise<boolean>;
/** Essentially disables push, deregisters the user's current device from receiving Kustomer pushes */
unsetPushToken(this: void): Promise<void>;
}
//# sourceMappingURL=KustomerChat.d.ts.map