Skip to content

2. Available APIs

Sébastien Vitard edited this page Mar 5, 2024 · 3 revisions

Website & Session management

Basic implementation

void Crisp.configure(Context applicationContext, String websiteID)
void Crisp.configure(Context applicationContext, String websiteID, @Nullable String tokenID)

Configures Crisp SDK with your websiteID and optionally your user's tokenID.

If it is called without a tokenID or with a null one, session will be created without one.

It must be called at least once before starting ChatActivity!

If the socket is already connected (so the ChatActivity is already started) when called, it will simply be ignored.

If websiteID is different from the previous one, any session, user, or action methods which have been called until then will be ignored, so call them after.

Session continuity

void Crisp.setTokenID(Context applicationContext, @Nullable String tokenID)

(Un)sets the tokenID to be sent along the session creation.

It must be called after calling Crisp.configure(Context, String, @Nullable String) and before starting the ChatActivity! If it is called after starting the ChatActivity, the session will be created without the tokenID so you will need to call Crisp.resetChatSession(Context context) and start over!

It will be associated with the latest websiteID passed in Crisp.configure(Context, String, @Nullable String).

If the socket is already connected (so the ChatActivity is already started) or no websiteID has been configured yet when called, it will simply be ignored.

Reset session

void Crisp.resetChatSession(Context applicationContext)

Resets the current session bound to the current websiteID and its associated data in cache. Also clears pending session, user and action commands if any.

If the socket is already connected (so the ChatActivity is already started) when called, it is closed right away.

Get session identifier

String Crisp.getSessionIdentifier(Context applicationContext)

Returns the current sessionID if any and loaded (so the ChatActivity is already started and session joined).

Session and User methods

Those methods are performed right away if the socket is already connected, when the session is joined otherwise unless you called one of these methods:

Push session data

void Crisp.setSessionBool(String key, boolean value)
void Crisp.setSessionInt(String key, int value)
void Crisp.setSessionString(String key, String value)

Sets a session data to the one provided.

Push session segments

void Crisp.setSessionSegment(String segment)
void Crisp.setSessionSegment(String segment, boolean overwrite)
void Crisp.setSessionSegments(List<String> segments)
void Crisp.setSessionSegments(List<String> segments, boolean overwrite)

Sets the session segments to the ones provided, overwriting or not (default behavior) the previous ones.

Push session events

void Crisp.pushSessionEvent(SessionEvent event)
void Crisp.pushSessionEvents(List<SessionEvent> events)

Sends the session events provided.

Change user avatar

boolean Crisp.setUserAvatar(String avatar)

Sets the user avatar to the one provided, if it is valid.

Returns true if valid, false otherwise.

Change user email

boolean Crisp.setUserEmail(String email)

Sets the user e-mail to the one provided, if it is valid.

Returns true if valid, false otherwise.

Change user phone

boolean Crisp.setUserPhone(String phone)

Sets the user phone to the one provided, if it is valid.

Returns true if valid, false otherwise.

Change user company

void Crisp.setUserCompany(Company company)

Sets the user company to the one provided.

Change user nickname

void Crisp.setUserNickname(String nickname)

Sets the user nickname to the one provided.

Action methods

Those methods are performed right away if the ChatActivity is currently running, on the next start otherwise unless you called one of these methods:

Open helpdesk search

void Crisp.searchHelpdesk(Context applicationContext)

Opens the Helpdesk tab if your Helpdesk is configured and the website chatbox is configured to display the Helpdesk tab.

View helpdesk article

void Crisp.openHelpdeskArticle(Context applicationContext, String id, String locale)
void Crisp.openHelpdeskArticle(Context applicationContext, String id, String locale, String title)
void Crisp.openHelpdeskArticle(Context applicationContext, String id, String locale, String title, String category)

Opens the target Helpdesk article if your Helpdesk is configured and the website chatbox is configured to display the Helpdesk tab.