login(user: UserDetails) => void

Description: This method logs in a user into the widget using restoreId and externalUserId. It is called when a user starts an interaction with the widget. Log in a user with restoreId and externalUserId. user: The login details of the user { externalUserId, restoreId }

Example Usage:

// Log in a user
    const userDetails = { externalUserId: 'user123', restoreId: 'restoreId123' };
    window.orufyWidget.login(userDetails);
    console.log('User logged in');

setUserDetails(user: Partial<UserDetails>) => void

Description: This method allows you to update user details after they have logged in. You can update fields such as name, email, or phone number. Update user details.

  • user: The details you want to update (e.g., name, email, phoneNumber).

Example Usage:

// Update user details
    const updatedDetails = { name: 'John Doe', email: 'johndoe@example.com' };
    window.orufyWidget.setUserDetails(updatedDetails);
    console.log('User details updated');

logout() => void

Description: This method logs out the current user, clearing the session data and disconnecting the user from the widget. Log out the current user/guest customer in the widget. Completely clears the widget session.

Example Usage:

// Log out the user
    window.orufyWidget.logout();
    console.log('User logged out');

setAppId(appId: string) => boolean

Description: This method sets the application ID for the widget. The application ID uniquely identifies your application within the widget context. Set the application ID for the widget. appId: The ID to set.

  • Returns: true if the ID was set successfully, otherwise false.

Example Usage:

// Set the application ID
    const appId = 'myAppId123';
    const isAppIdSet = window.orufyWidget.setAppId(appId);
    console.log(isAppIdSet ? 'App ID set successfully' : 'Failed to set App ID');

setExternalUserid(externalId: string) => Promise<unknown>

Description: This method associates an external user ID with the current session. It’s useful for linking the widget session with a user in your external system. Associate an external user ID with the current session.

  • externalId: The external ID to set.
  • Returns: A promise that resolves when the ID is set.

Example Usage:

// Set external user ID
    const externalId = 'externalUser123';
    window.orufyWidget.setExternalUserid(externalId)
    .then((response) => console.log(response))
    .catch((error) => console.error(error));

isLoggedIn() => boolean

Description: This method checks if a user is currently logged in with a valid restoreId and externalUserId. Check if a user is currently logged in. Check if a user is currently logged in with restoreID and externalUserId.

  • Returns: true if logged in, otherwise false. (Returns false in case of guest user chats).

Example Usage:

// Check if user is logged in
    const loggedIn = window.orufyWidget.isLoggedIn();
    console.log(loggedIn ? 'User is logged in' : 'User is not logged in');

getUser() => Promise<{ data: UserDetails; success: boolean }>

Description: This method retrieves the details of the currently logged-in user, such as name, email, and other information. Get details of the current user.

  • Returns: A promise with:
  • data: The user’s details.
  • success: Whether getting the details was successful.

Example Usage:

// Get user details
    window.orufyWidget.getUser()
    .then((response) => console.log(response.data))
    .catch((error) => console.error(error));

getUnreadChatsCount() => Promise<{ data: number; success: boolean }>

Description: This method retrieves the number of unread chats for the current user. Get unread chats count of the current user.

  • Returns: A promise with:
  • data: Number of unread chats.
  • success: Whether getting the details was successful.

Example Usage:

// Get unread chats count
    window.orufyWidget.getUnreadChatsCount()
    .then((response) => console.log('Unread chats count:', response.data))
    .catch((error) => console.error(error));