-
Notifications
You must be signed in to change notification settings - Fork 17
2. Available APIs
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.
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.
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.
String Crisp.getSessionIdentifier(Context applicationContext)
Returns the current sessionID
if any and loaded (so the ChatActivity
is already started and session joined).
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:
-
Crisp.configure(Context, String, @Nullable String)
with a differentwebsiteID
than the current, -
Crisp.resetChatSession(Context context)
.
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.
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.
void Crisp.pushSessionEvent(SessionEvent event)
void Crisp.pushSessionEvents(List<SessionEvent> events)
Sends the session events provided.
boolean Crisp.setUserAvatar(String avatar)
Sets the user avatar to the one provided, if it is valid.
Returns true
if valid, false
otherwise.
boolean Crisp.setUserEmail(String email)
Sets the user e-mail to the one provided, if it is valid.
Returns true
if valid, false
otherwise.
boolean Crisp.setUserPhone(String phone)
Sets the user phone to the one provided, if it is valid.
Returns true
if valid, false
otherwise.
void Crisp.setUserCompany(Company company)
Sets the user company to the one provided.
void Crisp.setUserNickname(String nickname)
Sets the user nickname to the one provided.
Those methods are performed right away if the ChatActivity
is currently running, on the next start otherwise unless you called one of these methods:
-
Crisp.configure(Context, String, @Nullable String)
with a differentwebsiteID
than the current, -
Crisp.resetChatSession(Context context)
, - any other action method, except
Crisp.showMessage(Content)
which is independent.
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.
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.
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 messagetype
requires all its fields to be set, i.e.AnimationContent
,AudioContent
,FileContent
orTextContent
), - a
Builder
class (if messagetype
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());
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)