Skip to content

2. Available APIs

Sébastien Vitard edited this page Oct 10, 2024 · 5 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 (i.e. the chatbox is opened), otherwise they are cached and will be sent when the session is loaded (i.e. on the next chatbox opening) unless you resetted the session or switched of website since, i.e. 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.

Show message (local only)

void Crisp.showMessage(Content content)

Shows a message as operator in local chatbox.

You can create and send AnimationContent, AudioContent, CarouselContent, FieldContent, FileContent, PickerContent or TextContent.

Each of these classes can be instantiated either from:

  • a constructor (if message type requires all its fields to be set, i.e. AnimationContent, AudioContent, FileContent or TextContent),
  • a Builder class (if message type has optional fields, i.e. CarouselContent, FieldContent, PickerContent).
Crisp.showMessage(new TextContent("Hello world"));
Crisp.showMessage(new FieldContent  .Builder("Id", "Text", "Placeholder")
                                    .setRequired(true)
                                    .build());

Events callback

You can register a callback for the following events:

  • session:loaded,
  • chat:opened,
  • chat:closed,
  • message:sent,
  • message:received.
void Crisp.addCallback(EventsCallback callback)

❗️ Don't forget to unregister it as soon as you don't need it anymore as Crisp SDK keeps a strong reference on it!

void Crisp.removeCallback(EventsCallback callback)